# SpatialReference

## Summary

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.

## Discussion

A SpatialReference can be easily created from existing datasets and PRJ files:

- Use a PRJ file as an argument to the SpatialReference class.
import arcpy, os prjFile = os.path.join(arcpy.GetInstallInfo()["InstallDir"], "Coordinate Systems/Geographic Coordinate Systems/North America/NAD 1983.prj") spatialRef = arcpy.SpatialReference(prjFile)

- Describe a dataset and access its spatialReference property.
dataset = "C:/Data/Landbase.gdb/Wetlands" spatialRef = arcpy.Describe(dataset).spatialReference

Which spatial reference properties are available depends on the coordinate system used. In the properties list below, those properties only available with a Projected Coordinate system are denoted with a ^{1}; properties available only with a Geographic Coordinate system are denoted with a ^{2}.

## Syntax

**SpatialReference (prjFile)**

Parameter | Explanation | Data Type |

prjFile |
The projection file used to populate the spatial reference object. | String |

## Properties

Property | Explanation | Data Type |

MDomain (Read Only) |
The extent of the measure domain. | String |

MFalseOriginAndUnits (Read Only) |
The measure false origin and units. | String |

MResolution (Read and Write) |
The measure resolution. | Double |

MTolerance (Read and Write) |
The measure tolerance. | Double |

XYResolution (Read and Write) |
The xy resolution. | Double |

XYTolerance (Read and Write) |
The xy tolerance. | Double |

ZDomain (Read Only) |
The extent of the Z domain. | String |

ZFalseOriginAndUnits (Read Only) |
The Z false origin and units. | String |

ZResolution (Read and Write) |
The Z resolution property. | Double |

ZTolerance (Read and Write) |
The Z tolerance property. | Double |

abbreviation (Read and Write) |
The abbreviated name of the spatial reference. | String |

alias (Read and Write) |
The alias of the spatial reference. | String |

domain (Read Only) |
The extent of the xy domain. | String |

factoryCode (Read and Write) |
The factory code of the spatial reference. | Integer |

falseOriginAndUnits (Read Only) |
The false origin and units. | String |

hasMPrecision (Read Only) |
Indicates whether or not m-value precision information has been defined. | Boolean |

hasXYPrecision (Read Only) |
Indicates whether or not xy precision information has been defined. | Boolean |

hasZPrecision (Read Only) |
Indicates whether or not z-value precision information has been defined. | Boolean |

isHighPrecision (Read and Write) |
Indicates whether or not the spatial reference has high precision set. | Boolean |

name (Read and Write) |
The name of the spatial reference. | String |

remarks (Read and Write) |
The comment string of the spatial reference. | String |

type (Read and Write) |
The type of the spatial reference. | String |

usage (Read Only) |
The usage notes. | String |

PCSCode (Read and Write) |
The projected coordinate system code. | Integer |

PCSName (Read and Write) |
The projected coordinate system name. | String |

azimuth (Read and Write) |
The azimuth of a projected coordinate system. | Double |

centralMeridian (Read and Write) |
The central meridian of a projected coordinate system. | Double |

centralMeridianInDegrees (Read and Write) |
The central meridian (Lambda0) of a projected coordinate system in degrees. | Double |

centralParallel (Read and Write) |
The central parallel of a projected coordinate system. | Double |

classification (Read Only) |
The classification of a map projection. | String |

falseEasting (Read and Write) |
The false easting of a projected coordinate system. | Double |

falseNorthing (Read and Write) |
The false northing of a projected coordinate system. | Double |

latitudeOf1st (Read and Write) |
The latitude of the first point of a projected coordinate system. | Double |

latitudeOf2nd (Read and Write) |
The latitude of the second point of a projected coordinate system. | Double |

linearUnitCode (Read and Write) |
The linear unit code. | Integer |

linearUnitName (Read and Write) |
The linear unit name. | String |

longitudeOf1st (Read and Write) |
The longitude of the first point of a projected coordinate system. | Double |

longitudeOf2nd (Read and Write) |
The longitude of the second point of a projected coordinate system. | Double |

longitudeOfOrigin (Read and Write) |
The longitude of origin of a projected coordinate system. | Double |

projectionCode (Read and Write) |
The projection code. | Integer |

projectionName (Read and Write) |
The projection name. | String |

scaleFactor (Read and Write) |
The scale factor of a projected coordinate system. | Double |

standardParallel1 (Read and Write) |
The first parallel of a projected coordinate system. | Double |

standardParallel2 (Read and Write) |
The second parallel of a projected coordinate system. | Double |

