ArcPy data analysis SHAPE@XY token centroid different than SHAPE@ centroid value

7330
3
04-23-2014 08:24 AM
JA4
by
New Contributor II
Working with a dataset of municipal parcels (polygons) I've noticed a difference between the XY centroid value accessed through the SHAPE@XY token VS SHAPE@. While I can't post an example, I found this issue by comparing where points were placed when geocoding using an address locator that was created from the parcel polygons. For odd shaped parcels, such as long and narrow landscape areas that wrap around a housing development, the point generated from the SHAPE@XY value is placed at the true centroid of the polygon, "The center of gravity for a feature." The SHAPE@ token, when dissected like "poly_geom.centroid.X" and "poly_geom.centroid.Y" will provide the XY coordinates for the centroid or label point as described on the ArcPy Polygon page: "The true centroid if it is within or on the feature; otherwise, the label point is returned..."

So the point of this post is that using the SHAPE@XY token is misleading. It is the same as getting the SHAPE@TRUECENTROID value for X&Y. This is also true of the SHAPE@X or SHAPE@Y. This will cause issues for people who want to geocode address locations and then do any kind of spatial analysis where counting points in parcels is important. There will be odd shaped parcels that should have a point inside but don't, and points in other parcels that shouldn't be there but are placed due to the center of gravity of the odd parcel. I use the SHAPE@ token to avoid this issue, but that means more memory is consumed to hold the entire polygon geom object instead of the just the centroid, which makes for a slower script.

Have other people noticed this? I don't feel like this is a bug, but it would be nice to have a consistent meaning for centroid when working with both the SHAPE@XY token and the centroid properties of a polygon geom object.
Tags (2)
3 Replies
ChrisPedrezuela
Occasional Contributor III
I got this result,

for i in arcpy.da.SearchCursor("Ngaruawahia_StructurePlanAreas", ['SHAPE@', 'SHAPE@XY', 'SHAPE@TRUECENTROID']):
...     print (i[0].centroid.X,i[0].centroid.Y), i[1], i[2]
...     
(1789821.778531158, 5820949.009319027) (1789821.778531158, 5820949.009319027) (1789821.778531158, 5820949.009319027)
(1782710.746833228, 5828120.099465807) (1782710.746833228, 5828120.099465807) (1782710.746833228, 5828120.099465807)
(1793174.7978348304, 5834627.9375800025) (1793174.7978348304, 5834627.9375800025) (1793174.7978348304, 5834627.9375800025)
(1793743.185461287, 5824684.673387148) (1793743.185461287, 5824684.673387148) (1793743.185461287, 5824684.673387148)
(1790026.8500248736, 5828569.732378332) (1790026.8500248736, 5828569.732378332) (1790026.8500248736, 5828569.732378332)
(1791073.8189072697, 5832543.665935521) (1791073.8189072697, 5832543.665935521) (1791073.8189072697, 5832543.665935521)
(1772783.6783350855, 5873593.864663156) (1772783.6783350855, 5873593.864663156) (1772783.6783350855, 5873593.864663156)


Seems fine.
0 Kudos
AndrewLowerre
New Contributor III

Hi,

Running the same code as set out in the last post on a set of my own polygons (some of which are highly convoluted), I did not get identical results.

The coordinates returned by the 'SHAPE@XY' and 'SHAPE@TRUECENTROID' tokens were, without exception, identical. But for about 3% (29 of 1,038) of my polygons, the coords returned by getting centroid.X and centroid.Y from the geometry returned by the 'SHAPE@' token did not equal those returned by the other two tokens.

Like the original poster, I need points inside my polygons, rather than the 'true' centroids. I've found using the labelPoint property of the Polygon geometry object gets me what I need. I agree with J A that the documentation is less than clear, and that the results of using the different tokens are not what I would have expected.

The devil is, as always, in the details...

Cheers

0 Kudos
curtvprice
MVP Esteemed Contributor

Here's the help article on Geometry object properties

Geometry—Help | ArcGIS Desktop 

I also found two lists of geometry tokens (SHAPE@foo), which should be shortcuts to Geometry properties.  The second one is a little more complete.

SearchCursor—Help | ArcGIS Desktop 

Working with NumPy in ArcGIS—Help | ArcGIS Desktop 

0 Kudos