Syntax to retrieve x/y coordinates in python?

14051
4
09-22-2010 12:49 PM
ThomasMeyer
New Contributor
I'm opening a point shapefile cursor, while row: ...

shouldn't it be something like:

row.shape.x  ??

I've tried for many hours looking for this answer online to no avail.  Is there no api?   I don't see Shape 'class' on the "Geoprocess Object Model", what am I missing?
0 Kudos
4 Replies
ThomasMeyer
New Contributor
Thanks a bunch!  that got me on the right track.  Although, sadly, I thought I'd be getting back a lat/long values as the x/y. 

I'm starting with a shapefile of nad/stateplane, project it to geographic, and want to then extract all the lat/long values (all within the script).  *sigh*  back to google...


edit: nevermind, it works, I forgot to uncomment the projection command, lol.  here is some code:


rows = gp.UpdateCursor(proj_shp)
row = rows.Next()
while row:
feat = row.shape
pnt = feat.GetPart(0)
print "x: " + str( pnt.x )
0 Kudos
GerryGabrisch
Occasional Contributor III
If they are points, just calculate xy values by calling the ArcToolbox tool, and populate the attribute table with lat/long.  Then use a search cursor to extract the lat long for each point.
0 Kudos
GerryGabrisch
Occasional Contributor III
If they are points, just calculate xy values by calling the ArcToolbox tool, and populate the attribute table with lat/long.  Then use a search cursor to extract the lat long for each point.


Sorry, what I meant to say was reproject the data into WGS84 and use the AddXY Coordinates tool to populate the attribute table with lats/longs, then use the cursor to step through the records.
0 Kudos