SpatialReference
汇总
空间参考的每一部分都具有多个属性,特别是坐标系,它定义了哪些地图投影选项用于定义水平坐标。
讨论
也可使用 Describe spatialReference 属性从现有数据集访问 SpatialReference 对象。
dataset = "c:/data/landbase.gdb/Wetlands"
spatial_ref = arcpy.Describe(dataset).spatialReference
XY、Z 和 M 范围与空间参考域有所不同。空间参考中的 XY、Z 和 M 域用于定义可存储在要素类中的坐标值的有效范围。要素类范围反映了存在于要素类中的坐标值的实际范围。这些范围不能大于域。
SpatialReference 对象支持用于比较空间参考的等于 (==) 和不等于 (!=) 运算符。
注:
空间参考属性的可用性取决于所使用的坐标系。 在下面的属性列表中,只可用于投影坐标系的属性以 1 表示;只可用于地理坐标系的属性以 2 表示。
由于投影坐标系基于地理坐标系,因此可以使用 GCS 属性从地理坐标系访问投影坐标系属性。
语法
SpatialReference({item}, {vcs}, {text})
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
item (可选) |
The horizontal coordinate system used to create the Create a
Create a
Create a
Create a
For more information about coordinate system names and factory codes, see the geographic_coordinate_systems.pdf and projected_coordinate_systems.pdf files. For more information, see Using the spatial reference class. |
Variant |
|
vcs (可选) |
The vertical coordinate system (VCS). The VCS defines information about the z-coordinates and can be set using a name or factory code. See the following examples: Define the vertical coordinate system using a name.
Define the vertical coordinate system using a factory code.
|
Variant |
|
text (可选) |
A well-known text (WKT or WKT2 format) string that can be used to define a horizontal and vertical coordinate system. 注:When creating a Create a
Create a
Create a
|
String |
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
GCS (只读) |
投影坐标系将针对其基于的地理坐标系返回 |
SpatialReference |
|
MDomain (只读) |
测量值域的范围。 |
String |
|
MFalseOriginAndUnits (只读) |
测量假定原点和单位。 |
String |
|
MResolution (读取和写入) |
测量分辨率。 |
Double |
|
MTolerance (读取和写入) |
测量容差。 |
Double |
|
VCS (只读) |
如果坐标系具有垂直坐标系,则属性将针对其基于的垂直坐标系返回 |
Object |
|
XYResolution (读取和写入) |
x,y 分辨率。 |
Double |
|
XYTolerance (读取和写入) |
x,y 容差。 |
Double |
|
ZDomain (只读) |
Z 值域的范围。 |
String |
|
ZFalseOriginAndUnits (只读) |
Z 假定原点和单位。 |
String |
|
ZResolution (读取和写入) |
z 分辨率。 |
Double |
|
ZTolerance (读取和写入) |
z 容差。 |
Double |
|
abbreviation (读取和写入) |
空间参考的缩写名称。 |
String |
|
alias (读取和写入) |
空间参考的别名。 |
String |
|
domain (只读) |
x,y 值域的范围。 |
String |
|
factoryCode (读取和写入) |
空间参考的工厂代码或熟知 ID (WKID)。 |
Integer |
|
falseOriginAndUnits (只读) |
假定原点和单位。 |
String |
|
hasMPrecision (只读) |
指定是否已定义 m 值精度信息。 |
Boolean |
|
hasXYPrecision (只读) |
指定是否已定义 x,y 坐标精度信息。 |
Boolean |
|
hasZPrecision (只读) |
指定是否已定义 z 值精度信息。 |
Boolean |
|
isHighPrecision (读取和写入) |
指定空间参考是否已设置高精度。 |
Boolean |
|
name (读取和写入) |
空间参考的名称。 |
String |
|
remarks (读取和写入) |
空间参考的注释字符串。 |
String |
|
type (读取和写入) |
指定空间参考的类型。
|
String |
|
usage (只读) |
用法说明。 |
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 (读取和写入) |
地理坐标系代码。2 |
Integer |
|
GCSName (读取和写入) |
地理坐标系名称。2 |
String |
|
angularUnitCode (读取和写入) |
角度单位代码。2 |
Integer |
|
angularUnitName (读取和写入) |
角度单位名称。2 |
String |
|
datumCode (读取和写入) |
基准代码。2 |
Integer |
|
datumName (读取和写入) |
基准名称。2 |
String |
|
flattening (读取和写入) |
此椭球体的扁率。2 |
Double |
|
longitude (读取和写入) |
此本初子午线的经度值。2 |
Double |
|
primeMeridianCode (读取和写入) |
本初子午线代码。2 |
Integer |
|
primeMeridianName (读取和写入) |
本初子午线名称。2 |
String |
|
radiansPerUnit (只读) |
每角度单位的弧度。2 |
Double |
|
semiMajorAxis (读取和写入) |
此椭球体的半长轴长度。2 |
Double |
|
semiMinorAxis (读取和写入) |
此椭球体的半短轴长度。2 |
Double |
|
spheroidCode (读取和写入) |
椭球体代码。2 |
Integer |
|
spheroidName (读取和写入) |
椭球体名称。2 |
String |
方法
create()
使用属性创建 SpatialReference 对象。
createFromFile(prj_file)
从投影文件创建 SpatialReference 对象。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
prj_file |
The projection file used to populate the |
String |
exportToString({encoding})
将对象导出至其字符串表示。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
encoding (可选) |
Specifies the encoding of the exported string.
(默认值为 WKT) |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
String |
对象的 WKT 或 WKT 2 表示。 |
loadFromString(string)
通过 WKT 字符串定义 SpatialReference 对象。
exportToString 方法可用于导出空间参考的 WKT 字符串表示。
将 WKT 字符串与水平坐标系配合使用。
# The following string is the WKT for the # Geographic Coordinate system "WGS 1984" (factory code=4326) wkt = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],\ PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]];\ -400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119522E-09;\ 0.001;0.001;IsHighPrecision' sr = arcpy.SpatialReference() sr.loadFromString(wkt)将 WKT 字符串与水平坐标系和垂直坐标系配合使用。 请注意,将在 WKT 的
VERTCS部分中定义垂直坐标系。# The following string is the WKT for the # Geographic Coordinate system "WGS 1984" (factory code=4326), # with a vertical coordinate system "WGS 1984" (factory code=115700) wkt = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],\ PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],\ VERTCS["WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],\ PARAMETER["Vertical_Shift",0.0],PARAMETER["Direction",1.0],UNIT["Meter",1.0]];\ -400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119522E-09;\ 0.001;0.001;IsHighPrecision' sr = arcpy.SpatialReference() sr.loadFromString(wkt)
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
string |
The WKT string representation of the object. |
String |
setDomain(x_min, x_max, y_min, y_max)
设置 x,y 值域。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
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)
设置假定 x,y 原点和单位。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
false_x |
The false x-value. |
Double |
|
false_y |
The false y-value. |
Double |
|
xy_units |
The x,y-units. |
String |
setMDomain(m_min, m_max)
设置 m 值域。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
m_min |
The minimum m-value. |
Double |
|
m_max |
The maximum m-value. |
Double |
setMFalseOriginAndUnits(false_m, m_units)
设置假定 m 原点和单位。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
false_m |
The false m-value. |
Double |
|
m_units |
The m-units. |
Double |
setZDomain(z_min, z_max)
设置 z 值域。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
z_min |
The minimum z-value. |
Double |
|
z_max |
The maximum z-value. |
Double |
setZFalseOriginAndUnits(false_z, z_units)
设置假定 z 原点和单位。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
false_z |
The false z-value. |
Double |
|
z_units |
The false z-units. |
Double |
代码示例
对工作空间中的每个要素类,输出其空间参考的名称。
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(r"{fc} has an unknown spatial reference")
# Otherwise, print out the feature class name and spatial reference
else:
print(f"{fc} : {spatial_ref.name}")