1

My goal is to perform search using filtered WFS attributes. I am using GeoServer 2.5, WFS version 1.0.0, GeoTools version 8.7. I found two solutions that should work according to the description that I found online.

First one:

final Filter filter = ECQL.toFilter("name ILIKE '%SiMpLe%'");
final Query query = new Query(layerName, filter);

When I look how query object looks like it is like that:

Query:
feature type: story:layer_name
filter: [ name is like %TeStInG% ]
[properties:  ALL ]

and it does not give me any data in return. I do not have any error as well, simply does not work...

Second one:

final Filter filter = ECQL.toFilter("strToLowerCase(name) LIKE '%SiMpLe%'");
final Query query = new Query(layerName, filter);

When I perform this query I got error:

javax.naming.OperationNotSupportedException: Cannot encode PropertyName opengis.net/ogc org.geotools.filter.function.FilterFunction_strToLowerCase
org.xml.sax.SAXException: Cannot encode PropertyName opengis.net/ogc org.geotools.filter.function.FilterFunction_strToLowerCase
javax.naming.OperationNotSupportedException: Cannot encode PropertyName opengis.net/ogc 
Caused by: java.util.NoSuchElementException: Could not aquire feature:java.io.IOException: org.xml.sax.SAXException: Cannot encode PropertyName opengis.net/ogc org.geotools.filter.function.FilterFunction_strToLowerCase
javax.naming.OperationNotSupportedException: Cannot encode PropertyName opengis.net/ogc org.geotools.filter.function.FilterFunction_strToLowerCase
    at org.geotools.data.store.NoContentIterator.next(NoContentIterator.java:58) [gt-main-8.7.jar:]
    at org.geotools.data.store.NoContentIterator.next(NoContentIterator.java:43) [gt-main-8.7.jar:]
    at org.geotools.feature.collection.DelegateFeatureIterator.next(DelegateFeatureIterator.java:58) [gt-main-8.7.jar:]

Caused by: java.io.IOException: org.xml.sax.SAXException: Cannot encode PropertyName opengis.net/ogc org.geotools.filter.function.FilterFunction_strToLowerCase
javax.naming.OperationNotSupportedException: Cannot encode PropertyName opengis.net/ogc org.geotools.filter.function.FilterFunction_strToLowerCase
    at org.geotools.data.wfs.v1_0_0.NonStrictWFSStrategy.createFeatureReader(NonStrictWFSStrategy.java:126) [gt-wfs-8.7.jar:]
    at org.geotools.data.wfs.v1_0_0.NonStrictWFSStrategy.getFeatureReader(NonStrictWFSStrategy.java:77) [gt-wfs-8.7.jar:]
    at org.geotools.data.wfs.v1_0_0.WFS_1_0_0_DataStore.getFeatureReader(WFS_1_0_0_DataStore.java:856) [gt-wfs-8.7.jar:]
    at org.geotools.data.DefaultFeatureResults.reader(DefaultFeatureResults.java:214) [gt-main-8.7.jar:]
    at org.geotools.data.store.DataFeatureCollection.openIterator(DataFeatureCollection.java:230) [gt-main-8.7.jar:]
    at org.geotools.data.store.DataFeatureCollection.iterator(DataFeatureCollection.java:198) [gt-main-8.7.jar:]
    at org.geotools.data.store.DataFeatureCollection.features(DataFeatureCollection.java:187) [gt-main-8.7.jar:]
Caused by: org.xml.sax.SAXException: Cannot encode PropertyName opengis.net/ogc org.geotools.filter.function.FilterFunction_strToLowerCase
javax.naming.OperationNotSupportedException: Cannot encode PropertyName opengis.net/ogc org.geotools.filter.function.FilterFunction_strToLowerCase
    at org.geotools.data.wfs.v1_0_0.WFS_1_0_0_DataStore.getFeatureReaderPost(WFS_1_0_0_DataStore.java:778) [gt-wfs-8.7.jar:]
    at org.geotools.data.wfs.v1_0_0.NonStrictWFSStrategy.createFeatureReaderPOST(NonStrictWFSStrategy.java:136) [gt-wfs-8.7.jar:]
    at org.geotools.data.wfs.v1_0_0.NonStrictWFSStrategy.createFeatureReader(NonStrictWFSStrategy.java:122) [gt-wfs-8.7.jar:]
    ... 117 more
