SpatialReference

Résumé

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.

Discussion

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

Les étendues XY, Z et M ne correspondent pas aux domaines de référence spatiale. Les domaines XY, Z et M d'une référence spatiale définissent la plage valide de valeurs de coordonnées pouvant être stockées dans une classe d'entités. Les étendues de la classe d’entités reflètent la plage réelle des valeurs de coordonnées présentes dans la classe d’entités. Ces étendues ne peuvent pas être plus importantes que les domaines.

Remarque :

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.

Syntaxe

 SpatialReference ({item}, {vcs})
ParamètreExplicationType de données
item

The coordinate system to be used to create the SpatialReference. Can be set using a projection file, name, factory code, or well-known text (WKT) format. See examples below.

  • Using a projection file (.prj)
    sr = arcpy.SpatialReference("c:/coordsystems/NAD 1983.prj")
  • Using the name of the coordinate system
    sr = arcpy.SpatialReference("Hawaii Albers Equal Area Conic")
  • Using a coordinate system's factory code (or authority code)
    # 32145 is the code for: 
    #  NAD 1983 StatePlane Vermont FIPS 4400 (Meters)
    sr = arcpy.SpatialReference(32145)
  • Using a well-known text string representation
    # String below is representation 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)

For more information on coordinate system names and factory codes, see 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. Can be set using a name, factory code, or well-known text (WKT) format. See examples below.

  • Using names
    sr = arcpy.SpatialReference("Hawaii Albers Equal Area Conic", "MSL (Height)")
  • Using factory codes
    # Spatial Reference factory code of 32145 is : NAD 1983 StatePlane Vermont FIPS 4400 (Meters)
    # Spatial Reference factory code of 5714 is : Mean Sea Level (Height)
    
    sr = arcpy.SpatialReference(32145, 5714)
  • Using a well-known text string representation. Note that the vcs argument is not used, and the VCS is defined in the VERTCS section of the WKT.
    # String below is representation 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)
Variant

Propriétés

PropriétéExplicationType de données
GCS
(Lecture seule)

A projected coordinate system returns a SpatialReference object for the geographic coordinate system it is based on. A geographic coordinate system returns the same SpatialReference.

SpatialReference
MDomain
(Lecture seule)

The extent of the measure domain.

String
MFalseOriginAndUnits
(Lecture seule)

The measure false origin and units.

String
MResolution
(Lecture/écriture)

The measure resolution.

Double
MTolerance
(Lecture/écriture)

The measure tolerance.

Double
VCS
(Lecture seule)

If the coordinate system has a vertical coordinate system, it returns a VCS object for the vertical coordinate system it is based on.

Object
XYResolution
(Lecture/écriture)

The xy resolution.

Double
XYTolerance
(Lecture/écriture)

The xy tolerance.

Double
ZDomain
(Lecture seule)

The extent of the z domain.

String
ZFalseOriginAndUnits
(Lecture seule)

The z false origin and units.

String
ZResolution
(Lecture/écriture)

The z resolution property.

Double
ZTolerance
(Lecture/écriture)

The z-tolerance property.

Double
abbreviation
(Lecture/écriture)

The abbreviated name of the spatial reference.

String
alias
(Lecture/écriture)

The alias of the spatial reference.

String
domain
(Lecture seule)

The extent of the xy domain.

String
factoryCode
(Lecture/écriture)

The factory code or well-known ID (WKID) of the spatial reference.

Integer
falseOriginAndUnits
(Lecture seule)

The false origin and units.

String
hasMPrecision
(Lecture seule)

Indicates whether m-value precision information has been defined.

Boolean
hasXYPrecision
(Lecture seule)

Indicates whether xy precision information has been defined.

Boolean
hasZPrecision
(Lecture seule)

Indicates whether z-value precision information has been defined.

Boolean
isHighPrecision
(Lecture/écriture)

Indicates whether the spatial reference has high precision set.

Boolean
name
(Lecture/écriture)

The name of the spatial reference.

String
remarks
(Lecture/écriture)

The comment string of the spatial reference.

String
type
(Lecture/écriture)

The type of the spatial reference.

  • Geographic—A geographic coordinate system.
  • Projected— A projected coordinate system.
String
usage
(Lecture seule)

The usage notes.

String
PCSCode
(Lecture/écriture)

The projected coordinate system code.1

Integer
PCSName
(Lecture/écriture)

The projected coordinate system name.1

String
azimuth
(Lecture/écriture)

The azimuth of a projected coordinate system.1

Double
centralMeridian
(Lecture/écriture)

The central meridian of a projected coordinate system.1

Double
centralMeridianInDegrees
(Lecture/écriture)

The central meridian (Lambda0) of a projected coordinate system in degrees.1

Double
centralParallel
(Lecture/écriture)

