My observations and recommendation:
id
appears to be interpreted as an internal keyword for FeatureID and not a property/attribute/column name. Many datasets will use id
as a column name and might get tripped up by this.
Example, using the topp:states layer in the default data:
Here, id
is the FeatureID = states.49
and thus http://localhost:8080/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeNames=topp:states&outputFormat=json&cql_filter=id+IN+('states.49’) will return this one result.
However, if we customise the attributes and change attribute STATE_NAME
to id
, simulating a non-index database column called id
:
then http://localhost:8080/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeNames=topp:states&outputFormat=json&cql_filter=id+IN+('Washington’) will not match the record, as id
is being used as the FeatureID. In order to use the column id
, we need to put it in double quotes:
http://localhost:8080/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeNames=topp:states&outputFormat=json&cql_filter=“id”+IN+(‘Washington’), and this then works, as per the https://gis.stackexchange.com/questions/373005/geoserver-wms-cql-filter-id-xxx-works-but-id-in-xxx-does-not recommendation.
Simply using the IN(filter) format: http://localhost:8080/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeNames=topp:states&outputFormat=json&cql_filter=IN+(‘Washington’), implies the FeatureID id
and does not return any data.
The XML equivalent: http://localhost:8080/geoserver/wfs?request=GetFeature&version=1.0.0&typeName=topp:states&outputFormat=json&FILTER=%3CFilter%20xmlns%3D%22http%3A%2F%2Fwww.opengis.net%2Fogc%22%3E%3CPropertyIsEqualTo%3E%3CPropertyName%3Eid%3C%2FPropertyName%3E%3CLiteral%3EWashington%3C%2FLiteral%3E%3C%2FPropertyIsEqualTo%3E%3C%2FFilter%3E (which encodes this filter, for those of us who can’t easily URL-decode in our heads:
id Washington )does correctly use the attribute id
, as expected, and not the FeatureID id
.
According to the both https://docs.geoserver.org/latest/en/user/filter/ecql_reference.html and https://docs.geoserver.org/latest/en/user/tutorials/cql/cql_tutorial.html,
and
it appears as though we should be able to filter on attribute id
= Washington rather than FeatureID id
= states.49
If this is a bug (developers?), I wonder how many systems will break when it is fixed, or whether the best way forward is to simply document that an attribute id
is special and needs to be quoted thus: “id”. Let me know to fix the documentation.
Peter
GeoServer PSC
AWS Solutions Architect
https://github.com/petersmythe
···
–
Jody Garnett