Create Spatial Reference (Data Management)

Summary

Creates a spatial reference object for use in ModelBuilder and scripting.

Usage

Syntax

CreateSpatialReference_management ({spatial_reference}, {spatial_reference_template}, {xy_domain}, {z_domain}, {m_domain}, {template}, {expand_ratio})
ParameterExplanationData Type
spatial_reference
(Optional)

Name of the the spatial reference object to be created.

Spatial Reference
spatial_reference_template
(Optional)

The feature class or layer to be used as a template to set the value for the spatial reference.

Feature Layer; Raster Catalog Layer; Raster Dataset
xy_domain
(Optional)

Allowable coordinate range for x,y coordinates.

Envelope
z_domain
(Optional)

Allowable coordinate range for z values.

String
m_domain
(Optional)

Allowable coordinate range for m values.

String
template
[template,...]
(Optional)

Feature classes or layers that can be used to define the XY Domain.

Feature Layer
expand_ratio
(Optional)

Percentage by which the XY Domain will be expanded.

Double

Code Sample

Create Spatial Reference example (stand-alone script)

The following stand-alone script uses the CreateSpatialReference function as part of a workflow that loops through a folder and finds all shapefiles that end in "ST", create spatial references, and append them into a geodatabase feature class.

# Name: createspatialreference2.py
# Purpose: Loops through a folder and finds all feature classes within  the geodatabases under it.
# Filters only Polygon feature classes and Appends them to a new feature class sending the
# output to a personal geodatabase.

# Import system modules
import arcpy
import os
from arcpy import env
 
try:
    #Set the workspace where the geodatabases are stored
    env.workspace = r"C:\data\Redlands"
    workspaces = arcpy.ListWorkspaces() 
    
    #This list will contain all polygon feature classes
    fcList = []    
    
    for wks in workspaces:
        
        #Set each geodatabase as workspace to loop through all feature classes within
        env.workspace = wks
        
        fcs = arcpy.ListFeatureClasses('*', 'POLYGON')         
        for fc in fcs:
            fcList.append(os.path.join(wks, fc))
 
    sr = arcpy.CreateSpatialReference_management("", fcList[0], "", "", "", fcList)
    outFC = arcpy.CreateFeatureclass_management ('c:/data/redlands.mdb', 'gdt2', 'POLYGON', fcList[0], "", "", sr)
    arcpy.Append_management(fcList, outFC, 'no_test')
 
except arcpy.ExecuteError:
    print arcpy.GetMessages(2)
    
except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message
 
print "FINISHED"

Environments

This tool does not use any geoprocessing environments

Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

10/27/2014