[GIS] ArcGIS Rest performing query on feature service layers using within and intercepts

arcgis-rest-apiarcgis-servercfeature-servicerest

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?

Best Answer

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.

Cheers!

N

Related Question