table with 2 sets X, Y

396
1
02-20-2019 02:10 PM
GeorgeKatsambas
Occasional Contributor III

I have a table that has an origin X, Y (XP YP) and a destination X, Y (XD, YD) and an in-house 3rd party program that creates a OD vector line, however, this 3rd party tool reads lat/lons only. is there a formular to convert X to longitude etc. This is a table so calculate geometry is not available. 

Tags (3)
0 Kudos
1 Reply
RandyBurton
MVP Alum

If you know the spatial reference of your x,y coordinates, you could use something like the following:

inSR = arcpy.SpatialReference(3857) # web mercator (use your spatial reference here)
outSR = arcpy.SpatialReference(4326) # wgs_1984 (lon-lat)

ptGeo = arcpy.PointGeometry(arcpy.Point(x,y),inSR).projectAs(outSR)
print (ptGeo.centroid.X, ptGeo.centroid.Y) # lon-lat of point‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

See Reprojecting tabular data without creating feature class? for more discussion.

0 Kudos