ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

Using the spatial reference class

  • Creating a spatial reference

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 describing the dataset and accessing its 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

It is not often practical to keep all details of a spatial reference inside a Python script. By using a projection file, factory code, or spatial reference name 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 factory code (also known as an authority code) supplied as an input argument.

Tip:

For more information on coordinate system names and factory codes, see geographic_coordinate_systems.pdf and projected_coordinate_systems.pdf files in the ArcGIS Documentation folder.

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)
factoryCode    = arcpy.GetParameterAsText(2)

# Use a code as input to the SpatialReference class
#
sr = arcpy.SpatialReference(factoryCode)

# Use the SpatialReference object to create a new feature class with a 
#  specific coordinate system
#
arcpy.CreateFeatureclass_management(inputWorkspace, outputName, 
                                    "POLYLINE", spatial_reference=sr)
Note:

For a full list of properties and methods, see SpatialReference class.

Note:

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.

Related topics

  • SpatialReference

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2019 Esri. | Privacy | Legal