Clip Leaflet with WMS MultiPolygon Geometry

I’m trying to clip the WMS layer to multiple geometries.

My understanding is that the WMS layer call accepts “GEOMETRY” as a parameter, and that a “MultiPolygon” is the accepted way to clip the layer to multiple geometries.

The problem is that the data returned is not “filling” all polygon’s (see image), and not quite sure what I am doing wrong.

If I zoom out significantly, the area that is missing is filled.

Any idea what the issue could be?

This is the WKT for the geometry:

MULTIPOLYGON (((30.551724654842133 -29.44420920817037, 30.55235458417772 -29.445546325014504, 30.553732554600685 -29.445100621357035, 30.553338848766884 -29.44420920817037, 30.55471681918985 -29.443557785890043, 30.554441225104654 -29.442889216571032, 30.551724654842133 -29.44420920817037), (30.54692144365424 -29.43730049053851, 30.545582843814714 -29.441569207807582, 30.546271829025443 -29.44170635237385, 30.548043505283715 -29.437317634340324, 30.54692144365424 -29.43730049053851)))

Below is an example of the request URL:********************************66?service=WMS&request=GetMap&layers=NDVI&styles=&format=image%2Fpng&transparent=true&version=1.1.1&maxcc=50&time=2023-01-08%2F2023-01-08&geometry=MULTIPOLYGON%20(((30.551724654842133%20-29.44420920817037%2C%2030.55235458417772%20-29.445546325014504%2C%2030.553732554600685%20-29.445100621357035%2C%2030.553338848766884%20-29.44420920817037%2C%2030.55471681918985%20-29.443557785890043%2C%2030.554441225104654%20-29.442889216571032%2C%2030.551724654842133%20-29.44420920817037)%2C%20(30.54692144365424%20-29.43730049053851%2C%2030.545582843814714%20-29.441569207807582%2C%2030.546271829025443%20-29.44170635237385%2C%2030.548043505283715%20-29.437317634340324%2C%2030.54692144365424%20-29.43730049053851)))&width=512&height=512&srs=EPSG%3A4326&bbox=30.541992187500004,-29.44916482692468,30.552978515625004,-29.439597566602902

Hi @jens.hiestermann ,

The bbox set in the request url is cutting your geometry. Could you try the url below and see if it works?********************************66?service=WMS&request=GetMap&layers=NDVI&styles=&format=image%2Fpng&transparent=true&version=1.1.1&maxcc=50&time=2023-01-08%2F2023-01-08&geometry=MULTIPOLYGON%20(((30.551724654842133%20-29.44420920817037%2C%2030.55235458417772%20-29.445546325014504%2C%2030.553732554600685%20-29.445100621357035%2C%2030.553338848766884%20-29.44420920817037%2C%2030.55471681918985%20-29.443557785890043%2C%2030.554441225104654%20-29.442889216571032%2C%2030.551724654842133%20-29.44420920817037)%2C%20(30.54692144365424%20-29.43730049053851%2C%2030.545582843814714%20-29.441569207807582%2C%2030.546271829025443%20-29.44170635237385%2C%2030.548043505283715%20-29.437317634340324%2C%2030.54692144365424%20-29.43730049053851)))&width=512&height=512&srs=EPSG%3A4326&bbox=30.5455828438147137,-29.4455463250145044,30.5547168191898493,-29.4373004905385116

Thanks for the response @chung.horng.

I understood from a response from @gmilcinski in another forum that bbox & geometry will intersect the two and data will only be returned for the intersecting area, the problem is that I am not submitting a bbox in the call to WMS service.

Please see this jsfiddle with the problem and issue. This actually should be 5 full fields but I only see 2 fields.

Let me know how I can achieve showing data for all 5 fields please.

Hi @jens.hiestermann ,

I checked the fiddle and from the developer tool I can see that bbox is included in the url that causes the response being clipped.

In the fiddle, the following two lines probably set the Leaflet’s bbox and it is automatically added to the request when using Leaflet’s WMSLayer. I suspect that If this initial bbox cuts off the geometries and the zoom is not moved/changed correspondingly, the response will be clipped.

var center = [-29.4412, 30.549964459422308];
var map ='map').setView(center, 16);

Hi @chung.horng, the issue was with the “MultiPolygon” geometry as WKT. If I use shapely to determine the bounds of this erroneous multipolygon, the bounds cover 1 field only, and not ALL fields as expected. Therefore the incorrect bounds generated from the multipolygon attached to the “geometry” param of the WMS request was that single field.

I recreated the multipolygon WKT, and it worked perfectly.
Apologies about this and thank you for checking.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.