2

I am having trouble forming a properly formatted CQL request using geoServer cross layer filer functions and was hoping others could assist. My request is as follows:

http://localhost:8080/geoserver/wfs?request=GetFeature&typeName=AU:TownPoints&CQL_FILTER=INTERSECTS(the_geom,collectGeometries(queryCollection('AU:Districts','the_geom','CODE=A1')))&version=1.1.0

The intent is to select the towns that are within a selected District shape.

With the above request a null data set is returned:

<wfs:FeatureCollection xmlns:ogc="http://www.opengis.net/ogc" xmlns:AU="hidden.com" xmlns:tiger="http://www.census.gov" xmlns:cite="http://www.opengeospatial.net/cite" xmlns:nurc="http://www.nurc.nato.int" xmlns:sde="http://geoserver.sf.net" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:it.geosolutions="http://www.geo-solutions.it" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="http://www.openplans.org/spearfish" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" **numberOfFeatures="0"** timeStamp="2013-03-20T22:36:01.593Z" xsi:schemaLocation="hidden.com http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=DHS%3ATownPoints http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd">
<gml:featureMembers/>
</wfs:FeatureCollection>

I think the formatting of my query string 'CODE=A1' is wrong, so geoServer returns a null set for the queryCollection, meaning the intersection is being performed against a null set. (Note: CODE='A1' works fine if I query Districts directly.)

I have also tried 'CODE='A1'' and some other variations but this nesting always causes an exception similar to the following:

Could not parse CQL filter list. Encountered "A1" at line 1, column 92.
 Was expecting one of:
 ")" ...
 "," ...
 "/" ...
 "*" ...
 "+" ...
 "-" ...
 Parsing : INTERSECTS(the_geom,collectGeometries(queryCollection('AU:Districts','the_geom','CODE='A1''))).

I have looked at lots of examples but cannot find one with a filter string in the queryCollection function.

1
INTERSECTS(geom, collectGeometries(queryCollection('topp:states', 'the_geom', 'STATE_ABBR=" + "'" + "'" + 'CA' + "'" + "'" + "')))

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • 2
    Welcome to GIS.SE. While this is most likely the solution, some explanation would be useful. – John Powell Jul 7 '15 at 7:44
  • It woudn't let me edit my answer the other day! Building the second expression in this manner "'" + "'" + 'CA' + "'" + "'" allowed me to achieve a text attribute filter to query all points, of my data, within the shape of California. – Daniel Jul 9 '15 at 16:15
0

This source https://docs.datastax.com/en/dse/5.1/cql/cql/cql_using/cqlSyntax.html#Escapingcharacters is the best documentation I could find, when I was encountering this CQL problem.

It states that:

[...] To use a single quotation mark itself in a string literal, escape it using a single quotation mark.

And then shows this example:

INSERT INTO cycling.calendar (race_id, race_start_date, race_end_date, race_name) VALUES (201, '2015-02-18', '2015-02-22', 'Women''s Tour of New Zealand');

Therefore you could change @Daniels code from:

INTERSECTS(geom, collectGeometries(queryCollection('topp:states', 'the_geom', 'STATE_ABBR=" + "'" + "'" + 'CA' + "'" + "'" + "')))

to this:

INTERSECTS(geom, collectGeometries(queryCollection('topp:states', 'the_geom', 'STATE_ABBR=''CA''')))

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.