I'm integrating GeoServer's REST API into our software and I can't find how to specify Coordinate Reference Systems (CRS) when creating a Shapefile datasource or when updating a layer.
What I currently do via API is:
If I leave the default EPSG:404000
on the 2 layers then they don't show up in Leaflet because the bbox
param is wrong. I have to manually change EPSG:404000
(default value set by API) to EPSG:4326
in both layers to have the layer group show up in Leaflet (bbox
param is now correct).
I can specify a CRS value when creating a layer group via API but not when creating layers.
If I pass
<attribution>
<title>hello</title>
</attribution>
<bounds>
<crs>EPSG:4326</crs>
</bounds>
then layer's title is changed but not the CRS.
How can I change the CRS value of a layer via API?
Thanks!
As always the trick with any REST API is to look at the response from a correct layer (though in this case the real trick is to fix your shapefiles), so http://localhost:8080/geoserver/rest/workspaces/topp/datastores/states_shapefile/featuretypes/states.xml
:
<featureType>
<name>states</name>
<nativeName>states</nativeName>
<namespace>
<name>topp</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/namespaces/topp.xml" type="application/xml"/>
</namespace>
<title>USA Population</title>
<abstract>This is some census data on the states.</abstract>
<keywords>
<string>census</string>
<string>united</string>
<string>boundaries</string>
<string>state</string>
<string>states</string>
</keywords>
<nativeCRS>GEOGCS["GCS_WGS_1984",
DATUM["WGS_1984",
SPHEROID["WGS_1984", 6378137.0, 298.257223563]],
PRIMEM["Greenwich", 0.0],
UNIT["degree", 0.017453292519943295],
AXIS["Longitude", EAST],
AXIS["Latitude", NORTH]]</nativeCRS>
<srs>EPSG:4326</srs>
<nativeBoundingBox>
<minx>-124.73142200000001</minx>
<maxx>-66.969849</maxx>
<miny>24.955967</miny>
<maxy>49.371735</maxy>
<crs>EPSG:4326</crs>
</nativeBoundingBox>
<latLonBoundingBox>
<minx>-124.731422</minx>
<maxx>-66.969849</maxx>
<miny>24.955967</miny>
<maxy>49.371735</maxy>
<crs>EPSG:4326</crs>
</latLonBoundingBox>
<projectionPolicy>FORCE_DECLARED</projectionPolicy>
<enabled>true</enabled>
...
So it seems that you can specify the Native CRS and default CRS in the XML as either a WKT String or an EPSG code, in your case you want to override the native CRS (EPSG:40400, which means unknown) with EPSG:4326 (if that's what your data is actually in) so when modifying the featuretype
you need to POST at least:
<featureType>
<srs>EPSG:4326</srs>
<projectionPolicy>FORCE_DECLARED</projectionPolicy>
</featureType>
But I suspect you'll also need to set the latLonBoundingBox
unless it looks right any way.