[GIS] Leaflet polygon (multi polygon) to CQL equivelent

cql-filtergeoserverjavascriptleafletpolygon

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() + ")";

Best Answer

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

Related Question