Using the spatial reference class
Geographic datasets, such as feature classes, coverages, and rasters, have a spatial reference that defines a dataset's coordinate system, x,y domain, m-domain, and z-domain. Each part of the spatial reference has a number of properties, especially the coordinate system, which defines what map projection options are used to define horizontal coordinates. All this information is available from the spatial reference property, which is actually another object containing a number of properties.
import arcpy # Describe a feature class # fc = "D:/St_Johns/data.gdb/roads" desc = arcpy.Describe(fc) # Get the spatial reference # sr = desc.spatialReference # Check if the feature class is in projected space # if sr.type == "Projected": arcpy.Copy_management(fc,"D:/St_Johns/data.gdb/roads_UTM")
Creating a spatial reference using a projection (.prj) file
It is not often practical to keep all details of a spatial reference inside a Python script. By using a projection file as an argument to the SpatialReference class, you can quickly complete the properties of a spatial reference and use the object as input to a geoprocessing tool. In the following example, the spatial reference is constructed using a projection file supplied as an input argument.
import arcpy inputWorkspace = "c:/temp" outputName = "rivers.shp" # Get the input workspace, the output name for the new feature class # and path to an input projection file # inputWorkspace = arcpy.GetParameterAsText(0) outputName = arcpy.GetParameterAsText(1) prjFile = arcpy.GetParameterAsText(2) # Use the the projection file as input to the SpatialReference class # spatialRef = arcpy.SpatialReference(prjFile) # Use the SpatialReference object to create a new feature class with a # specific coordinate system # arcpy.CreateFeatureClass_management(inputWorkspace, outputName, "POLYLINE", "", "", "", spatialRef)
For a full list of properties and methods, see SpatialReference class.
Spatial references are sometimes referred to as Projection Engine strings. The Projection Engine (PE) is a library of code that all of ArcGIS uses for defining map projections and transforming from one projection to another.