Summary
Each part of the spatial reference has a number of properties (especially the coordinate system) that defines what map projection options are used to define horizontal coordinates.
Discussion
A SpatialReference object can also be accessed from existing datasets using the Describe spatialReference property.
dataset = "c:/data/landbase.gdb/Wetlands"
spatial_ref = arcpy.Describe(dataset).spatialReference
XY, Z, and M extents are not the same as spatial reference domains. The XY, Z, and M domains in a spatial reference define the valid range of coordinate values that can be stored in a feature class. The feature class extents reflect the actual range of coordinate values that exist in the feature class. These extents cannot be larger than the domains.
Note:
The spatial reference properties available depend on the coordinate system used. In the properties list below, those properties that are only available with a projected coordinate system are denoted with a 1; properties only available with a geographic coordinate system are denoted with a 2.
Because a projected coordinate system is based on a geographic coordinate system, projected coordinate system properties can be accessed from a geographic coordinate system via the GCS property.
Syntax
SpatialReference ({item}, {vcs}, text)
Parameter | Explanation | Data Type |
item | The horizontal coordinate system used to create the SpatialReference. The coordinate system can be set using a projection file, name, or factory code.
For more information about coordinate system names and factory codes, see the geographic_coordinate_systems.pdf and projected_coordinate_systems.pdf files. For more information, see Using the spatial reference class. | Variant |
vcs | The vertical coordinate system (VCS). The VCS defines information about the z-coordinates, and can be set using a name or factory code. See the following examples:
| Variant |
text | A well-known text (WKT) string that can be used to define a horizontal and vertical coordinate system.
| String |
Properties
Property | Explanation | Data Type |
GCS (Read Only) | A projected coordinate system returns a SpatialReference object for the geographic coordinate system it is based on. A geographic coordinate system returns the same SpatialReference. | SpatialReference |
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 |
VCS (Read Only) | If the coordinate system has a vertical coordinate system, it returns a VCS object for the vertical coordinate system it is based on. | Object |
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 or well-known ID (WKID) of the spatial reference. | Integer |
falseOriginAndUnits (Read Only) | The false origin and units. | String |
hasMPrecision (Read Only) | Indicates whether m-value precision information has been defined. | Boolean |
hasXYPrecision (Read Only) | Indicates whether xy precision information has been defined. | Boolean |
hasZPrecision (Read Only) | Indicates whether z-value precision information has been defined. | Boolean |
isHighPrecision (Read and Write) | Indicates whether 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.1 | Integer |
PCSName (Read and Write) | The projected coordinate system name.1 | String |
azimuth (Read and Write) | The azimuth of a projected coordinate system.1 | Double |
centralMeridian (Read and Write) | The central meridian of a projected coordinate system.1 | Double |
centralMeridianInDegrees (Read and Write) | The central meridian (Lambda0) of a projected coordinate system in degrees.1 | Double |
centralParallel (Read and Write) | The central parallel of a projected coordinate system.1 | Double |
classification (Read Only) | The classification of a map projection.1 | String |
falseEasting (Read and Write) | The false easting of a projected coordinate system.1 | Double |
falseNorthing (Read and Write) | The false northing of a projected coordinate system.1 | Double |
latitudeOf1st (Read and Write) | The latitude of the first point of a projected coordinate system.1 | Double |
latitudeOf2nd (Read and Write) | The latitude of the second point of a projected coordinate system.1 | Double |
latitudeOfOrigin (Read and Write) | The latitude of origin of a projected coordinate system.1 | Double |
linearUnitCode (Read and Write) | The linear unit code.1 | Integer |
linearUnitName (Read and Write) | The linear unit name.1 | String |
longitude (Read and Write) | The longitude value of this prime meridian.1 | Double |
longitudeOf1st (Read and Write) | The longitude of the first point of a projected coordinate system.1 | Double |
longitudeOf2nd (Read and Write) | The longitude of the second point of a projected coordinate system.1 | Double |
longitudeOfOrigin (Read and Write) | The longitude of origin of a projected coordinate system.1 | Double |
metersPerUnit (Read Only) | The meters per linear unit.1 | Double |
projectionCode (Read and Write) | The projection code.1 | Integer |
projectionName (Read and Write) | The projection name.1 | String |
scaleFactor (Read and Write) | The scale factor of a projected coordinate system.1 | Double |
standardParallel1 (Read and Write) | The first parallel of a projected coordinate system.1 | Double |
standardParallel2 (Read and Write) | The second parallel of a projected coordinate system.1 | Double |
GCSCode (Read and Write) | The geographic coordinate system code.2 | Integer |
GCSName (Read and Write) | The geographic coordinate system name.2 | String |
angularUnitCode (Read and Write) | The angular unit code.2 | Integer |
angularUnitName (Read and Write) | The angular unit name.2 | String |
datumCode (Read and Write) | The datum code.2 | Integer |
datumName (Read and Write) | The datum name.2 | String |
flattening (Read and Write) | The flattening ratio of this spheroid.2 | Double |
longitude (Read and Write) | The longitude value of this prime meridian.2 | Double |
primeMeridianCode (Read and Write) | The prime meridian code.2 | Integer |
primeMeridianName (Read and Write) | The prime meridian name.2 | String |
radiansPerUnit (Read Only) | The radians per angular unit.2 | Double |
semiMajorAxis (Read and Write) | The semi-major axis length of this spheroid.2 | Double |
semiMinorAxis (Read and Write) | The semi-minor axis length of this spheroid.2 | Double |
spheroidCode (Read and Write) | The spheroid code.2 | Integer |
spheroidName (Read and Write) | The spheroid name.2 | String |
Method Overview
Method | Explanation |
create () | Creates the SpatialReference object using properties. |
createFromFile (prj_file) | Creates the SpatialReference object from a projection file. |
exportToString () | Exports the object to its string representation. |
loadFromString (string) | Restore or update the spatial reference object using a WKT string. The exportToString method can be used to export a WKT string representation of the spatial reference.
|
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. |
setMFalseOriginAndUnits (false_m, m_units) | Sets the M false origin and units. |
setZDomain (z_min, z_max) | Sets the Z domain. |
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 SpatialReference object. | String |
exportToString ()
Data Type | Explanation |
String | The WKT string representation of the object. |
loadFromString (string)
Parameter | Explanation | Data Type |
string | The WKT 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 |
setMFalseOriginAndUnits (false_m, m_units)
Parameter | Explanation | Data Type |
false_m | The false m-value. | Double |
m_units | The m units. | Double |
setZDomain (z_min, z_max)
Parameter | Explanation | Data Type |
z_min | The minimum z-value. | Double |
z_max | The maximum z-value. | 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
# Set the workspace environment
arcpy.env.workspace = "c:/base/base.gdb"
# Get a list of the feature classes in the input folder
feature_classes = arcpy.ListFeatureClasses()
# Loop through the list
for fc in feature_classes:
# Create the spatial reference object
spatial_ref = arcpy.Describe(fc).spatialReference
# If the spatial reference is unknown
if spatial_ref.name == "Unknown":
print("{} has an unknown spatial reference".format(fc))
# Otherwise, print out the feature class name and spatial reference
else:
print("{} : {}".format(fc, spatial_ref.name))