GCSCode (Read and Write) |
The geographic coordinate system code. | Integer |

GCSName (Read and Write) |
The geographic coordinate system name. | String |

angularUnitCode (Read and Write) |
The angular unit code. | Integer |

angularUnitName (Read and Write) |
The angular unit name. | String |

datumCode (Read and Write) |
The datum code. | Integer |

datumName (Read and Write) |
The datum name. | String |

flattening (Read and Write) |
The flattening ratio of this spheroid. | Double |

longitude (Read and Write) |
The longitude value of this prime meridian. | Double |

primeMeridianCode (Read and Write) |
The prime meridian code. | Integer |

primeMeridianName (Read and Write) |
The prime meridian name. | String |

radiansPerUnit (Read Only) |
The radians per angular unit. | Double |

semiMajorAxis (Read and Write) |
The semi-major axis length of this spheroid. | Double |

semiMinorAxis (Read and Write) |
The semi-minor axis length of this spheroid. | Double |

spheroidCode (Read and Write) |
The spheroid code. | Integer |

spheroidName (Read and Write) |
The spheroid name. | String |

## Method Overview

Method | Explanation |

create () |
Creates the spatial reference object using properties. |

createFromFile (prj_file) |
Creates the spatial reference object from a projection file. |

exportToString () |
Exports the object to its string representation. |

loadFromString (string) |
Restore the object using its string representation. The exportToString method can be used to create a string representation. |

setDomain (x_min, x_max, y_min, y_max) |
Sets the XY domain. |

setFalseOriginAndUnits (false_x, false_y, xy_units) |
Sets the XY false origin and units. |

setMDomain (m_min, m_max) |
Sets the M domain. |

setZDomain (z_min, z_max) |
Sets the Z domain. |

setMFalseOriginAndUnits (false_m, m_units) |
Sets the M false origin and units. |

setZFalseOriginAndUnits (false_z, z_units) |
Sets the Z false origin and units. |

## Methods

**create ()**

**createFromFile (prj_file)**

Parameter | Explanation | Data Type |

prj_file |
The projection file used to populate the spatial reference object. | String |

**exportToString ()**

Data Type | Explanation |

String |
The string representation of the object. |

**loadFromString (string)**

Parameter | Explanation | Data Type |

string |
The string representation of the object. | String |

**setDomain (x_min, x_max, y_min, y_max)**

Parameter | Explanation | Data Type |

x_min |
The minimum x-value. | Double |

x_max |
The maximum x-value. | Double |

y_min |
The minimum y-value. | Double |

y_max |
The maximum y-value. | Double |

**setFalseOriginAndUnits (false_x, false_y, xy_units)**

Parameter | Explanation | Data Type |

false_x |
The false x value. | Double |

false_y |
The false y value. | Double |

xy_units |
The xy units. | String |

**setMDomain (m_min, m_max)**

Parameter | Explanation | Data Type |

m_min |
The minimum m-value. | Double |

m_max |
The maximum m-value. | Double |

**setZDomain (z_min, z_max)**

Parameter | Explanation | Data Type |

z_min |
The minimum z-value. | Double |

z_max |
The maximum z-value. | Double |

**setMFalseOriginAndUnits (false_m, m_units)**

Parameter | Explanation | Data Type |

false_m |
The false m-value. | Double |

m_units |
The m units. | Double |

**setZFalseOriginAndUnits (false_z, z_units)**

Parameter | Explanation | Data Type |

false_z |
The false z-value. | Double |

z_units |
The false z units. | Double |

## Code Sample

For each feature class in a workspace, print the name of its spatial reference.

import arcpy from arcpy import env # Set the workspace environment # env.workspace = "C:/base/base.gdb" # Get a list of the feature classes in the input folder # fcs = arcpy.ListFeatureClasses() # Loop through the list # for fc in fcs: # Create the spatial reference object # sr = arcpy.Describe(fc).spatialReference # If the spatial reference is unknown # if sr.name == "Unknown": print fc + " has an unknown spatial reference\n" # Otherwise, print out the feature class name and # spatial reference # else: print fc + ": " + sr.name + "\n"

Create a SpatialReference using a .prj file.

import arcpy prjFile = "c:/Program Files/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems" + \ "/Continental/North America/USA Contiguous Equidistant Conic.prj" # Create a spatial reference object using a projection file # sr = arcpy.SpatialReference(prjFile)

Create a SpatialReference from a factory code.

import arcpy # Create a spatial reference object using a factory code # sr = arcpy.SpatialReference() sr.factoryCode = 3857 sr.create()