Skip to content

Instantly share code, notes, and snippets.

@scw
Created August 26, 2013 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scw/6343532 to your computer and use it in GitHub Desktop.
Save scw/6343532 to your computer and use it in GitHub Desktop.
Compare between ArcGIS and Proj.4 when converting between WGS84 and Mass State Plane.
import pyproj
import arcpy
# ArcMap result (meters):
# 306,414.514 854,124.573
x = -70.216908
y = 41.930268
# perform projection using pyproj (PROJ.4)
p1 = pyproj.Proj(init='epsg:4326') # geographic WGS84
p2 = pyproj.Proj(init='epsg:26986') # Mass State Plane
p_x,p_y = pyproj.transform(p1,p2,x,y)
# perform projection using Arcpy (PE)
sr_wgs84 = arcpy.SpatialReference(4326)
sr_msp = arcpy.SpatialReference(26986)
point = arcpy.Point(x, y)
point_geom = arcpy.PointGeometry(point, sr_wgs84)
proj_point = point_geom.projectAs(sr_msp)
a_x, a_y = (proj_point.firstPoint.X, proj_point.firstPoint.Y)
print """pyproj:\t\tarcpy:
{0}\t{1}
{2}\t{3}""".format(p_x, a_x, p_y, a_y)
@scw
Copy link
Author

scw commented Aug 26, 2013

$ python compare-projection.py
pyproj:         arcpy:
306414.524181   306414.524181
854124.578684   854124.578684

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment