Create Spatial Reference (Data Management)
Summary
Creates a spatial reference object for use in ModelBuilder and scripting.
Usage
-
You can create a spatial reference object with set coordinate system, spatial domains, and precision. The spatial domains and precision of the output spatial reference can be further modified using XY Domain, Z Domain, M Domain, Template XYDomains, and Grow XYDomain By Percentage parameters.
-
Template XYDomains does not have to be in the same coordinate system as that specified in Spatial Reference or Spatial Reference Template. If they are different, the extents will be projected to match.
-
If the Spatial Reference and Spatial Reference Template parameters are both set, spatial reference parameter will take priority.
-
All the parameters of the tool are optional. If no parameters are specified, the spatial reference will be defined as 'Unknown' and the XYDomain will assume standard defaults.
-
In ModelBuilder, the output of this tool can be used as input to tools with a spatial reference parameter (e.g., Create_Feature_Class, Create_Feature_Dataset, Make_XY_Event_Layer).
Syntax
Parameter | Explanation | Data 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
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"