[GIS] Specifying input coordinate reference system for WFS

coordinate systemgeoservergetfeaturewfs

GeoServer allows to specify output CRS by parameter srsName in WFS GetFeature.

Is there a way to specify the input CRS?

I am displaying layers of different CRSs in my map – all reprojected to EPSG:900913. Therefore the WFS requests generated are also in EPSG:900913. What I want is to tell GeoServer that my inputs are in EPSG:900913 so that GeoServer can reproject my input and return the result.

I am using WFS version 2.0.0.

Best Answer

WFS version 1.0.0 supports officially only the default SRS/CRS both for input and output. However, many WFS server brands have backported the srsName parameter that came with WFS 1.1.0 at least for output. With some WFS servers srsName may work also for defining the input geometry but let's assume that it is not possible and concentrate on WFS 1.1.0. As far as I know WFS 2.0 did not change anything about srsNames.

The general method for using spatial filters in WFS is to use XML filters as defined in the OGC Filter Encoding standard. Here is an operational GetFeature POST request that works for GeoServers, for example the one at http://demo.opengeo.org/geoserver/wfs

<?xml version="1.0" encoding="ISO-8859-1"?>
<wfs:GetFeature xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" maxFeatures="1000" outputFormat="text/xml; subtype=gml/3.1.1">
<wfs:Query xmlns:topp="http://www.openplans.org/topp" srsName="EPSG:4326" typeName="topp:states">
<ogc:Filter>
<ogc:BBOX>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<gml:Envelope srsName="EPSG:4326">
<gml:lowerCorner>-114.33879630350562 38.719441534468004</gml:lowerCorner> <gml:upperCorner>-105.3631043169184 43.36299536870085</gml:upperCorner>
</gml:Envelope>
</ogc:BBOX>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>

You can see the definition of output CRS as parameter of wfs:Query and the definition of the reference geometry inside the BBOX filter. Notice that when srsName is given in a short format EPSG:4326 GeoServer awaits coordinates in longitude-latitude order. If srsName is given as urn:x-ogc:def:crs:EPSG:4326 then the coordinate order must follow the official EPSG definition of axis order which is latitude-longitude for 4326.

WFS has also shortcut of using BBOX filter as Key Value Pair parameter in http GET request. BBOX takes 5 parameters: xmin, ymin, xmax, ymax, SRID. However, the fifth parameter is not always used which leaves room for some mess because WFS 1.1.0 standard says that if SRID is missing then the BBOX is expressed as urn:x-ogc:def:crs:EPSG:4326 (remember the axis order). However, at least GeoServer is made to interpret such 4 parameter BBOX in the same way that WFS 1.0.0 i.e. to use the default projection.

This request is using BBOX in EPSG:4326 (lon-lat):

http://demo.opengeo.org/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature&typename=topp:states&BBOX=-114.33,38.71,-105.36,43.36,EPSG:4326

Compare with the same request using a 4-parameter BBOX which must now have a reversed axis order

http://demo.opengeo.org/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature&typename=topp:states&&BBOX=38.71,-114.33,43.36,-105.36

This request is using a BBOX that has the same extents but expressed as EPSG:3857 coordinates:

http://demo.opengeo.org/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature&typename=topp:states&BBOX=-12727157,4680216,-11728621,5366929,EPSG:3857

Some WFS servers do not understand the fifth parameter of BBOX at all and KVP requests can be done only in the default SRID or else all you get is an error message. You still remember that 4 parameter BBOX is officially WGS84 bounding box in lat-lon axis order - WFS can be messy.

EDIT BBOX is in WGS84 only in WFS 1.1.0 standard. In WFS 1.0.0 and again in 2.0.0 it defaults to the default SRS of the feature type.