The central parallel of a projected coordinate system.1

Double
classification
(Lecture seule)

The classification of a map projection.1

String
falseEasting
(Lecture/écriture)

The false easting of a projected coordinate system.1

Double
falseNorthing
(Lecture/écriture)

The false northing of a projected coordinate system.1

Double
latitudeOf1st
(Lecture/écriture)

The latitude of the first point of a projected coordinate system.1

Double
latitudeOf2nd
(Lecture/écriture)

The latitude of the second point of a projected coordinate system.1

Double
latitudeOfOrigin
(Lecture/écriture)

The latitude of origin of a projected coordinate system.1

Double
linearUnitCode
(Lecture/écriture)

The linear unit code.1

Integer
linearUnitName
(Lecture/écriture)

The linear unit name.1

String
longitude
(Lecture/écriture)

The longitude value of this prime meridian.1

Double
longitudeOf1st
(Lecture/écriture)

The longitude of the first point of a projected coordinate system.1

Double
longitudeOf2nd
(Lecture/écriture)

The longitude of the second point of a projected coordinate system.1

Double
longitudeOfOrigin
(Lecture/écriture)

The longitude of origin of a projected coordinate system.1

Double
metersPerUnit
(Lecture seule)

The meters per linear unit.1

Double
projectionCode
(Lecture/écriture)

The projection code.1

Integer
projectionName
(Lecture/écriture)

The projection name.1

String
scaleFactor
(Lecture/écriture)

The scale factor of a projected coordinate system.1

Double
standardParallel1
(Lecture/écriture)

The first parallel of a projected coordinate system.1

Double
standardParallel2
(Lecture/écriture)

The second parallel of a projected coordinate system.1

Double
GCSCode
(Lecture/écriture)

Code du système de coordonnées géographiques.2

Integer
GCSName
(Lecture/écriture)

Nom du système de coordonnées géographiques.2

String
angularUnitCode
(Lecture/écriture)

Code d'unité angulaire.2

Integer
angularUnitName
(Lecture/écriture)

Nom d'unité angulaire.2

String
datumCode
(Lecture/écriture)

Code du datum.2

Integer
datumName
(Lecture/écriture)

Nom du datum.2

String
flattening
(Lecture/écriture)

Coefficient d'aplatissement de cette sphéroïde.2

Double
longitude
(Lecture/écriture)

Valeur de longitude de ce méridien principal.2

Double
primeMeridianCode
(Lecture/écriture)

Code de méridien principal.2

Integer
primeMeridianName
(Lecture/écriture)

Nom du méridien principal.2

String
radiansPerUnit
(Lecture seule)

Radians par unité angulaire.2

Double
semiMajorAxis
(Lecture/écriture)

Longueur du demi-grand axe de ce sphéroïde.2

Double
semiMinorAxis
(Lecture/écriture)

Longueur du demi-petit axe de ce sphéroïde.2

Double
spheroidCode
(Lecture/écriture)

Code du sphéroïde.2

Integer
spheroidName
(Lecture/écriture)

Nom du sphéroïde.2

String

Vue d’ensemble des méthodes

MéthodeExplication
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.

setMFalseOriginAndUnits (false_m, m_units)

Sets the M false origin and units.

setZDomain (z_min, z_max)

Sets the Z domain.

setZFalseOriginAndUnits (false_z, z_units)

Sets the Z false origin and units.

Méthodes

create ()
createFromFile (prj_file)
ParamètreExplicationType de données
prj_file

The projection file used to populate the spatial reference object.

String
exportToString ()
Valeur renvoyée
Type de donnéesExplication
String

The string representation of the object.

loadFromString (string)
ParamètreExplicationType de données
string

The string representation of the object.

String
setDomain (x_min, x_max, y_min, y_max)
ParamètreExplicationType de données
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)
ParamètreExplicationType de données
false_x

The false x value.

Double
false_y

The false y value.

Double
xy_units

The xy units.

String
setMDomain (m_min, m_max)
ParamètreExplicationType de données
m_min

The minimum m-value.

Double
m_max

The maximum m-value.

Double
setMFalseOriginAndUnits (false_m, m_units)
ParamètreExplicationType de données
false_m

The false m-value.

Double
m_units

The m units.

Double
setZDomain (z_min, z_max)
ParamètreExplicationType de données
z_min

The minimum z-value.

Double
z_max

The maximum z-value.

Double
setZFalseOriginAndUnits (false_z, z_units)
ParamètreExplicationType de données
false_z

The false z-value.

Double
z_units

The false z units.

Double

Exemple de code

SpatialReference example

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("{} has an unknown spatial reference".format(fc))

    # Otherwise, print out the feature class name and spatial reference
    else:
        print("{} : {}".format(fc, spatial_ref.name))

Rubriques connexes