I am creating an application that needs to query a bunch of layers over REST to see which layers a point or line is within.

At the moment I have a local ArcGIS server set up with some feature services published. I can successfully connect to the services and retrieve results - I'm actually doing this from a C# application using a URL to query to feature service, then deserialising the JSON result.

Here is an example of how I am querying one of my services now: http://LocalArcGisServer.local.com:6080/arcgis/rest/services/SW/SW_2/FeatureServer/0/query?f=json&where=PROJECT='EP'

Now the bit I am struggling with. I have points and lines defined that I want to test against some layers in various feature services. For example, I want to see if my point is within a particular polygon, or if my line crosses a polygon.

How can I formulate a query to a REST service, passing in my point or line, and asking if that point is within the layer or not?

I think I need to pass in info to describe my input point or line, and ask the feature service to do a 'Within' or 'Intercepts' query. What are the parameters I need to set, or how would I reformulate that query?

2 Answers 2


Ok, I figured out how to do this.

As Stefan suggested, I had to add a couple of parameters to the URL:

geometry (value = e.g. 639739.5,7598259.3)

geometryType (value = esriGeometryPoint)

spatialRel (value = esriSpatialRelWithin)

Here is an example call: http://LocalArcGisServer.local.com:6080/arcgis/rest/services/SW/SW2/FeatureServer/2/query?f=json&geometry=**639739.5,7598259.3&**geometryType=esriGeometryPoint&spatialRel=esriSpatialRelWithin&returnGeometry=false";

If you do not need the geometry of the polygon which the point falls into, you need to set returnGeometry as false. It works very nicely indeed!

Here is a good example of using REST from C# to talk to an ArcGis Feature service: http://rexdotnet.blogspot.com.au/2009/11/using-arcgis-server-rest-api-in-net.html

Hope this mighthelp someone else too.




Take a look at the documentation http://resources.arcgis.com/en/help/rest/apiref/

You're probably looking for the mapservice or feature service query operation. Set the geometry and spatialRel parameters. The geometry would be your points or lines.

  • Thanks for that Stefan - the spatialRel seems to have an option for what I need: Description: The spatial relationship to be applied on the input geometry while performing the query. The supported spatial relationships include intersects, contains, envelope intersects, within, etc. The default spatial relationship is intersects (esriSpatialRelIntersects). Values: esriSpatialRelIntersects | esriSpatialRelContains | esriSpatialRelCrosses | esriSpatialRelEnvelopeIntersects | esriSpatialRelIndexIntersects | esriSpatialRelOverlaps | esriSpatialRelTouches | esriSpatialRelWithin Now to try it... Oct 2, 2014 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.