Search code examples
javascriptarcgisarcgis-serverarcgis-js-api

ArcGIS find conflict between layer and geometry


I have a problem I could use some help with. In our application we have multiple FeatureLayers and on some of these layers a user can draw new objects.

When a user draws a new object, lets call it a tent (any type of Geometry), I need to check if the position is valid. The object is valid when it does not consume the same position as a building. The buildings are stored on a separate featureLayer that is stored on a MapServer (and loaded in the browser). The drawing, the tent, is only stored locally (for now).

So to get to the point.. what is think I need is a service that finds the distance between all objects on a layer(the buildings) and the object that is drawn at-the-moment..

I did have a look at the SummarizeNearby services but at this moment we don’t have the license for it. Then I had a look at the GeometryService and I would like to know if this is the correct way to do it..

I think it is possible to use the difference or intersect method of the GeometryService to find the difference between all the graphic/geometries on the buildings-layer and the drawn-object. If the difference is the same size as the graphics in the buildings-layer, then there is no conflict. But if the result is different then the buildings-layer, then the buildings-layer did contain the object that is just drawn, and there-for the drawn object is not valid.

Please let me now if this is the way to go, or if there are other ways to calculate/find objects that intersect/overlap.

Many thanks!

Nico


Solution

  • If you're just looking to figure out that any of the 'tents' overlap any of the buildings, I would suggest doing a query on the building service using the tent geometry as your spatial filter.

    Here's the documentation on using the Query and QueryTask objects in the API. You could play around with the various spatial relationships to see what works for you. Set the geometry property equal to the tent geometry, create a QueryTask and call executeForCount. The callback function will give you the count of features, or in this case, buildings, that match the spatial query you just did.

    Here's a quick fiddle I threw together.