SpatialReference
Zusammenfassung
Each part of the spatial reference has a number of properties (especially the coordinate system) that defines what map projection options are used to define horizontal coordinates.
Diskussion
A SpatialReference object can also be accessed from existing datasets using the Describe spatialReference property.
dataset = "c:/data/landbase.gdb/Wetlands"
spatial_ref = arcpy.Describe(dataset).spatialReference
XY, Z, and M extents are not the same as spatial reference domains. The XY, Z, and M domains in a spatial reference define the valid range of coordinate values that can be stored in a feature class. The feature class extents reflect the actual range of coordinate values that exist in the feature class. These extents cannot be larger than the domains.
The SpatialReference object supports equal (==) and not equal (!=) operators for comparing spatial references.
Hinweis:
The spatial reference properties available depend on the coordinate system used. In the properties list below, those properties that are only available with a projected coordinate system are denoted with a 1; properties only available with a geographic coordinate system are denoted with a 2.
Because a projected coordinate system is based on a geographic coordinate system, projected coordinate system properties can be accessed from a geographic coordinate system using the GCS property.
Syntax
SpatialReference({item}, {vcs}, {text})
| Name | Erläuterung | Datentyp |
|---|---|---|
|
item (Optional) |
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 (Optional) |
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 (Optional) |
A well-known text (WKT or WKT2 format) string that can be used to define a horizontal and vertical coordinate system. Hinweis:When creating a Create a
Create a
Create a
|
String |
Eigenschaften
| Name | Erläuterung | Datentyp |
|---|---|---|
|
GCS (Schreibgeschützt) |
A projected coordinate system returns a |
SpatialReference |
|
MDomain (Schreibgeschützt) |
The extent of the measure domain. |
String |
|
MFalseOriginAndUnits (Schreibgeschützt) |
The measure false origin and units. |
String |
|
MResolution (Lesen und schreiben) |
The measure resolution. |
Double |
|
MTolerance (Lesen und schreiben) |
The measure tolerance. |
Double |
|
VCS (Schreibgeschützt) |
If the coordinate system has a vertical coordinate system, the property returns a |
Object |
|
XYResolution (Lesen und schreiben) |
The x,y-resolution. |
Double |
|
XYTolerance (Lesen und schreiben) |
The x,y-tolerance. |
Double |
|
ZDomain (Schreibgeschützt) |
The extent of the z-domain. |
String |
|
ZFalseOriginAndUnits (Schreibgeschützt) |
The z false origin and units. |
String |
|
ZResolution (Lesen und schreiben) |
The z-resolution. |
Double |
|
ZTolerance (Lesen und schreiben) |
The z-tolerance. |
Double |
|
abbreviation (Lesen und schreiben) |
The abbreviated name of the spatial reference. |
String |
|
alias (Lesen und schreiben) |
The alias of the spatial reference. |
String |
|
domain (Schreibgeschützt) |
The extent of the x,y-domain. |
String |
|
factoryCode (Lesen und schreiben) |
The factory code or well-known ID (WKID) of the spatial reference. |
Integer |
|
falseOriginAndUnits (Schreibgeschützt) |
The false origin and units. |
String |
|
hasMPrecision (Schreibgeschützt) |
Specifies whether m-value precision information has been defined. |
Boolean |
|
hasXYPrecision (Schreibgeschützt) |
Specifies whether x,y-coordinate precision information has been defined. |
Boolean |
|
hasZPrecision (Schreibgeschützt) |
Specifies whether z-value precision information has been defined. |
Boolean |
|
isHighPrecision (Lesen und schreiben) |
Specifies whether the spatial reference has high precision set. |
Boolean |
|
name (Lesen und schreiben) |
The name of the spatial reference. |
String |
|
remarks (Lesen und schreiben) |
The comment string of the spatial reference. |
String |
|
type (Lesen und schreiben) |
Specifies the type of the spatial reference.
|
String |
|
usage (Schreibgeschützt) |
The usage notes. |
String |
|
PCSCode (Lesen und schreiben) |
The projected coordinate system code.1 |
Integer |
|
PCSName (Lesen und schreiben) |
The projected coordinate system name.1 |
String |
|
azimuth (Lesen und schreiben) |
The azimuth of a projected coordinate system.1 |
Double |
|
centralMeridian (Lesen und schreiben) |
The central meridian of a projected coordinate system.1 |
Double |
|
centralMeridianInDegrees (Lesen und schreiben) |
The central meridian (Lambda0) of a projected coordinate system in degrees.1 |
Double |
|
centralParallel (Lesen und schreiben) |
The central parallel of a projected coordinate system.1 |
Double |
|
classification (Schreibgeschützt) |
The classification of a map projection.1 |
String |
|
falseEasting (Lesen und schreiben) |
The false easting of a projected coordinate system.1 |
Double |
|
falseNorthing (Lesen und schreiben) |
The false northing of a projected coordinate system.1 |
Double |
|
latitudeOf1st (Lesen und schreiben) |
The latitude of the first point of a projected coordinate system.1 |
Double |
|
latitudeOf2nd (Lesen und schreiben) |
The latitude of the second point of a projected coordinate system.1 |
Double |
|
latitudeOfOrigin (Lesen und schreiben) |
The latitude of origin of a projected coordinate system.1 |
Double |
|
linearUnitCode (Lesen und schreiben) |
The linear unit code.1 |
Integer |
|
linearUnitName (Lesen und schreiben) |
The linear unit name.1 |
String |
|
longitude (Lesen und schreiben) |
The longitude value of this prime meridian.1 |
Double |
|
longitudeOf1st (Lesen und schreiben) |
The longitude of the first point of a projected coordinate system.1 |
Double |
|
longitudeOf2nd (Lesen und schreiben) |
The longitude of the second point of a projected coordinate system.1 |
Double |
|
longitudeOfOrigin (Lesen und schreiben) |
The longitude of origin of a projected coordinate system.1 |
Double |
|
metersPerUnit (Schreibgeschützt) |
The meters per linear unit.1 |
Double |
|
projectionCode (Lesen und schreiben) |
The projection code.1 |
Integer |
|
projectionName (Lesen und schreiben) |
The projection name.1 |
String |
|
scaleFactor (Lesen und schreiben) |
The scale factor of a projected coordinate system.1 |
Double |
|
standardParallel1 (Lesen und schreiben) |
The first parallel of a projected coordinate system.1 |
Double |
|
standardParallel2 (Lesen und schreiben) |
The second parallel of a projected coordinate system.1 |
Double |
|
GCSCode (Lesen und schreiben) |
The geographic coordinate system code.2 |
Integer |
|
GCSName (Lesen und schreiben) |
The geographic coordinate system name.2 |
String |
|
angularUnitCode (Lesen und schreiben) |
The angular unit code.2 |
Integer |
|
angularUnitName (Lesen und schreiben) |
The angular unit name.2 |
String |
|
datumCode (Lesen und schreiben) |
The datum code.2 |
Integer |
|
datumName (Lesen und schreiben) |
The datum name.2 |
String |
|
flattening (Lesen und schreiben) |
The flattening ratio of this spheroid.2 |
Double |
|
longitude (Lesen und schreiben) |
The longitude value of this prime meridian.2 |
Double |
|
primeMeridianCode (Lesen und schreiben) |
The prime meridian code.2 |
Integer |
|
primeMeridianName (Lesen und schreiben) |
The prime meridian name.2 |
String |
|
radiansPerUnit (Schreibgeschützt) |
The radians per angular unit.2 |
Double |
|
semiMajorAxis (Lesen und schreiben) |
The semi-major axis length of this spheroid.2 |
Double |
|
semiMinorAxis (Lesen und schreiben) |
The semi-minor axis length of this spheroid.2 |
Double |
|
spheroidCode (Lesen und schreiben) |
The spheroid code.2 |
Integer |
|
spheroidName (Lesen und schreiben) |
The spheroid name.2 |
String |
Methoden
create()
Creates the SpatialReference object using properties.
createFromFile(prj_file)
Creates the SpatialReference object from a projection file.
| Name | Erläuterung | Datentyp |
|---|---|---|
|
prj_file |
The projection file used to populate the |
String |
exportToString({encoding})
Exports the object to its string representation.
| Name | Erläuterung | Datentyp |
|---|---|---|
|
encoding (Optional) |
Specifies the encoding of the exported string.
The default value is WKT. |
String |
Rückgabewert
| Datentyp | Erläuterung |
|---|---|
|
String |
The WKT or WKT 2 representation of the object. |
loadFromString(string)
Defines a SpatialReference object from a WKT string.
The exportToString method can be used to export a WKT string representation of the spatial reference.
Using a WKT string with a horizontal coordinate system.
# 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)Using a WKT string with a horizontal and vertical coordinate system. Note that the vertical coordinate system is defined in the
VERTCSsection of the WKT.# 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)
| Name | Erläuterung | Datentyp |
|---|---|---|
|
string |
The WKT string representation of the object. |
String |
setDomain(x_min, x_max, y_min, y_max)
Sets the x,y-domain.
| Name | Erläuterung | Datentyp |
|---|---|---|
|
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)
Sets the false x,y origin and units.
| Name | Erläuterung | Datentyp |
|---|---|---|
|
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)
Sets the m-domain.
| Name | Erläuterung | Datentyp |
|---|---|---|
|
m_min |
The minimum m-value. |
Double |
|
m_max |
The maximum m-value. |
Double |
setMFalseOriginAndUnits(false_m, m_units)
Sets the false m origin and units.
| Name | Erläuterung | Datentyp |
|---|---|---|
|
false_m |
The false m-value. |
Double |
|
m_units |
The m-units. |
Double |
setZDomain(z_min, z_max)
Sets the z-domain.
| Name | Erläuterung | Datentyp |
|---|---|---|
|
z_min |
The minimum z-value. |
Double |
|
z_max |
The maximum z-value. |
Double |
setZFalseOriginAndUnits(false_z, z_units)
Sets the false z origin and units.
| Name | Erläuterung | Datentyp |
|---|---|---|
|
false_z |
The false z-value. |
Double |
|
z_units |
The false z-units. |
Double |
Codebeispiel
For each feature class in a workspace, print the name of its spatial reference.
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}")