Friday, June 17, 2016

Using Ordnance Survey Open Data with GeoServer running in the SAP HANA Cloud Platform

Using Ordnance Survey Open Data with GeoServer running in the SAP HANA Cloud Platform (HCP)

By Robert Russell

I use the SAPHCP as a runtime only version of GeoServer and use a local platform independant master copy of GeoServer on my Mac computer. I make my changes and updates on my local machine then use scripts to update a WAR file to deploy to the HCP. If you are interested in following these as a way to deploy to the HCP then I suggest that the HCP documentation is followed first link here. What follows however can be used to setup Ordnance Survey data on any GeoServer installation. As the GeoServer data directory is not a permanent filesystem on the SAPHCP then I use the extended scripts to keep my local and cloud HCP installations of GeoServer in sync (and I do not make any updates on the HCP version that I intend to keep as it will be lost when GeoServer restarts in the HCP)

Ordnance Survey Data Downloads

Download data from Ordnance Survey, I was interest in Solihull in the West Midlands, so downloaded the SP grid reference square.

An download link arrived via email and I extracted the files to a dedicated directory for the shapefiles.
I downloaded the stylesheets from Github

Download the ZIP file and I extracted to a dedicated directory for these style sheets.

For the Shapefiles and stylesheets I noted down the directories

GeoServer Setup

Download the platform independent version of GeoServer - I chose the same version as the WAR file for the HCP

Extract the file and find the “” script in the extracted directories to make a change to the JAVA_HOME settings. As I have already setup Eclipse and deployed GeoServer to the HCP I already had a SAPJVM 7 in place. GeoServer makes no mention at all of SAPJVM as a supported JVM but it works ;) .

Make sure is an executable and run the script to start GeoServer
Login with the standard user and password ( it is usually admin/geoserver )

Change the contact details (and the email address not shown in the screenshot above)
Change the default password
Select “server status” and note down the “Data directory” location as I used that in my scripts
So now up to three directories with the two Ordnance surveys and the GeoServer data directory.

Script to setup Ordnance survey shapefiles with GeoServer

I created an empty directory

Based on the stylesheet Quick start guide pdf

I created a simple csv file matching the shapefiles to the stylesheets.

vi matchShapeStyle.csv

The following script using curl and the REST services of GeoServer to publish the Ordnance Survey shapefiles to GeoServer.

The user and password needs to be changed CHANGETHISuser:password
The Download directories need to be updated as well /Users/robert/Downloads/{shapefiles/stylesheets}

#SLD copy master
###BEFORE running delete SP styles, shapefile store and layers
#####Leave SP_HeritageSite Site Max scale in
#SLD files are in

rm *sld
rm *sld.n*
cp "/Users/robert/Downloads/OS-VectorMap-District-stylesheets-master/ESRI Shapefile stylesheets/GeoServer stylesheets (SLD)/Full Colour style/"*sld .
cp "/Users/robert/Downloads/OS-VectorMap-District-stylesheets-master/ESRI Shapefile stylesheets/GeoServer stylesheets (SLD)/Backdrop style/"*sld .

SP="file:/Users/robert/Downloads/OS VectorMap District (ESRI Shape File) SP/data"

curl -v -u CHANGETHISuser:password -XPUT -H "Content-type: text/plain" -d "file:/Users/robert/Downloads/OS VectorMap District (ESRI Shape File) SP/data"  "http://localhost:8080/geoserver/rest/workspaces/cite/datastores/shapefiles/external.shp?configure=all"


while read i


NAME=`echo $i| awk -F, '{print $1}'`
NAME_S=`echo $NAME|sed "s/.shp//g"`
UPSLD=`echo $i| awk -F, '{print $2}'|tr -d '\r'`

sed -e '1,4d' < ${UPSLD}|sed -e "s/^M//g"|sed "s#vmdsymbols/FullColour/#file:#" >${UPSLD}.no
cat masterHEAD ${UPSLD}.no > ${UPSLD}.new

# "HeritageSite_FullColour.sld" "RailwayStation_FullColour.sld"

case ${UPSLD} in
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000"|grep -v "<MaxScaleDenominator>25000" >${UPSLD}


ls -l $UPSLD



echo $SLD

curl -u CHANGETHISuser:password -XPOST -H 'Content-type: text/xml'  -d ${SLD} http://localhost:8080/geoserver/rest/workspaces/cite/styles

