2

I am using leaflet with geoserver. I want to set up a CQL filter to do an intersect but having an issue with getting the geometry from leaflet polygon to cql polygon.

For instance, the feature has the following.

gemoetry.coordinates is something like this when output as a string.

-90.89,46.67,-90.89,46.67,-90.89,46.67,-90.89,46.67,-90.89,46.67

CQL would need it in this format.

POLYGON((-90.89 46.67,-90.89 46.67,-90.89 46.67,-90.89 46.67,-90.89 46.67))

This would then be used to do something like this.

cql_filter=INTERSECTS(Geometry, POLYGON((-90.89 46.67,-90.89 46.67,-90.89 46.67,-90.89 46.67,-90.89 46.67))

However, it doesn't seem like leaflet has a toString or toCQL to convert a leaflet polygon to a CQL polygon. Now, one thing that comes to mind is writing a custom parser to go through and generate the CQL polygon needed to do the filter. This doesn't seem ideal to me and not sure how it would handle multipolygons. Is there an easy way to do this is leaflet?

UPDATE: Based on the answer, I used the wicket with the following code.

var wkt = new Wkt.Wkt();
wkt.fromObject(object.geometry)
var filter = "INTERSECTS(Geometry," + wkt.write() + ")";
3
POLYGON((-90.89 46.67,-90.89 46.67,-90.89 46.67,-90.89 46.67,-90.89 46.67))

Looks like WKT. If it is, you can convert features/layers/geojson to WKT using Wellknown or Wicket-Leaflet

0

Well Known Text (WKT) can be used in a CQL filter, and the format of various geometries (i.e. point, line , polygon, polygon with hole, multipolygons, etc.) is well-explained at https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry

Background: I was trying to create a CQL filter that is an amalgamation of several polygon features, to run an intersect against it.

That filter looks like:

INTERSECTS(
Shape, MULTIPOLYGON (((1523858.684 474675.641,etc. etc. ,1523858.684 474675.641)),
((1523926.206 474286.616, etc. etc., 1523926.206 474286.616)),
((1514053.87 488388.212,etc. etc. ,1514053.87 488388.212),
(1510959.8 474575.92, etc. etc.,1510959.8 474575.92)))

)

and I wasn't sure why it was not working.

I considered the following format:

POLYGON (((1523858.684 474675.641,etc. etc. ,1523858.684 474675.641)),
((1523926.206 474286.616, etc. etc., 1523926.206 474286.616)),
((1514053.87 488388.212,etc. etc. ,1514053.87 488388.212),
(1510959.8 474575.92, etc. etc.,1510959.8 474575.92)))

but the first format (with MULTIPOLYGON) is definitely the way to go.

My problem, I later learned, was not the CQL filter syntax, but the (excessive: 108,000 characters) character length of that CQL in my get request.

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.