0
votes

I'm currently creating a map in Openlayers for a customer that requires validation for drawing polygons inside another polygon (base-area). By using JSTS and Openlayers native methods, i'm able to validate that all shapes are drawn inside the polygon, and do not intersect with other shapes inside the polygon. This includes markers and polygons.

Another requirement is to check if the base-area is completely filled by other polygons, with pre-defined margins. I've not been able to think of any way to do this yet. What would be a good way to accomplish this?

EDIT:

Methods i used to check if polygon contains other polygon:

const geoJSONFormat = new GeoJSON();
const jstsGeoJSONReader = new jsts.io.GeoJSONReader();`

polygon1 = jstsGeoJSONReader.read(geoJSONFormat.writeFeatureObject(feature1)).geometry;

polygon2 = jstsGeoJSONReader.read(geoJSONFormat.writeFeatureObject(feature2)).geometry;


polygon1ContainsPolygon2= polygon1.contains(polygon2); `

First i pass the given feature the geoJSONFormat.writeFeatureObject which is imported from OL. And then assign this to a variable using the JSTS GeoJSON-reader.

contains-method from JSTS will return a boolean indicating if polygon2 is contained inside polygon1

1
What do you mean by predefined margins?Ryan Sparks
I am interested in knowing how you validated the polygons are inside another. Perhaps, Sharing a code snippet could help people like me.Jamshaid K.
@JamshaidKamran gladly. I've updated the post with that information. Hope it helps.Koronag

1 Answers

3
votes

Since you've already validated the polygons are inside the base-area and that they aren't overlapping. To check the base-area is completely filled, just check the sum of the area of the polygons is equal to the base-area.

I'm not entirely sure what you mean by margin but you could check the sum of the area of the polygons is at least some x% of the area of the base-area to give some "wiggle" room.