Point order of ring (polygon geometry)

1835
8
Jump to solution
10-18-2019 12:58 PM
JamesCrandall
MVP Frequent Contributor
I'm querying a map service and using the polygon ring coordinates to the use as input geometry for another map service query. It looks like I'm not able to guarantee the point order of the first result and treats this as an outside ring (applying incorrect selections on the second query).
For example, I may have this as the initial ring:
{
  "rings": [
    [
      [
        -80.0929469116589,
        26.6756462518988
      ],
      [
        -80.0924963005446,
        26.6756390617361
      ],
      [
        -80.0924828894995,
        26.6753730253964
      ],
      [
        -80.092965687122,
        26.675375422123
      ],
      [
        -80.0929469116589,
        26.6756462518988
      ]
    ]
  ]
}
However, this selects features "outside" of that ring and it needs it to be in this order:
{
  "rings": [
    [
      [
        -80.0929469116589,
        26.6756462518988
      ],
      [
        -80.092965687122,
        26.675375422123
      ],
      [
        -80.0924828894995,
        26.6753730253964
      ],
      [
        -80.0924963005446,
        26.6756390617361
      ],
      [
        -80.0929469116589,
        26.6756462518988
      ]
    ]
  ]
}
Here's the basic code I am using to get the ring feature:
ringFeat = ''
qFl = 'https://services1.arcgis.com/sDAPyc2rGRn7vf9B/ArcGIS/rest/services/polySelectionLayer/FeatureServer/0/query'
sql = "OBJECTID=2"
qFlParams = urllib.urlencode({'f': 'json',
							   'geometryType': 'esriGeometryPolygon',
							   'geometry': '',
							   'spatialRel': 'esriSpatialRelIntersects',
							   'outSR': '4326',
							   'outFields': 'OBJECTID',
							   'returnGeometry': 'true',
							   'where': sql,
							   'token': token
							   })

reqFl = urllib2.Request(qFl, qFlParams)

errchk1 = ''
try:
	response = urllib2.urlopen(reqFl)
except urllib2.HTTPError, e:
	errchk1 = str(e.code)
except urllib2.URLError, e:
	errchk1 = str(e.code)

if errchk1 == '':
   
	jsonResult = json.load(response)
	appCount = len(jsonResult['features'])
	#if you have features, set the ringFeat to use in another query
	if appCount > 0:
		for feature in jsonResult['features']:
			ringFeat = feature['geometry']

#finalringFeat = json.loads(ringFeats)
print json.dumps(ringFeat)
finalRing = json.dumps(ringFeat)
0 Kudos
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor

We've determined the issue is with the hosted feature service (a new "Tracker" feature service).  ESRI is aware of the issue, closing this thread.

View solution in original post

8 Replies
JoshuaBixby
MVP Esteemed Contributor

Are the results in the example you give above always the same, in terms of results from first query, or does the ring order for that example vary?

0 Kudos
JamesCrandall
MVP Frequent Contributor

Hi Joshua,


The payload appears to be the same with each request made.

Of note: that is a hosted feature service I simply drew a couple of polygons in and then querying against it.  From the result ring I then use as input geometry to query/intersect with another map service (hosted fs points).  It selects all of the point features outside of that input ring!

Also: I can simply run the query from the REST query interface, copy the ring coordinates and then paste into the REST query interface of the point service and it gives me the same result.  So, I'm questioning if it's even an issue with my python implementation?

Anyway - thanks for any input!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

When you drew the polygons, do you recall if you drew them clockwise or counter-clockwise?

JamesCrandall
MVP Frequent Contributor

I tried both and it didn't seem to matter and get the same result with clockwise / counter-clockwise drawn features.

How about if I send the ring into the Simplify task of the Geometry service?  That seems to generate the desired coordinate order of the ring when I run it manually at the REST Geometry service Simplify task.  I think I can try a quick test in my .py implementation.

0 Kudos
JamesCrandall
MVP Frequent Contributor

What's odd is the first time I sent the output ring into the Simplify task and used that result as the input geometry in the query, it correctly returned the point features that fell inside of that ring.  Now, subsequent attempts (manually at the REST interface) does not perform the same selection result (selecting all points outside of that input simplified ring/geometry).

Head scratcher.

0 Kudos
JamesCrandall
MVP Frequent Contributor

I'm not sure how to proceed with this.  I've run some additional tests and the only thing I can think of is that I'm running into some sort of data issue.  The point feature service of interest is the source to the new ESRI "Tracker" app, but it's still just recording point features into a regular old hosted feature service.

I have added another hosted point feature service (symbolized with the black stars) and running the same exact query using the polygon as an inputGeometry, it selects 7 point features (which is correct). However, it selects 12 point features from the tracker point feature service (the light green symbols), which is obviously incorrect as there are many more points inside the polygon.

0 Kudos
JamesCrandall
MVP Frequent Contributor

We've determined the issue is with the hosted feature service (a new "Tracker" feature service).  ESRI is aware of the issue, closing this thread.

JoshuaBixby
MVP Esteemed Contributor

Thanks for sharing what you learned from Esri.