SpatialReference

サマリー

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.

説明

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、および M 範囲は、空間参照ドメインと同じではありません。空間参照に含まれる XY、Z、および M ドメインには、フィーチャクラスに格納できる座標値の有効な範囲が定義されています。フィーチャクラスの範囲は、そのフィーチャクラス内にある座標値の実際の範囲を意味します。これらの範囲は、ドメインよりも大きくすることができません。

The SpatialReference object supports equal (==) and not equal (!=) operators for comparing spatial references.

注意:

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.

構文

 SpatialReference ({item}, {vcs}, {text})
パラメーター説明データ タイプ
item

The horizontal coordinate system used to create the SpatialReference object. The coordinate system can be set using a projection file, name, or factory code.

Create a SpatialReference object using the display name of a coordinate system.

sr = arcpy.SpatialReference("Sinusoidal (world)")

Create a SpatialReference object using the canonical name of a coordinate system.

sr = arcpy.SpatialReference("World_Sinusoidal")

Create a SpatialReference object using a coordinate system's factory code (or authority code or WKID).

# The factory code of 32145 represents: 
# NAD 1983 StatePlane Vermont FIPS 4400 (Meters)

sr = arcpy.SpatialReference(32145)

Create a SpatialReference object using a projection file (.prj).

sr = arcpy.SpatialReference("c:/coordsystems/NAD 1983.prj")

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.

sr = arcpy.SpatialReference("Hawaii Albers Equal Area Conic", "MSL Height")

Define the vertical coordinate system using a factory code.

# 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)
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 SpatialReference object with a vertical coordinate system using the text argument, define the vertical coordinate system using the VERTCS section of the WKT string. The vcs argument is not used.

Create a SpatialReference object using a WKT string with a horizontal coordinate system.

# String below 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(text=wkt)

Create a SpatialReference object using a WKT2 string with a horizontal coordinate system.

# The following string is the WKT2 for the
# Projected Coordinate System "NAD 1983 StatePlane California V FIPS 0405 (US FEET)
# (factory code=2229)
wkt2 = """
PROJCRS[
   "NAD_1983_StatePlane_California_V_FIPS_0405_Feet",
   BASEGEOGCRS["GCS_North_American_1983",DATUM["D_North_American_1983",
   ELLIPSOID["GRS_1980",6378137.0,298.257222101,LENGTHUNIT["Meter",1.0]]
],
PRIMEM["Greenwich",0.0,ANGLEUNIT["Degree",0.017453292519943295]],CS[ellipsoidal,2],
AXIS["Latitude (lat)",north,ORDER[1]],AXIS["Longitude (lon)",east,ORDER[2]],
ANGLEUNIT["Degree",0.017453292519943295]],
CONVERSION["Lambert_Conformal_Conic",METHOD["Lambert_Conformal_Conic"],
PARAMETER["False_Easting",6561666.666666666,LENGTHUNIT["Foot_US",0.30480060960121924]],
PARAMETER["False_Northing",1640416.666666667,LENGTHUNIT["Foot_US",0.30480060960121924]],
PARAMETER["Central_Meridian",-118.0,ANGLEUNIT["Degree",0.017453292519943295]],
PARAMETER["Standard_Parallel_1",34.033333333333331,ANGLEUNIT["Degree",0.017453292519943295]],
PARAMETER["Standard_Parallel_2",35.466666666666669,ANGLEUNIT["Degree",0.017453292519943295]],
PARAMETER["Latitude_Of_Origin",33.5,ANGLEUNIT["Degree",0.017453292519943295]]],CS[Cartesian,2],
AXIS["Easting (X)",east,ORDER[1]],AXIS["Northing (Y)",north,ORDER[2]],
LENGTHUNIT["Foot_US",0.30480060960121924]]
"""

sr = arcpy.SpatialReference(text=wkt2)

Create a SpatialReference object using a WKT string with a horizontal and vertical 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]],
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(text=wkt)
String

プロパティ

プロパティ説明データ タイプ
GCS
(読み取り専用)

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 value.

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
VCS
(読み取り専用)

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

Object
XYResolution
(読み書き)

The x,y-resolution.

Double
XYTolerance
(読み書き)

The x,y-tolerance.

Double
ZDomain
(読み取り専用)

The extent of the z-domain.

String
ZFalseOriginAndUnits
(読み取り専用)

The z false origin and units.

String
ZResolution
(読み書き)

The z-resolution.

Double
ZTolerance
(読み書き)

The z-tolerance.

Double
abbreviation
(読み書き)

The abbreviated name of the spatial reference.

String
alias
(読み書き)

The alias of the spatial reference.

String
domain
(読み取り専用)

The extent of the x,y-domain.

String
factoryCode
(読み書き)

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

Integer
falseOriginAndUnits
(読み取り専用)

The false origin and units.

String
hasMPrecision
(読み取り専用)

Specifies whether m-value precision information has been defined.

Boolean
hasXYPrecision
(読み取り専用)

Specifies whether x,y-coordinate precision information has been defined.

Boolean
hasZPrecision
(読み取り専用)

Specifies whether z-value precision information has been defined.

Boolean
isHighPrecision
(読み書き)

Specifies whether 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
(読み書き)

Specifies the type of the spatial reference.

  • Geographic—A geographic coordinate system
  • Projected—A projected coordinate system
  • Unknown—An unknown coordinate system
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
latitudeOfOrigin
(読み書き)

The latitude of origin 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
metersPerUnit
(読み取り専用)

The meters per linear unit.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 SpatialReference object using properties.

createFromFile (prj_file)

Creates the SpatialReference object from a projection file.

exportToString ({encoding})

Exports the object to its string representation.

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 VERTCS section 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)

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.

方法

create ()
createFromFile (prj_file)
パラメーター説明データ タイプ
prj_file

The projection file used to populate the SpatialReference object.

String
exportToString ({encoding})
パラメーター説明データ タイプ
encoding

Specifies the encoding of the exported string.

  • WKT—The spatial reference will be exported to the WKT standard.
  • WKT2—The spatial reference will be exported to the WKT 2 standard.

(デフォルト値は次のとおりです WKT)

String
戻り値
データ タイプ説明
String

The WKT or WKT 2 representation of the object.

loadFromString (string)
パラメーター説明データ タイプ
string

The WKT string representation of the object.

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

The false x value.

Double
false_y

The false y value.

Double
xy_units

The xy units.

String
setMDomain (m_min, m_max)
パラメーター説明データ タイプ
m_min

The minimum m-value.

Double
m_max

The maximum m-value.

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

The minimum z-value.

Double
z_max

The maximum z-value.

Double
setZFalseOriginAndUnits (false_z, z_units)
パラメーター説明データ タイプ
false_z

The false z-value.

Double
z_units

The false z units.

Double

コードのサンプル

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

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

関連トピック