Point in polygon association

3506
7
Jump to solution
09-09-2015 02:42 PM
ChrisSmith7
Frequent Contributor

A few years back, when we were evaluating ArcGIS Server, I created a geoprocessing proof-of-concept service that received a lat/long and returned polygon IDs containing said point. There's now a need to actually use this feature, and within a high-volume environment, no less, so I've been looking to redevelop properly. There appear to be a few ways to go about this - Simple enough! However, what's the fastest, most performant way?

I have a map service containing a few thousand overlapping polygons (just need the layer to make the association) - I would like to send an x,y point (lat/long) and return a list of IDs from the map service.

I came across this thread:

How to find the polygon containing a given coordinate using ArcGIS Geometry Service? - Geographic In...

Should I go about it this way, or should I use GeometryService?

0 Kudos
1 Solution

Accepted Solutions
ChrisSmith7
Frequent Contributor

Ok, so, with a fresh brain, I realized I was going about this the wrong way. I had to ensure query capabilities were enabled for the layer (curiously, they had been disabled on my targeted service) - everything I needed to do was available for me to hit from asp.net by loading the service URL with querystring params:

http://yourGISserver.com/arcgis/rest/services/base_services/yourMapLayer/MapServer/0/query?where=&

text=&

objectIds=&

time=&

geometry=%7B%22x%22+%3A+-104.53%2C+%22y%22+%3A+34.74%7D%0D%0A&

geometryType=esriGeometryPoint&

inSR=4326&

spatialRel=esriSpatialRelWithin&relationParam=&

outFields=yourTargetField&

returnGeometry=false&

maxAllowableOffset=&

geometryPrecision=&

outSR=&

returnIdsOnly=false&

returnCountOnly=false&

orderByFields=&

groupByFieldsForStatistics=&

outStatistics=&

returnZ=false&

returnM=false&

gdbVersion=&

returnDistinctValues=false&

returnTrueCurves=false&

resultOffset=&

resultRecordCount=&

f=pjson

This returns a JSON object with the attributes I need!

{
"displayFieldName": "DisplayField",
"fieldAliases": {
  "yourTargetField": "yourTargetField"
},
"fields": [
  {
  "name": "yourTargetField",
  "type": "esriFieldTypeString",
  "alias": "yourTargetField",
  "length": 6
  }
],
"features": [
  {
  "attributes": {
    "yourTargetField": "FOO123"
  }
  },
  {
  "attributes": {
    "yourTargetField": "BAR321"
  }
  },
  {
  "attributes": {
    "yourTargetField": "BIZ789"
  }
  },
  {
  "attributes": {
    "yourTargetField": "BAT987"
  }
  }
]
}

View solution in original post

0 Kudos
7 Replies
SteveCole
Frequent Contributor

I don't have the answer but your question reminds me of a Blog post by ESRI about the client-side GeometryEngine which may be faster if you're dealing with a lot of features. GeometryEngine is in beta and only available in API v3.13 & above.

ChrisSmith7
Frequent Contributor

I was thinking about this - ideally, I'd like to be able to hit it through REST. Really, if I could use SQL Spatial Data, I'd be set (I can't, unfortunately).

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Chris,

   I think using a QueryTask would be the way to go.

  1. Are you dealing with one point or hundreds or more points?
  2. Are you only dealing with on polygon layer?
  3. Do you already have the polygon geometry at the client (because the layer is a FeatureLayer in your map)?
ChrisSmith7
Frequent Contributor

Robert,

1. I would be dealing with a single point at any given moment in time, such as when a user registered on the system.

2. Just one layer - technically, about 20 coincidental layers merged into one layer, with overlaps (strictly to obtain the associations)

3. I can, but what I'd really like to do is hit it from the server, e.g. something like this:

http://geoservices.tamu.edu/Services/CensusIntersection/WebService/v04_01/Rest/?lat=34.0726207996348...

Then massage and use the returned object server-side.

0 Kudos
TracySchloss
Frequent Contributor

I've seen a noticeable performance difference depending on whether I return the geometry or not.  If all you need is data values returned, a queryTask has worked OK for me, if I have the returnGeometry set to false.

ChrisSmith7
Frequent Contributor

Thanks, I will probably end-up going this route... I'll let you know how it ends-up.

0 Kudos
ChrisSmith7
Frequent Contributor

Ok, so, with a fresh brain, I realized I was going about this the wrong way. I had to ensure query capabilities were enabled for the layer (curiously, they had been disabled on my targeted service) - everything I needed to do was available for me to hit from asp.net by loading the service URL with querystring params:

http://yourGISserver.com/arcgis/rest/services/base_services/yourMapLayer/MapServer/0/query?where=&

text=&

objectIds=&

time=&

geometry=%7B%22x%22+%3A+-104.53%2C+%22y%22+%3A+34.74%7D%0D%0A&

geometryType=esriGeometryPoint&

inSR=4326&

spatialRel=esriSpatialRelWithin&relationParam=&

outFields=yourTargetField&

returnGeometry=false&

maxAllowableOffset=&

geometryPrecision=&

outSR=&

returnIdsOnly=false&

returnCountOnly=false&

orderByFields=&

groupByFieldsForStatistics=&

outStatistics=&

returnZ=false&

returnM=false&

gdbVersion=&

returnDistinctValues=false&

returnTrueCurves=false&

resultOffset=&

resultRecordCount=&

f=pjson

This returns a JSON object with the attributes I need!

{
"displayFieldName": "DisplayField",
"fieldAliases": {
  "yourTargetField": "yourTargetField"
},
"fields": [
  {
  "name": "yourTargetField",
  "type": "esriFieldTypeString",
  "alias": "yourTargetField",
  "length": 6
  }
],
"features": [
  {
  "attributes": {
    "yourTargetField": "FOO123"
  }
  },
  {
  "attributes": {
    "yourTargetField": "BAR321"
  }
  },
  {
  "attributes": {
    "yourTargetField": "BIZ789"
  }
  },
  {
  "attributes": {
    "yourTargetField": "BAT987"
  }
  }
]
}
0 Kudos