Tuesday 19 February 2019

Create a Layer in GeoServer using REST


As part of a possible solution to this question i want create a layer in GeoServer via REST that supplies a SQL statement along with a userid.


Reading I think i would create a feature type and publish it? I need to do this all in REST. Does anyone have any code examples?



Answer



There are many things you can do with the GeoServer REST API that are not specifically documented and that there are not code examples for. Here's the strategy for tackling those.



First, start with the examples in the documentation. Make sure you are familiar with how you can create a simple new layer or workspace using an HTTP POST with either XML or JSON.


Then, through the GeoServer UI, manually create the object you need for which there is no documentation (in this case, a feature type).


Finally, manually browse to the GeoServer REST index (http://your-server/rest or http://your-server/geoserver/rest). Browse through the index until you find the feature type you just created. Append ".xml" or ".json" to the URL of this resource, and you will see its XML or JSON representation.


This representation is what you would have needed to POST to create the feature type through the API. The URL of the representation is the URL that you would have needed to POST to (for example, http://your-server/geoserver/rest/..../myFeatureTypeName.json).


You can use this strategy to figure out how to programmatically create or configure any resource in GeoServer.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...