Monday, 1 July 2013

Spatial Reference Information

My biggest teaching bug is students that don't know what spatial reference system they are using or more importantly, why it is important.  This small script shows you how to obtain bits of information about the system you are using.

'''
SpatialReferenceDemo.py

Demonstrates a few things about the spatial reference within arcpy
'''
import os
import arcpy

#uncomment your preferred coordinate system
#coord_sys = "Coordinate Systems/Geographic Coordinate Systems/World/WGS 1984.prj"
#coord_sys = "Coordinate Systems/Geographic Coordinate Systems/North America/NAD 1983.prj"
coord_sys = "Coordinate Systems/Projected Coordinate Systems/UTM/NAD 1983/NAD 1983 UTM Zone 18N.prj"
#coord_sys = "Coordinate Systems/Projected Coordinate Systems/National Grids/Canada/NAD 1983 MTM 9.prj"

print "\nSpatial Reference information: "
if coord_sys != None:
  prj_file = os.path.join(arcpy.GetInstallInfo()['InstallDir'],coord_sys)
  SR = arcpy.SpatialReference(prj_file)
  print "Coordinate system type: ", SR.type
  if SR.type == "Projected":
    print "PCS name: ",SR.PCSName
  else:
    print "GCS name: ", SR.GCSName
  print "xy resolution: ", SR.XYResolution
  print "xy tolerance: ", SR.XYTolerance
  print "high precision: ", SR.isHighPrecision
else:
  print"  no spatial reference specified"


No comments:

Post a Comment