Skip to main content

SpatialReference

A wrapper for the OGRSpatialReference object. According to the GDAL web site, the SpatialReference object "provide[s] services to represent coordinate systems (projections and datums) and to transform between them."

Attributes

AttributeTypeDescription
destructorcallable = capi.release_srsThe C API function used to release the OGRSpatialReference object when the instance is destroyed.
axis_order[AxisOrder](axisorder.md?sid=django_contrib_gis_gdal_srs_axisorder) = AxisOrder.TRADITIONALThe strategy used for coordinate axis ordering, which must be an AxisOrder instance.
ptrpointerThe internal pointer to the underlying OGRSpatialReference C object.
namestringReturn the name of this Spatial Reference.
sridintegerReturn the SRID of top-level authority, or None if undefined.
linear_namestringReturn the name of the linear units.
linear_unitsfloatReturn the value of the linear units.
angular_namestringReturn the name of the angular units.
angular_unitsfloatReturn the value of the angular units.
unitstupleReturn a 2-tuple of the units value and the units name.
ellipsoidtupleReturn a tuple of the ellipsoid parameters: (semimajor axis, semiminor axis, and inverse flattening).
semi_majorfloatReturn the Semi Major Axis for this Spatial Reference.
semi_minorfloatReturn the Semi Minor Axis for this Spatial Reference.
inverse_flatteningfloatReturn the Inverse Flattening for this Spatial Reference.
geographicbooleanReturn True if this SpatialReference is geographic (root node is GEOGCS).
localbooleanReturn True if this SpatialReference is local (root node is LOCAL_CS).
projectedbooleanReturn True if this SpatialReference is a projected coordinate system (root node is PROJCS).
wktstringReturn the WKT representation of this Spatial Reference.
pretty_wktstringReturn the 'pretty' representation of the WKT.
projstringReturn the PROJ representation for this Spatial Reference.
proj4stringAlias for proj().
xmlstringReturn the XML representation of this Spatial Reference.

Constructor

Signature

def SpatialReference(
srs_input: string|int = "",
srs_type: string = "user",
axis_order: [AxisOrder](axisorder.md?sid=django_contrib_gis_gdal_srs_axisorder) = null
) - > null

Parameters

NameTypeDescription
srs_input`stringint` = ""
srs_typestring = "user"The type of the input provided in srs_input (e.g., 'user', 'wkt', 'epsg').
axis_order[AxisOrder](axisorder.md?sid=django_contrib_gis_gdal_srs_axisorder) = nullThe axis order strategy to be used by the spatial reference.

Methods


attr_value()

@classmethod
def attr_value(
target: string,
index: integer = 0
) - > string

The attribute value for the given target node (e.g. 'PROJCS'). The index keyword specifies an index of the child node to return.

Parameters

NameTypeDescription
targetstringThe name of the WKT node to query.
indexinteger = 0The zero-based index of the child node to retrieve.

Returns

TypeDescription
stringThe string value of the specified attribute node.

auth_name()

@classmethod
def auth_name(
target: string
) - > string

Return the authority name for the given string target node.

Parameters

NameTypeDescription
targetstringThe WKT node name for which to retrieve the authority name.

Returns

TypeDescription
stringThe name of the authority (e.g., 'EPSG') for the specified node.

auth_code()

@classmethod
def auth_code(
target: string
) - > string

Return the authority code for the given string target node.

Parameters

NameTypeDescription
targetstringThe WKT node name for which to retrieve the authority code.

Returns

TypeDescription
stringThe authority's identification code (e.g., '4326') for the specified node.

clone()

@classmethod
def clone() - > [SpatialReference](spatialreference.md?sid=django_contrib_gis_gdal_srs_spatialreference)

Return a clone of this SpatialReference object.

Returns

TypeDescription
[SpatialReference](spatialreference.md?sid=django_contrib_gis_gdal_srs_spatialreference)A new SpatialReference instance that is a duplicate of the current one.

from_esri()

@classmethod
def from_esri()

Morph this SpatialReference from ESRI's format to EPSG.


identify_epsg()

@classmethod
def identify_epsg()

This method inspects the WKT of this SpatialReference, and will add EPSG authority nodes where an EPSG identifier is applicable.


to_esri()

@classmethod
def to_esri()

Morph this SpatialReference to ESRI's format.


validate()

@classmethod
def validate()

Check to see if the given spatial reference is valid.


name()

@classmethod
def name() - > string

Return the name of this Spatial Reference.

Returns

TypeDescription
stringThe name of the coordinate system (e.g., PROJCS or GEOGCS value).

srid()

@classmethod
def srid() - > integer

Return the SRID of top-level authority, or None if undefined.

Returns

