GeoServer REST API vs. SDE-Layers

Yesterday i gave the GeoServer REST API a try to register approx. 250 Raster and vector layers all coming from an SDE-Database. My debian6 server hosts postgres 8.4 with SDE 10.0 and Geoserver 2.1.2 (tomcat6)…Previously I installed the sde- extension for geoserver

From my experience the most important issue on publishing hundreds of layers from an GDB is a 100 percent consistent naming convention. Note that in ArcGIS SDE-GDB the cool feature-dataset structure is not represented through the JAVA sde-driver, meaning that the ability to group layers must be possible trough their names…

My aim was to do all basic geoserver-gui tasks in a simple batch file from my win7 client:

  • create raster stores
  • register raster layers
  • register vector layers from existing store

The geoserver doc has some examples on how to interact with the REST API. I also found this project site (opengeoportal wiki)  very useful. My example uses curl…

Raster-Registration based on textfile containing sde layer names (newLayerListRaster.txt):

Result is:

  • raster store (as named in textfile)
  • raster layer with default style (as named in textfile)
@echo off
 SET username="????"
 SET password="????"
 SET sdeusername="????"
 SET sdepassword="????"
 SET sdehost="127.0.0.1"
 SET sdeport="????"
 SET geoserverhostandpath="????/geoserver"
 SET workspace="sde"
 SET list=%1
 echo ---GeoServer Raster Registration ArcSDE---
 echo REQUEST...
 echo arg1=NewStoreName: --from list--
 echo arg2=SDE-RasterTableName(DB.SCHEMA.TABLENAME): --from list--
 echo.
 echo RESPONSE...
 FOR /F %%i in (%list%) do curl -XPOST -u %username%:%password% -H "Content-Type:text/xml" -d "<coverageStore><name>%%i</name><type>ArcSDE Raster</type><enabled>true</enabled><url>sde://%sdeusername%:%sdepassword%@%sdehost%:%sdeport%/#%%i</url></coverageStore>" http://%geoserverhostandpath%/rest/workspaces/%workspace%/coveragestores
 FOR /F %%i in (%list%) do curl -XPOST -u %username%:%password% -H "Content-Type:text/xml" -d "<coverage><name>%%i</name><nativeFormat>ArcSDE Raster</nativeFormat><requestSRS><string>EPSG:4326</string></requestSRS><responseSRS><string>EPSG:4326</string></responseSRS><parameters><entry><string>OVERVIEW_POLICY</string><string>QUALITY</string></entry></parameters></coverage>" http://%geoserverhostandpath%/rest/workspaces/%workspace%/coveragestores/%%i/coverages
 echo.

 

Vector Registration (store must exist):

Result is:

  • vector layer (as named in textfile)
@echo off
 SET username=????
 SET password=????
 SET geoserverhostandpath=????/geoserver
 SET workspacename=????
 SET datastoreName=????
 SET list=%1
 echo ---GeoServer Vector-Layer Registration in existing Store for ArcSDE ---
 echo REQUEST...
 echo arg1=SDE-VectorTableName(DB.SCHEMA.TABLENAME): --from list--
 echo arg2=newStyleName: --from list--
 echo.
 echo RESPONSE...
 @echo on
 FOR /F %%i in (%list%) do curl -XPOST -u %username%:%password% -d {"featureType":{"name":"%%i"}} -H "Content-Type:application/json" http://%geoserverhostandpath%/rest/workspaces/%workspacename%/datastores/%datastoreName%/featuretypes
 @echo off
 echo.
 rem curl -XPOST -u %username%:%password% -H "Content-type: text/xml" -d "<style><name>%stylename%</name><filename>%styleName%.sld</filename></style>" http://%geoserverhostandpath%/rest/styles
 echo.

These two examples can easily be adopted to define projection settings and other layer settings. Just edit the xml or json part of the XPOST request. A good starting point is to define a layer fully by hand in the geoserver gui and look into the resulting layer.xml or coverage.xml in the geoserver data dir. The structure of these xml’s is quite straightforward. Then try to place the tags you want into the batch request…

The next thing i want to automate is style handling and assigning specific styles to layers… One approach is to extend the layerlist from our batch routine with a second or third attribute delimited by e.g. semicolon, holding style info…

Single commands: create style > upload sld file for style > assign style to layer

  • curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' -d '<style><name>newStyleName</name><filename>newStyleName.sld</filename></style>' http://?????/geoserver/rest/styles
    
  • curl -u admin:geoserver -XPUT -H 'Content-type: application/vnd.ogc.sld+xml'-d '@newStyleName.sld' http://?????/geoserver/rest/styles/schwemmland
    
  • curl -u admin:geoserver -XPUT -H 'Content-type: text/xml' -d '<layer><defaultStyle><name>newStyleName</name></defaultStyle></layer>' http://?????/geoserver/rest/layers/LayerName
    

Conclusion:

Depending on the amount of layers the REST API can save a lot of time.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s