SpatialReference
摘要
Each part of the spatial reference has a number of properties, especially the coordinate system, which defines what map projection options are used to define horizontal coordinates.
讨论
A SpatialReference can be easily created from existing datasets and PRJ files:
- Use a PRJ file as an argument to the SpatialReference class.
import arcpy, os prjFile = os.path.join(arcpy.GetInstallInfo()["InstallDir"], "Coordinate Systems/Geographic Coordinate Systems/North America/NAD 1983.prj") spatialRef = arcpy.SpatialReference(prjFile) - Describe a dataset and access its spatialReference property.
dataset = "C:/Data/Landbase.gdb/Wetlands" spatialRef = arcpy.Describe(dataset).spatialReference
注:Which spatial reference properties are available depends on the coordinate system used. In the properties list below, those properties only available with a Projected Coordinate system are denoted with a 1; properties available only with a Geographic Coordinate system are denoted with a 2.
语法
| 参数 | 说明 | 数据类型 |
prjFile |
The projection file used to populate the spatial reference object. | String |
属性
| 属性 | 说明 | 数据类型 |
| 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 (可读写) |
The projected coordinate system code.1 | Integer |
| PCSName (可读写) |
The projected coordinate system name.1 | String |
| azimuth (可读写) |
The azimuth of a projected coordinate system.1 | Double |
| centralMeridian (可读写) |
The central meridian of a projected coordinate system.1 | Double |
| centralMeridianInDegrees (可读写) |
The central meridian (Lambda0) of a projected coordinate system in degrees.1 | Double |
| centralParallel (可读写) |
The central parallel of a projected coordinate system.1 | Double |
| classification (只读) |
The classification of a map projection.1 | String |
| falseEasting (可读写) |
The false easting of a projected coordinate system.1 | Double |
| falseNorthing (可读写) |
The false northing of a projected coordinate system.1 | Double |
| latitudeOf1st (可读写) |
The latitude of the first point of a projected coordinate system.1 | Double |
| latitudeOf2nd (可读写) |
The latitude of the second point of a projected coordinate system.1 | Double |
| linearUnitCode (可读写) |
The linear unit code.1 | Integer |
| linearUnitName (可读写) |
The linear unit name.1 | String |
| longitude (可读写) | The longitude value of this prime meridian.1 | Double |
| longitudeOf1st (可读写) |
The longitude of the first point of a projected coordinate system.1 | Double |
| longitudeOf2nd (可读写) |
The longitude of the second point of a projected coordinate system.1 | Double |
| longitudeOfOrigin (可读写) |
The longitude of origin of a projected coordinate system.1 | Double |
| projectionCode (可读写) |
The projection code.1 | Integer |
| projectionName (可读写) |
The projection name.1 | String |
| scaleFactor (可读写) |
The scale factor of a projected coordinate system.1 | Double |
| standardParallel1 (可读写) |
The first parallel of a projected coordinate system.1 | Double |
| standardParallel2 (可读写) |
The second parallel of a projected coordinate system.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 () |
Creates the spatial reference object using properties. |
| createFromFile (prj_file) |
Creates the spatial reference object from a projection file. |
| exportToString () |
Exports the object to its string representation. |
| loadFromString (string) |
Restore the object using its string representation. The exportToString method can be used to create a string representation. |
| setDomain (x_min, x_max, y_min, y_max) |
Sets the XY domain. |
| setFalseOriginAndUnits (false_x, false_y, xy_units) |
Sets the XY false origin and units. |
| setMDomain (m_min, m_max) |
Sets the M domain. |
| setZDomain (z_min, z_max) |
Sets the Z domain. |
| setMFalseOriginAndUnits (false_m, m_units) |
Sets the M false origin and units. |
| setZFalseOriginAndUnits (false_z, z_units) |
Sets the Z false origin and units. |
方法
| 参数 | 说明 | 数据类型 |
prj_file |
The projection file used to populate the spatial reference object. | String |
| 数据类型 | 说明 |
| String |
The string representation of the object. |
| 参数 | 说明 | 数据类型 |
string |
The string representation of the object. | String |
| 参数 | 说明 | 数据类型 |
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 |
| 参数 | 说明 | 数据类型 |
false_x |
The false x value. | Double |
false_y |
The false y value. | Double |
xy_units |
The xy units. | String |
| 参数 | 说明 | 数据类型 |
m_min |
The minimum m-value. | Double |
m_max |
The maximum m-value. | Double |
| 参数 | 说明 | 数据类型 |
z_min |
The minimum z-value. | Double |
z_max |
The maximum z-value. | Double |
| 参数 | 说明 | 数据类型 |
false_m |
The false m-value. | Double |
m_units |
The m units. | Double |
| 参数 | 说明 | 数据类型 |
false_z |
The false z-value. | Double |
z_units |
The false z units. | Double |
代码示例
For each feature class in a workspace, print the name of its spatial reference.
import arcpy
from arcpy import env
# Set the workspace environment
#
env.workspace = "C:/base/base.gdb"
# Get a list of the feature classes in the input folder
#
fcs = arcpy.ListFeatureClasses()
# Loop through the list
#
for fc in fcs:
# Create the spatial reference object
#
sr = arcpy.Describe(fc).spatialReference
# If the spatial reference is unknown
#
if sr.name == "Unknown":
print fc + " has an unknown spatial reference\n"
# Otherwise, print out the feature class name and
# spatial reference
#
else:
print fc + ": " + sr.name + "\n"
Create a SpatialReference using a .prj file.
import arcpy
prjFile = "c:/Program Files/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems" + \
"/Continental/North America/USA Contiguous Equidistant Conic.prj"
# Create a spatial reference object using a projection file
#
sr = arcpy.SpatialReference(prjFile)
Create a SpatialReference from a factory code.
import arcpy # Create a spatial reference object using a factory code # sr = arcpy.SpatialReference() sr.factoryCode = 3857 sr.create()