I'm trying to add a new layer to GeoServer using REST API. Here is REST API docs: https://docs.geoserver.org/latest/en/api/#/latest/en/api/1.0.0/wmslayers.yaml
Post request body:
<?xml version="1.0" encoding="UTF-8"?>
<wmsLayer>
<name>string</name>
<nativeName>string</nativeName>
<namespace>
<name>string</name>
<link>string</link>
</namespace>
<title>string</title>
<abstract>string</abstract>
<description>string</description>
<keywords>
<string>string</string>
</keywords>
<metadatalinks>
<metadataLink>
<type>string</type>
<metadataType>string</metadataType>
<content>string</content>
</metadataLink>
</metadatalinks>
<dataLinks>
<metadataLink>
<type>string</type>
<content>string</content>
</metadataLink>
</dataLinks>
<nativeCRS>string</nativeCRS>
<srs>string</srs>
<nativeBoundingBox>
<minx>0</minx>
<maxx>0</maxx>
<miny>0</miny>
<maxy>0</maxy>
<crs>string</crs>
</nativeBoundingBox>
<latLonBoundingBox>
<minx>0</minx>
<maxx>0</maxx>
<miny>0</miny>
<maxy>0</maxy>
<crs>string</crs>
</latLonBoundingBox>
<projectionPolicy>FORCE_DECLARED</projectionPolicy>
<enabled>true</enabled>
<metadata>
<@key>regionateStrategy</@key>
<text>string</text>
</metadata>
<store>
<@class>string</@class>
<name>string</name>
<href>string</href>
</store>
</wmsLayer>
How to add CQL filter for layer the same as I can do with GeoServer web interface?
1 Answer 1
As always with the REST API, the simple answer is build what you need once in the GUI and then ask the REST endpoint what it would like to see.
The key line seems to be:
<cqlFilter>STATE_ABBR like 'A%'</cqlFilter>
So I get the following:
<featureType>
<name>states2</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>states</title>
<keywords>
<string>features</string>
<string>states</string>
</keywords>
<nativeCRS>
GEOGCS["WGS 84", DATUM["World Geodetic System 1984", SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4326"]]
</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.73142200000001</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>
<store class="dataStore">
<name>topp:states_shapefile</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/states_shapefile.xml" type="application/xml"/>
</store>
<serviceConfiguration>false</serviceConfiguration>
<cqlFilter>STATE_ABBR like 'A%'</cqlFilter>
<maxFeatures>0</maxFeatures>
<numDecimals>0</numDecimals>
<padWithZeros>false</padWithZeros>
<forcedDecimal>false</forcedDecimal>
<overridingServiceSRS>false</overridingServiceSRS>
<skipNumberMatched>false</skipNumberMatched>
<circularArcPresent>false</circularArcPresent>
<attributes>....</attributes>
</featureType>
-
Thank you! It is very usefull.Belowee P.– Belowee P.2019年10月01日 07:42:13 +00:00Commented Oct 1, 2019 at 7:42