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 “startup.sh” 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 startup.sh 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
SP_TidalWater.shp,TidalWater_FullColour.sld
SP_Foreshore.shp,Foreshore_FullColour.sld
SP_Woodland.shp,Woodland_FullColour.sld
SP_SurfaceWater_Area.shp,SurfaceWater_Area_FullColour.sld
SP_Ornament.shp,Ornament_FullColour.sld
SP_SurfaceWater_Line.shp,SurfaceWater_Line_FullColour.sld
SP_Building.shp,Building_FullColour.sld
SP_Glasshouse.shp,Glasshouse_FullColour.sld
SP_Roundabout.shp,Roundabout_(Casing)_FullColour.sld
SP_Road.shp,Road_(Level0)_FullColour.sld
SP_RailwayTrack.shp,RailwayTrack_FullColour.sld
SP_RoadTunnel.shp,RoadTunnel_FullColour.sld
SP_RailwayTunnel.shp,RailwayTunnel_FullColour.sld
SP_ElectricityTransmissionLine.shp,ElectricityTransmissionLine_FullColour.sld
SP_AdministrativeBoundary.shp,AdministrativeBoundary_FullColour.sld
SP_SpotHeight.shp,SpotHeight_FullColour.sld
SP_NamedPlace.shp,NamedPlace_FullColour.sld
SP_RailwayStation.shp,RailwayStation_FullColour.sld
SP_MotorwayJunction.shp,MotorwayJunction_FullColour.sld
SP_FunctionalSite.shp,FunctionalSite_FullColour.sld
SP_HeritageSite.shp,HeritageSite_FullColour.sld
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
####SP_RailwayStation
####SP_ElectricityTransmissionLine
#
#SLD files are in
##/Users/robert/Downloads/geoserver-2.8.1/data_dir/workspaces/cite/styles/ordnan####ce_survey
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 .
#Shapes
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"
LAYER1=""
STYLE=""
#Styles
while read i
do
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'`
LAYER1=$LAYER1"<layer>${NAME_S}</layer>"
STYLE1=$STYLE1"<style>${NAME_S}</style>"
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
HeritageSite_FullColour.sld)
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
;;
RailwayStation_FullColour.sld)
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
;;
HeritageSite_Backdrop.sld)
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
;;
RailwayStation_Backdrop.sld)
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
;;
ElectricityTransmissionLine_FullColour.sld)
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
;;
ElectricityTransmissionLine_Backdrop.sld)
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
;;
SurfaceWater_Line_FullColour.sld)
echo "${UPSLD} Match" >>/tmp/checker
cat ${UPSLD}.new| grep -v "<MinScaleDenominator>7000" >${UPSLD}
;;
SurfaceWater_Line_Backdrop.sld)
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}
;;
esac
echo $NAME $UPSLD
ls -l $UPSLD
SLD="<style><name>${NAME_S}</name><filename>${UPSLD}</filename></style>"
MAPSLD="<layer><defaultStyle><name>${NAME_S}</name><workspace>cite</workspace></defaultStyle></layer>"
SETSRS="<layer><featureType><srs>EPSG:900913</srs><projectionPolicy>FORCE_DECLARED</projectionPolicy></featureType></layer>"
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
LG="<layerGroup><name>SP</name><layers>${LAYER1}</layers><styles>${STYLE1}</styles></layerGroup>"
#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
- As the SAPHCP trial account has usage limits I choose to limit the shapefiles via a layer bounding box CQL selection as the following.
- 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
- Limit the GeoWebCache to 100mb - again purely due to the SAPHCP limits - this settings HAS to be made again once deployed to the SAPHCP.
- Add the SP Layer group to the CITE workspace.
- 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 neogeo28deploy.sh
/Users/robert/Desktop/root/geoserver/deploy
Created an empty directory
/Users/robert/Desktop/root/geoserver/deploy/neo
Downloaded/Copied the STANDARD GeoServer WAR file to a dedicated directory
/var/tmp/geoserver.war
Information on the deploy script below
The neo.sh 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/neo.sh deploy --host hanatrial.ondemand.com --account p1248461150trial --application neogeo28 --source /Users/robert/Desktop/root/geoserver/deploy/neo/neogeo28.war --user CHANGETHISuser@email
/Users/robert/Downloads/neotom/tools/neo.sh start --host hanatrial.ondemand.com --account p1248461150trial --application neogeo28 --user CHANGETHISuser@email
**Once Deployed ENSURE THE limit of the Disk Quota
No comments:
Post a Comment