curl -v -u CHANGETHISuser:password -XPUT -H "Content-type: application/vnd.ogc.sld+xml"  -d @${UPSLD}  http://localhost:8080/geoserver/rest/workspaces/cite/styles/${NAME_S}

curl -u CHANGETHISuser:password -XPUT -H 'Content-type: text/xml' -d ${MAPSLD}  http://localhost:8080/geoserver/rest/layers/cite:${NAME_S}

#curl -u CHANGETHISuser:password -XPUT -H 'Content-type: text/xml'  -d ${SETSRS} http://localhost:8080/geoserver/rest/layers/cite:${NAME_S}

#curl -u CHANGETHISuser:password -XPUT -H 'Content-type: text/xml'  -d "<featureType><srs>EPSG:900913</srs></featureType>" http://localhost:8080/geoserver/rest/workspaces/cite/datastores/shapefiles/featuretypes/${NAME_S}

done < matchShapeStyle.csv


#echo $LG
curl -v -u CHANGETHISuser:password -XPOST -H 'Content-type: text/xml' -d ${LG}  http://localhost:8080/geoserver/rest/layergroups

echo "UPDATE BBOX Feature to limit to Solihull"
echo "1) IMPORtant to add bbox restriction to layers"
echo "    BBOX(the_geom, 408813.38462, 272194.17965, 427732.57921, 290850.25285)"
echo "2) also manually add roadabout and road stylings to layer group SP"
echo "3) place disk quota to 100mb for geowebcache"
echo "4) add SP layer group to cite workspace"
echo "5) REALLY important to have relative path name to SP store"

The Last 5 items displayed at the script are required as per the following

  1. As the SAPHCP trial account has usage limits I choose to limit the shapefiles via a layer bounding box CQL selection as the following.
  2. As SP_Road and SP_Roundabout have 2 styles in the Layer Group I manually import the style sheet and add the layers to the Layer Group
  3. Limit the GeoWebCache to 100mb - again purely due to the SAPHCP limits - this settings HAS to be made again once deployed to the SAPHCP.
  4. Add the SP Layer group to the CITE workspace.
  5. IMPORTANT to have a relative path to the “shapefiles” Data Source Name. file:data/SP

Deploy to SAPHCP

**Important to Stop and Delete the neogeo28 application from the Cloud cockpit

Created a script
Created an empty directory
Downloaded/Copied the STANDARD GeoServer WAR file to a dedicated directory

Information on the deploy script below
The script is part of the Tomcat SDK for SAPHCP.
**Important that the local Data directory is used /Users/robert/Downloads/geoserver-2.8.1/data_dir
The caffeinate command is used to prevent my Mac from sleeping during the deploy to the SAPHCP as it can take some time to deploy
Change the CHANGETHISuser@email to the account email address for the SAPHCP

mkdir -p /Users/robert/Downloads/geoserver-2.8.1/data_dir/data/SP
cp "/Users/robert/Downloads/OS VectorMap District (ESRI Shape File) SP/data/"* /Users/robert/Downloads/geoserver-2.8.1/data_dir/data/SP

sed -i "" "s#/Users/robert/Downloads/OS%20VectorMap%20District%20(ESRI%20Shape%20File)%20SP/data/#data/SP#g" /Users/robert/Downloads/geoserver-2.8.1/data_dir/workspaces/cite/shapefiles/datastore.xml

rm -rf /Users/robert/Desktop/root/geoserver/deploy/neo
mkdir /Users/robert/Desktop/root/geoserver/deploy/neo

cd /Users/robert/Desktop/root/geoserver/deploy/neo

unzip /var/tmp/geoserver.war -d .
rm -rf data
mkdir data

cp -pr /Users/robert/Downloads/geoserver-2.8.1/data_dir/. /Users/robert/Desktop/root/geoserver/deploy/neo/data/.

zip -r neogeo28.war .

caffeinate -i /Users/robert/Downloads/neotom/tools/ deploy --host --account p1248461150trial --application neogeo28 --source /Users/robert/Desktop/root/geoserver/deploy/neo/neogeo28.war --user CHANGETHISuser@email

/Users/robert/Downloads/neotom/tools/ start --host --account p1248461150trial --application neogeo28 --user CHANGETHISuser@email

**Once Deployed ENSURE THE limit of the Disk Quota

No comments:

Post a Comment

Google +