REST find nearest feature

1928
4
10-12-2017 11:33 AM
PaulKroseman
Occasional Contributor II

I'm want to query my feature service to find the feature nearest to a specific point. My current procedure is query all features within a certain radius, iterate for each feature in the result and calculate the distance to the point, then return the feature with the least distance.

This seems inefficient. Is there a Near/Nearest tool available to REST for doing this better, or at least requiring less code in my application?

Using ArcGIS Server 10.3.1.

0 Kudos
4 Replies
RandallWilliams
Esri Regular Contributor

You can publish the NEAR tool as a GP Tool. Portal for ArcGIS has the Find Nearest tool available OOTB.

http://server.arcgis.com/en/portal/latest/use/find-nearest.htm

I think the OOTB spatial analysis tools documented above were introduced at 10.4.

nicogis
MVP Frequent Contributor

without prepare the data (Quadtree ect.) with structure precalculated you could trivially increase the radius of the circle until it intersects at least one feature and then loop only on these. I do it for example with a soe.

PaulKroseman
Occasional Contributor II

You can publish the NEAR tool as a GP Tool. Portal for ArcGIS has the Find Nearest tool available OOTB.

The Near GP tool didn't work. It fails with schema is read-only error even when the near fields already exist. It also appears I would have to publish the GP tool once for each different input feature class.

The Portal tool might work. I don't have Portal installed currently so I'm stuck with my current solution.

without prepare the data (Quadtree ect.) with structure precalculated you could trivially increase the radius of the circle until it intersects at least one feature and then loop only on these. I do it for example with a soe.

This is close to what I do currently. I start with a radius that is likely to return 1 feature, then double the radius until at least 1 feature is found, finally iterate the results to find the nearest.

0 Kudos
rylincoln
New Contributor

Is this still really true? seems completely ridiculous to have an underlying spatial database like postgis/postgresql and not be able to leverage a basic "nearest" query without publishing a custom GP tool...

0 Kudos