摘要
空间参考的每一部分都具有多个属性,特别是坐标系,它定义了哪些地图投影选项用于定义水平坐标。
说明
也可使用 Describe spatialReference 属性从现有数据集访问 SpatialReference 对象。
dataset = "c:/data/landbase.gdb/Wetlands"
spatial_ref = arcpy.Describe(dataset).spatialReference
语法
SpatialReference ({item})| 参数 | 说明 | 数据类型 |
item | 可以通过三种方式创建空间参考:
有关坐标系名称和工厂代码的详细信息,请参阅 geographic_coordinate_systems.pdf 和 projected_coordinate_systems.pdf ArcGIS 文档文件夹中的文件。 有关详细信息,请参阅使用空间参考类。 | String |
属性
| 属性 | 说明 | 数据类型 |
| GCS (只读) | If a projected coordinate system, returns a SpatialReference object for the geographic coordinate system it is based on. If a geographic coordinate system, returns the same SpatialReference. | SpatialReference |
| MDomain (只读) | The extent of the measure domain. | String |
| MFalseOriginAndUnits (只读) | The measure false origin and units. | String |
| MResolution (可读写) | The measure resolution. | Double |
| MTolerance (可读写) | The measure tolerance. | Double |
| XYResolution (可读写) | The xy resolution. | Double |
| XYTolerance (可读写) | The xy tolerance. | Double |
| ZDomain (只读) | The extent of the Z domain. | String |
| ZFalseOriginAndUnits (只读) | The Z false origin and units. | String |
| ZResolution (可读写) | The Z resolution property. | Double |
| ZTolerance (可读写) | The Z tolerance property. | Double |
| abbreviation (可读写) | The abbreviated name of the spatial reference. | String |
| alias (可读写) | The alias of the spatial reference. | String |
| domain (只读) | The extent of the xy domain. | String |
| factoryCode (可读写) | The factory code of the spatial reference. | Integer |
| falseOriginAndUnits (只读) | The false origin and units. | String |
| hasMPrecision (只读) | Indicates whether or not m-value precision information has been defined. | Boolean |
| hasXYPrecision (只读) | Indicates whether or not xy precision information has been defined. | Boolean |
| hasZPrecision (只读) | Indicates whether or not z-value precision information has been defined. | Boolean |
| isHighPrecision (可读写) | Indicates whether or not the spatial reference has high precision set. | Boolean |
| name (可读写) | The name of the spatial reference. | String |
| remarks (可读写) | The comment string of the spatial reference. | String |
| type (可读写) | The type of the spatial reference. | String |
| usage (只读) | The usage notes. | String |
| PCSCode (可读写) | 投影坐标系代码。1 | Integer |
| PCSName (可读写) | 投影坐标系名称。1 | String |
| azimuth (可读写) | 投影坐标系的方位角。1 | Double |
| centralMeridian (可读写) | 投影坐标系的中央经线。1 | Double |
| centralMeridianInDegrees (可读写) | 投影坐标系的中央经线 (Lambda0)(以度为单位)。1 | Double |
| centralParallel (可读写) | 投影坐标系的中央纬线。1 | Double |
| classification (只读) | 地图投影的分类。1 | String |
| falseEasting (可读写) | 投影坐标系的东偏移量。1 | Double |
| falseNorthing (可读写) | 投影坐标系的北偏移量。1 | Double |
| latitudeOf1st (可读写) | 投影坐标系第一个点的纬度。1 | Double |
| latitudeOf2nd (可读写) | 投影坐标系第二个点的纬度。1 | Double |
| latitudeOfOrigin (可读写) | 投影坐标系原点的纬度。1 | Double |
| linearUnitCode (可读写) | 线性单位代码。1 | Integer |
| linearUnitName (可读写) | 线性单位名称。1 | String |
| longitude (可读写) | 此本初子午线的经度值。1 | Double |
| longitudeOf1st (可读写) | 投影坐标系第一个点的经度。1 | Double |
| longitudeOf2nd (可读写) | 投影坐标系第二个点的经度。1 | Double |
| longitudeOfOrigin (可读写) | 投影坐标系原点的经度。1 | Double |
| metersPerUnit (只读) | 米/线性单位。1 | Double |
| projectionCode (可读写) | 投影代码。1 | Integer |
| projectionName (可读写) | 投影名称。1 | String |
| scaleFactor (可读写) | 投影坐标系的比例因子。1 | Double |
| standardParallel1 (可读写) | 投影坐标系的第一条纬线。1 | Double |
| standardParallel2 (可读写) | 投影坐标系的第二条纬线。1 | Double |
| GCSCode (可读写) | The geographic coordinate system code.2 | Integer |
| GCSName (可读写) | The geographic coordinate system name.2 | String |
| angularUnitCode (可读写) | The angular unit code.2 | Integer |
| angularUnitName (可读写) | The angular unit name.2 | String |
| datumCode (可读写) | The datum code.2 | Integer |
| datumName (可读写) | The datum name.2 | String |
| flattening (可读写) | The flattening ratio of this spheroid.2 | Double |
| longitude (可读写) | The longitude value of this prime meridian.2 | Double |
| primeMeridianCode (可读写) | The prime meridian code.2 | Integer |
| primeMeridianName (可读写) | The prime meridian name.2 | String |
| radiansPerUnit (只读) | The radians per angular unit.2 | Double |
| semiMajorAxis (可读写) | The semi-major axis length of this spheroid.2 | Double |
| semiMinorAxis (可读写) | The semi-minor axis length of this spheroid.2 | Double |
| spheroidCode (可读写) | The spheroid code.2 | Integer |
| spheroidName (可读写) | The spheroid name.2 | String |
方法概述
| 方法 | 说明 |
| create () | 使用属性创建空间参考对象。 |
| createFromFile (prj_file) | 从投影文件创建一个空间参考对象。 |
| exportToString () | 将对象导出至其字符串表示。 |
| loadFromString (string) | 使用对象的字符串表示来恢复对象。可以使用 exportToString 方法创建字符串表示。 |
| setDomain (x_min, x_max, y_min, y_max) | 设置 XY 属性域。 |
| setFalseOriginAndUnits (false_x, false_y, xy_units) | 设置 XY 的假定原点和单位。 |
| setMDomain (m_min, m_max) | 设置 M 属性域。 |
| setMFalseOriginAndUnits (false_m, m_units) | 设置 M 的假定原点和单位。 |
| setZDomain (z_min, z_max) | 设置 Z 属性域。 |
| setZFalseOriginAndUnits (false_z, z_units) | 设置 Z 的假定原点和单位。 |
方法
create ()
createFromFile (prj_file)
| 参数 | 说明 | 数据类型 |
prj_file | 该投影文件用于填充此空间参考对象。 | String |
exportToString ()
返回值
| 数据类型 | 说明 |
| String | 对象的字符串表示。 |
loadFromString (string)
| 参数 | 说明 | 数据类型 |
string | 对象的字符串表示。 | String |
setDomain (x_min, x_max, y_min, y_max)
| 参数 | 说明 | 数据类型 |
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)
| 参数 | 说明 | 数据类型 |
false_x | 假定的 x 值。 | Double |
false_y | 假定的 y 值。 | Double |
xy_units | xy 的单位。 | String |
setMDomain (m_min, m_max)
| 参数 | 说明 | 数据类型 |
m_min | 最小 m 值。 | Double |
m_max | 最大 m 值。 | Double |
setMFalseOriginAndUnits (false_m, m_units)
| 参数 | 说明 | 数据类型 |
false_m | The false m-value. | Double |
m_units | The m units. | Double |
setZDomain (z_min, z_max)
| 参数 | 说明 | 数据类型 |
z_min | 最小 z 值。 | Double |
z_max | 最大 z 值。 | Double |
setZFalseOriginAndUnits (false_z, z_units)
| 参数 | 说明 | 数据类型 |
false_z | The false z-value. | Double |
z_units | The false z units. | Double |
代码示例
SpatialReference 示例
对工作空间中的每个要素类,输出其空间参考的名称。
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("{0} has an unknown spatial reference".format(fc))
# Otherwise, print out the feature class name and
# spatial reference
else:
print("{0} : {1}".format(fc, spatial_ref.name))