TypeDescription
integerThe integer Spatial Reference Identifier or None.

linear_name()

@classmethod
def linear_name() - > string

Return the name of the linear units.

Returns

TypeDescription
stringThe name of the linear unit of measure (e.g., 'metre').

linear_units()

@classmethod
def linear_units() - > float

Return the value of the linear units.

Returns

TypeDescription
floatThe conversion factor from the linear unit to meters.

angular_name()

@classmethod
def angular_name() - > string

Return the name of the angular units.

Returns

TypeDescription
stringThe name of the angular unit of measure (e.g., 'degree').

angular_units()

@classmethod
def angular_units() - > float

Return the value of the angular units.

Returns

TypeDescription
floatThe conversion factor from the angular unit to radians.

units()

@classmethod
def units() - > tuple

Return a 2-tuple of the units value and the units name. Automatically determine whether to return the linear or angular units.

Returns

TypeDescription
tupleA tuple containing the unit conversion factor and the unit name string.

ellipsoid()

@classmethod
def ellipsoid() - > tuple

Return a tuple of the ellipsoid parameters: (semimajor axis, semiminor axis, and inverse flattening)

Returns

TypeDescription
tupleA 3-tuple containing the semi-major axis, semi-minor axis, and inverse flattening values.

semi_major()

@classmethod
def semi_major() - > float

Return the Semi Major Axis for this Spatial Reference.

Returns

TypeDescription
floatThe length of the semi-major axis of the ellipsoid.

semi_minor()

@classmethod
def semi_minor() - > float

Return the Semi Minor Axis for this Spatial Reference.

Returns

TypeDescription
floatThe length of the semi-minor axis of the ellipsoid.

inverse_flattening()

@classmethod
def inverse_flattening() - > float

Return the Inverse Flattening for this Spatial Reference.

Returns

TypeDescription
floatThe inverse flattening value of the ellipsoid.

geographic()

@classmethod
def geographic() - > boolean

Return True if this SpatialReference is geographic (root node is GEOGCS).

Returns

TypeDescription
booleanTrue if the spatial reference is geographic, False otherwise.

local()

@classmethod
def local() - > boolean

Return True if this SpatialReference is local (root node is LOCAL_CS).

Returns

TypeDescription
booleanTrue if the spatial reference is a local coordinate system, False otherwise.

projected()

@classmethod
def projected() - > boolean

Return True if this SpatialReference is a projected coordinate system (root node is PROJCS).

Returns

TypeDescription
booleanTrue if the spatial reference is projected, False otherwise.

import_epsg()

@classmethod
def import_epsg(
epsg: integer
)

Import the Spatial Reference from the EPSG code (an integer).

Parameters

NameTypeDescription
epsgintegerThe EPSG numeric code representing the coordinate system.

import_proj()

@classmethod
def import_proj(
proj: string
)

Import the Spatial Reference from a PROJ string.

Parameters

NameTypeDescription
projstringThe PROJ projection string defining the spatial reference.

import_user_input()

@classmethod
def import_user_input(
user_input: string
)

Import the Spatial Reference from the given user input string.

Parameters

NameTypeDescription
user_inputstringA string containing WKT, PROJ, or a well-known shorthand like 'WGS84'.

import_wkt()

@classmethod
def import_wkt(
wkt: string
)

Import the Spatial Reference from OGC WKT (string)

Parameters

NameTypeDescription
wktstringThe OGC Well Known Text string to parse.

import_xml()

@classmethod
def import_xml(
xml: string
)

Import the Spatial Reference from an XML string.

Parameters

NameTypeDescription
xmlstringThe XML string containing the spatial reference definition.

wkt()

@classmethod
def wkt() - > string

Return the WKT representation of this Spatial Reference.

Returns

TypeDescription
stringThe OGC Well Known Text string for this spatial reference.

pretty_wkt()

@classmethod
def pretty_wkt(
simplify: integer = 0
) - > string

Return the 'pretty' representation of the WKT.

Parameters

NameTypeDescription
simplifyinteger = 0A flag indicating whether to simplify the output WKT.

Returns

TypeDescription
stringA formatted, multi-line Well Known Text string.

proj()

@classmethod
def proj() - > string

Return the PROJ representation for this Spatial Reference.

Returns

TypeDescription
stringThe PROJ string representation of the coordinate system.

proj4()

@classmethod
def proj4() - > string

Alias for proj().

Returns

TypeDescription
stringThe PROJ string representation of the coordinate system.

xml()

@classmethod
def xml(
dialect: string = ""
) - > string

Return the XML representation of this Spatial Reference.

Parameters

NameTypeDescription
dialectstring = ""The specific XML dialect to use for the output.

Returns

TypeDescription
stringThe XML string representation of the spatial reference.