地理数据集(如要素类、Coverage 和栅格)具有定义数据集坐标系、x,y 值域、m 值域和 z 值域的空间参考。 空间参考的每一部分都具有多个属性,特别是坐标系,它定义了哪些地图投影选项用于定义水平坐标。 所有这些信息都可以通过描述数据集和访问其空间参考属性(实际上是另一个包含多个属性的对象)来获得。
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.management.Copy(fc, "D:/St_Johns/data.gdb/roads_UTM")
创建空间参考
将空间参考的所有细节都保存在 Python 脚本中通常是不现实的。 通过使用投影文件、工厂代码或空间参考名称作为 SpatialReference 类的参数,您可以快速完成空间参考的属性设置,并将该对象用作地理处理工具的输入。 在以下示例中,空间参考使用作为输入参数提供的工厂代码(也称为权限代码)构造。
提示:
有关坐标系名称和工厂代码的详细信息,请参阅geographic_coordinate_systems.pdf和projected_coordinate_systems.pdfArcGIS 文档文件夹中的文件。
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.management.CreateFeatureclass(inputWorkspace, outputName,
"POLYLINE", spatial_reference=sr)
注:
有关属性和方法的完整列表,请参见 SpatialReference 类。
注:
空间参考有时称为投影引擎字符串。 投影引擎 (PE) 是一个代码库,其中包含所有 ArcGIS 用于定义地图投影和执行投影变换的代码。