Caused by: javax.naming.OperationNotSupportedException: Cannot encode PropertyName opengis.net/ogc org.geotools.filter.function.FilterFunction_strToLowerCase
    at org.geotools.xml.filter.FilterComplexTypes$PropertyNameType.encode(FilterComplexTypes.java:1540) [gt-xml-8.7.jar:]
    at org.geotools.xml.filter.FilterOpsComplexTypes$PropertyIsLikeType.encode(FilterOpsComplexTypes.java:1357) [gt-xml-8.7.jar:]
    at org.geotools.xml.filter.FilterOpsComplexTypes$ComparisonOpsType.encode(FilterOpsComplexTypes.java:379) [gt-xml-8.7.jar:]
    at org.geotools.xml.filter.FilterOpsComplexTypes.encodeFilter(FilterOpsComplexTypes.java:108) [gt-xml-8.7.jar:]
    at org.geotools.xml.filter.FilterOpsComplexTypes$FilterType.encode(FilterOpsComplexTypes.java:905) [gt-xml-8.7.jar:]
    at org.geotools.data.wfs.v1_0_0.xml.WFSBasicComplexTypes$QueryType.encode(WFSBasicComplexTypes.java:592) [gt-wfs-8.7.jar:]
    at org.geotools.data.wfs.v1_0_0.xml.WFSBasicComplexTypes$GetFeatureType.encode(WFSBasicComplexTypes.java:198) [gt-wfs-8.7.jar:]
    at org.geotools.xml.DocumentWriter.writeFragment(DocumentWriter.java:318) [gt-xml-8.7.jar:]
    at org.geotools.xml.DocumentWriter.writeDocument(DocumentWriter.java:216) [gt-xml-8.7.jar:]
    at org.geotools.data.wfs.v1_0_0.WFS_1_0_0_DataStore.getFeatureReaderPost(WFS_1_0_0_DataStore.java:775) [gt-wfs-8.7.jar:]
    ... 119 more

I also have tried with WFS with version 1.1.0, but again I got error. IN general I would like to work with WFS v 1.0.0.

DO you know what may causing this errors to appear?

Is it my app, or outdated geotools library (it supports ILIKE, I have seen sources), or maybe GeoServer?

  • 1
    those are so old it is unlikely that anyone will be able to definitively answer this. Please upgrade to a recent version such as GT18.1 and GS2.12. – Ian Turton Jan 5 '18 at 10:12
  • Possibly it's incorrect to say that the first one doesn't work. Rather it works but doesn't find any matches. – nmtoken Jan 8 '18 at 9:16
1

So repeating this using GeoTools 18.1 I get the following on a local 2.12.1 GeoServer install and the following code:

final Filter filter = ECQL.toFilter("STATE_NAME ILIKE 'north%'");
String layerName = "topp:states";
final Query query = new Query(layerName , filter);
System.out.println(query);
System.out.println(((org.geotools.filter.LikeFilterImpl)query.getFilter()).isMatchingCase());
SimpleFeatureSource source = datastore.getFeatureSource(name);
SimpleFeatureCollection feats = source.getFeatures(q);
System.out.println("size ="+feats.size());
try (SimpleFeatureIterator itr = feats.features()) {
  int count=0;
  while (itr.hasNext()) {
    SimpleFeature feature = itr.next();

    System.out.println((count++) + " " + feature.getAttribute("STATE_NAME"));

  }
}

Gives output as:

http://localhost:8080/geoserver/ows?request=getCapabilities&service=wfs&version=1.1.0
Query:
   feature type: topp:states
   filter: [ STATE_NAME is like north% ]
   [properties:  ALL ]
false
size =2
0 North Carolina
1 North Dakota

Your second example won't work as you need to convert both sides to lowercase for it to work. So

final Filter filter = ECQL.toFilter("strToLowerCase(name) LIKE '%SiMpLe%'");

becomes

final Filter filter = ECQL.toFilter("strToLowerCase(name) LIKE '%simple%'");

However, it seems there is a bug in the WFS client and it is silently dropping the attribute from the Query when it doesn't spot it in the properties list so that all GeoServer sees is

query[0]:
    filter = [  is like north% ]
    srsName = urn:x-ogc:def:crs:EPSG:4326
    typeName[0] = {http://www.openplans.org/topp}states
outputFormat = text/xml; subtype=gml/3.1.1
resultType = results

Update

On further testing, while ILIKE is not supported for WFS 1.0.0 your query should still work but this bug prevents it, but it does work with WFS 1.1.0 where the matchCase attribute was added.

  • Thank you for such a precise answer! I was afraid that it may be something wrong with the library. I see that even if not that old version is used there are some problems. It is strange that it is described in API, and no one else before me saw that this does not work... I think I have to stay with WFS1.0.0, so I guess there is nothing much I can do about it , can't I? BTW I know that both sides of query must be written in lower cases :) But since the code exploded in my face, I just did not change the second part to lower case, because it just was not relevant at that point. – paweluz Jan 8 '18 at 7:41
  • It's not that odd no one has noticed before now as this is an unsupported module that doesn't get used that much and the issue is just for ILIKE in one (old) version. – Ian Turton Jan 8 '18 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.