validate polygon within another polygon

10-12-2020 07:36 AM
MVP Frequent Contributor

I have been using this function to validate a polygon in the graphics layer by applying a negative buffer and then using geometryEngine.within to test if that buffer falls inside the selected polygon of another layer.

validateScheduleBoundary: function () {
            this.getScratchGeometry().then(lang.hitch(this, function (serverScratch) {
                this.workplanBoundaryLayer.queryFeatures(this.queryWorkplanLayer(), lang.hitch(this, function (result) {
                    var wpbuffer = geometryEngine.geodesicBuffer([0].geometry, -5, "meters")
                    var withinTest = geometryEngine.within(wpbuffer, result.features[0].geometry);
                    if (withinTest == false) {
                        alert("Schedule must be inside of the workplan boundary.  Try again.");
                        return false
                    else {
                        return true

This has worked until now with simple features however where the polygon used to check against has "holes" within it the within test fails.

Any suggestions on how to rework this?

Thanks for any input!

0 Kudos
1 Reply
MVP Frequent Contributor

What if I converted one to a polyline feature?

I've attempted to flip the order around and create the buffer on the polygon used to check if it falls inside of it, but I think the holes still prohibit the validation (it always returns False).

I also tried using the Extent of the polygon used to check if it falls inside of it, which does work, but I'm not sure how much accuracy I'm losing (especially with odd shaped polygons that may cause incorrect validation.

Any input is appreciated.

0 Kudos