Select to view content in your preferred language

Intersection is not accurate

313
3
04-04-2024 08:33 AM
AndreaRosati
New Contributor

Dear ESRI,

we built an application in Javascript where we are selecting a bunch of points on the ESRI map and retrieving selected points through the intersection with the graphic layer in the following way:

                        sketchViewModel.on("create", (event) => {
                            if (event.state === "complete") {
                                const extent = event.graphic.geometry.extent;
                                const intersection = graphicsLayer.graphics.filter((graphic) =>
                                    extent.intersects(graphic.geometry)
                                );
                                console.log("Items", intersection._items)
                                graphicsLayer.remove(event.graphic);
                                that.fireEvent("select", { event: intersection._items });
                            }
                        })

However, we noticed a strange behavior. We want to select all the points on a given street. If we proceed by selecting small blocks very close to the points, the process works fine, but if we select all the points together the intersection seems to take more points than requested, probably involving also the nearest points.

Look at this case. First we select 3 points

2024-04-03_09-42-08.png

and all seems fine:

2024-04-03_09-43-43.png

Three points are selected correctly. In the console you see 4 because one is always junk and not used.

Then we take 4 other points on the same street:

2024-04-03_09-45-46.png

Even in this case the result is correct:

2024-04-03_09-46-11.png

(One point is always junk and not used)

Finally, we select the remaining 2 points

2024-04-03_09-48-01.png

and in this case too, all is correct.

2024-04-03_09-48-22.png

So, in total, I've selected 9 points (consider that for each selection one is always dummy)

But, if select all the points together using a segmented line

2024-04-03_09-49-22.png

it brings me more than the ones I selected

2024-04-03_09-50-03.png

How can I fix this strange behavior? Why it's not so accurate when I extract the selected points?

Thanks

0 Kudos
3 Replies
SteveCole
Frequent Contributor

Others are far more proficient in 4.x than I am but could it be that you're using event.graphic.geometry.extent which might be treated as a bounding box for the graphic rather than it's actual shape?

In the selections that work, you'll notice that there aren't other points located within the square of your selection but if you look at your polygon selection, and use the xmin,ymin.xmax,ymax rectangle of the polygon, you'll see that many other points would be selected based on that rectangular shape.

AndreaRosati
New Contributor

Hi Steve, thanks for your answer!

However, I'm not sure this is the real cause of the problem. Indeed, if I rotate a little bit the map and use only the rectangular selection, I have the same issue. Look at this new example.

I have 9 points here on the same street with a shorter selection:

2024-04-05_09-00-45.png2024-04-05_09-01-22.png

But as soon as I extend the selection on the right, without including other points, the number of the points returned is greater:

2024-04-05_09-02-00.png2024-04-05_09-02-32.png

Very strange behaviour. I hope that someone can help me on this.

Andrea

0 Kudos
JohnGrayson
Esri Regular Contributor

Andrea,
    if you rotated the map then the extent might not be what you think it is.  As mentioned by Steve, you should not use the extent as it will not provide the correct intersection results since the geometry and the extent are different.  Maybe something like the code below might help.  Also, its hard to tell exactly what might be going on, so something that will help is if you have a CodePen or similar so we can experience the issue and help you out.

const searchGeometry = event.graphic.geometry;
const intersections = graphicsLayer.graphics.filter((graphic) =>
    geometryEngine.intersects(searchGeometry,graphic.geometry)
);

 

0 Kudos