Python Spatial Reference System API

This page contains classes, methods and functions that relate to spatial reference systems:

SpatialReference

class osgeo.osr.SpatialReference(*args, **kwargs)

Python proxy of an OGRSpatialReference.

AddGuessedTOWGS84(SpatialReference self) OGRErr
AutoIdentifyEPSG(SpatialReference self) OGRErr

Add an EPSG authority code to the CRS where an aspect of the coordinate system can be easily and safely corresponded with an EPSG identifier.

See OGRSpatialReference::AutoIdentifyEPSG().

Returns:

OGRERR_NONE or OGRERR_UNSUPPORTED_SRS.

Return type:

int

Clone(SpatialReference self) SpatialReference
CloneGeogCS(SpatialReference self) SpatialReference
ConvertToOtherProjection(SpatialReference self, char const * other_projection, char ** options=None) SpatialReference
CopyGeogCSFrom(SpatialReference self, SpatialReference rhs) OGRErr
DemoteTo2D(SpatialReference self, char const * name=None) OGRErr
EPSGTreatsAsLatLong(SpatialReference self) int
EPSGTreatsAsNorthingEasting(SpatialReference self) int
ExportToCF1(options={})

Export a CRS to netCDF CF-1 definitions.

http://cfconventions.org/cf-conventions/cf-conventions.html#appendix-grid-mappings

ExportToCF1Units(SpatialReference self, char ** options=None) retStringAndCPLFree *
ExportToERM(SpatialReference self) OGRErr
ExportToMICoordSys(SpatialReference self) OGRErr
ExportToPCI(SpatialReference self) OGRErr
ExportToPROJJSON(SpatialReference self, char ** options=None) OGRErr

Export this SRS in PROJJSON format.

See OGRSpatialReference::exportToPROJJSON().

Parameters:

options (list/dict) -- Options to control the format of the output. See OGRSpatialReference::ExportToPROJJSON().

Return type:

str

ExportToPrettyWkt(SpatialReference self, int simplify=0) OGRErr

Convert this SRS into a nicely formatted WKT 1 string for display to a person.

See OGRSpatialReference::exportToPrettyWkt().

Parameters:

simplify (bool, default = False)

Return type:

str

ExportToProj4(SpatialReference self) OGRErr

Export this SRS to PROJ.4 legacy format.

Warning

Use of this function is discouraged. See OGRSpatialReference::exportToProj4().

Return type:

str

ExportToUSGS(SpatialReference self) OGRErr
ExportToWkt(SpatialReference self, char ** options=None) OGRErr

Export this SRS into WKT 1 format.

See OGRSpatialReference::exportToWkt().

Return type:

str

ExportToXML(SpatialReference self, char const * dialect="") OGRErr
FindMatches(SpatialReference self, char ** options=None)
GetAngularUnits(SpatialReference self) double

Fetch conversion between angular geographic coordinate system units and radians.

See OGRSpatialReference::GetAngularUnits().

Returns:

Value to multiply angular distances by to transform them to radians.

Return type:

float

Examples

>>> srs = osr.SpatialReference()
>>> srs.ImportFromEPSG(4326)
0
>>> srs.GetAngularUnits()
0.017453292519943295
GetAngularUnitsName(SpatialReference self) char const *

Fetch angular geographic coordinate system units.

See OGRSpatialReference::GetAngularUnits().

Return type:

str

Examples

>>> srs = osr.SpatialReference()
>>> srs.ImportFromEPSG(4326)
0
>>> srs.GetAngularUnitsName()
'degree'
GetAreaOfUse(SpatialReference self) AreaOfUse

Return the area of use of the SRS.

See OGRSpatialReference::GetAreaOfUse().

Returns:

object providing a description of the area of use as well as bounding parallels / meridians

Return type:

AreaOfUse

Examples

>>> vt_sp = osr.SpatialReference()
>>> vt_sp.ImportFromEPSG(5646)
0
>>> aou = vt_sp.GetAreaOfUse()
>>> aou.name
'United States (USA) - Vermont - counties of Addison; Bennington; Caledonia; Chittenden; Essex; Franklin; Grand Isle; Lamoille; Orange; Orleans; Rutland; Washington; Windham; Windsor.'
>>> aou.west_lon_degree, aou.south_lat_degree, aou.east_lon_degree, aou.north_lat_degree
(-73.44, 42.72, -71.5, 45.03)
GetAttrValue(SpatialReference self, char const * name, int child=0) char const *

Fetch indicated attribute of named node.

See OGRSpatialReference::GetAttrValue().

Parameters:
  • name (str) -- tree node to look for (case insensitive)

  • child (int, default = 0) -- 0-indexed child of the node

Return type:

str

Examples

>>> vt_sp = osr.SpatialReference()
>>> vt_sp.ImportFromEPSG(5646)
0
>>> vt_sp.GetAttrValue('UNIT', 0)
'US survey foot'
GetAuthorityCode(SpatialReference self, char const * target_key) char const *

Get the authority code for a node.

See OGRSpatialReference::GetAuthorityCode().

Parameters:

target_key (str) -- the partial or complete path to the node to get an authority from (e.g., 'PROJCS', 'GEOGCS' or None to get an authority code on the root element)

Return type:

str or None on failure

Examples

>>> srs = osr.SpatialReference()
>>> srs.ImportFromEPSG(4326)
0
>>> srs.GetAuthorityName('DATUM')
'EPSG'
>>> srs.GetAuthorityCode('DATUM')
'6326'
>>> srs.GetAuthorityCode(None)
'4326'
GetAuthorityName(SpatialReference self, char const * target_key) char const *

Get the authority name for a node.

See OGRSpatialReference::GetAuthorityName().

Parameters:

target_key (str) -- the partial or complete path to the node to get an authority from (e.g., 'PROJCS', 'GEOGCS' or None to get an authority name on the root element)

Return type:

str

GetAxesCount(SpatialReference self) int

Return the number of axes of the coordinate system of the CRS.

See OGRSpatialReference::GetAxesCount().

Return type:

int

Examples

>>> srs = osr.SpatialReference()
>>> srs.ImportFromEPSG(4326)
0
>>> srs.GetAxesCount()
2
>>> srs.ImportFromEPSG(4979)
0
>>> srs.GetAxesCount()
3
GetAxisMappingStrategy(SpatialReference self) OSRAxisMappingStrategy

Return the data axis to CRS axis mapping strategy:

  • OAMS_TRADITIONAL_GIS_ORDER means that for geographic CRS with lag/long order, the data will still be long/lat ordered. Similarly for a projected CRS with northing/easting order, the data will still be easting/northing ordered.

  • OAMS_AUTHORITY_COMPLIANT means that the data axis will be identical to the CRS axis.

  • OAMS_CUSTOM means that the ordering is defined with SetDataAxisToSRSAxisMapping().

See OGRSpatialReference::GetAxisMappingStrategy().

Return type:

int

GetAxisName(SpatialReference self, char const * target_key, int iAxis) char const *

Fetch an axis description.

See OGRSpatialReference::GetAxis().

Parameters:
  • target_key (str) -- The portion of the coordinate system, either 'GEOGCS' or 'PROJCS'

  • iAxis (int) -- The 0-based index of the axis to fetch

Return type:

str

Examples

>>> srs = osr.SpatialReference()
>>> srs.ImportFromEPSG(4979)
0
>>> for i in range(3):
...     srs.GetAxisName('GEOGCS', i)
...
'Geodetic latitude'
'Geodetic longitude'
'Ellipsoidal height'
GetAxisOrientation(SpatialReference self, char const * target_key, int iAxis) OGRAxisOrientation

Fetch an axis orientation.

See OGRSpatialReference::GetAxis().

Parameters:
  • target_key (str) -- The portion of the coordinate system, either 'GEOGCS' or 'PROJCS'

  • iAxis (int) -- The 0-based index of the axis to fetch

Return type:

int

Examples

>>> srs = osr.SpatialReference()
>>> srs.ImportFromEPSG(4979)
0
>>> srs.GetAxisOrientation('GEOGCS', 0) == osr.OAO_North
True
>>> srs.GetAxisOrientation('GEOGCS', 1) == osr.OAO_East
True
>>> srs.GetAxisOrientation('GEOGCS', 2) == osr.OAO_Up
True
GetCoordinateEpoch(SpatialReference self) double

Return the coordinate epoch as a decimal year.

See OGRSpatialReference::GetCoordinateEpoch().

Returns:

coordinate epoch as a decimal year, or 0 if not set/relevant

Return type:

float

GetDataAxisToSRSAxisMapping(SpatialReference self)

Return the data axis to SRS axis mapping.

See OGRSpatialReference::GetDataAxisToSRSAxisMapping().

Return type:

tuple

GetInvFlattening(SpatialReference self) double

Get the spheroid inverse flattening.

See OGRSpatialReference::GetInvFlattening().

Return type:

float

Examples

>>> srs = osr.SpatialReference()
>>> srs.ImportFromEPSG(4326) # WGS84
0
>>> srs.GetInvFlattening()
298.257223563
>>> srs.ImportFromEPSG(4269) # NAD83
0
>>> srs.GetInvFlattening()
298.257222101
GetLinearUnits(SpatialReference self) double

Fetch the conversion between linear projection units and meters.

See OGRSpatialReference::GetLinearUnits().

Return type:

float

Examples

>>> vt_sp = osr.SpatialReference()
>>> vt_sp.ImportFromEPSG(5646)
0
>>> vt_sp.GetLinearUnits()
0.30480060960121924
GetLinearUnitsName(SpatialReference self) char const *

Fetch the name of the linear projection units.

See OGRSpatialReference::GetLinearUnits().

Return type:

str

Examples

>>> vt_sp = osr.SpatialReference()
>>> vt_sp.ImportFromEPSG(5646)
0
>>> vt_sp.GetLinearUnitsName()
'US survey foot'
GetName(SpatialReference self) char const *

Return the CRS name.

See OGRSpatialReference::GetName().

Return type:

str

Examples

>>> vt_sp = osr.SpatialReference()
>>> vt_sp.ImportFromEPSG(5646)
0
>>> vt_sp.GetName()
'NAD83 / Vermont (ftUS)'
GetNormProjParm(SpatialReference self, char const * name, double default_val=0.0) double

Fetch a normalized projection parameter value.

This method is the same as GetProjParm() except that the value of the parameter is normalized into degrees or meters depending on whether it is linear or angular.

See OGRSpatialReference::GetNormProjParm().

Parameters:
  • name (str) -- parameter name, available as constants prefixed with SRS_PP.

  • default_val (float, default = 0.0) -- value to return if this parameter doesn't exist

Return type:

float

Examples

>>> vt_sp = osr.SpatialReference()
>>> vt_sp.ImportFromEPSG(5646)
0
>>> vt_sp.GetProjParm(osr.SRS_PP_FALSE_EASTING)
1640416.6667
>>> vt_sp.GetNormProjParm(osr.SRS_PP_FALSE_EASTING)
500000.0000101601
GetProjParm(SpatialReference self, char const * name, double default_val=0.0) double

Fetch a projection parameter value.

See OGRSpatialReference::GetProjParm().

Parameters:
  • name (str) -- parameter name, available as constants prefixed with SRS_PP.

  • default_val (float, default = 0.0) -- value to return if this parameter doesn't exist

Return type:

float

Examples

>>> vt_sp = osr.SpatialReference()
>>> vt_sp.ImportFromEPSG(5646)
0
>>> vt_sp.GetProjParm(osr.SRS_PP_FALSE_EASTING)
1640416.6667
>>> vt_sp.GetProjParm(osr.SRS_PP_FALSE_NORTHING)
0.0
GetSemiMajor(SpatialReference self) double

Get spheroid semi major axis (in meters starting with GDAL 3.0)

See OGRSpatialReference::GetSemiMajor().

Returns:

semi-major axis, or SRS_WGS84_SEMIMAJOR if it cannot be found.

Return type:

float

GetSemiMinor(SpatialReference self) double

Get spheroid semi minor axis.

See OGRSpatialReference::GetSemiMinor().

Returns:

semi-minor axis, or SRS_WGS84_SEMIMINOR if it cannot be found.

Return type:

float

GetTOWGS84(SpatialReference self) OGRErr

Fetch TOWGS84 parameter, if available.

See OGRSpatialReference::GetTOWGS84().

Return type:

tuple

GetTargetLinearUnits(SpatialReference self, char const * target_key) double

Fetch linear units for a target.

See OGRSpatialReference::GetTargetLinearUnits().

Parameters:

target_key (str) -- key to look un, such as 'PROJCS' or 'VERT_CS'

Return type:

double

GetUTMZone(SpatialReference self) int

Get UTM zone.

See OGRSpatialReference::GetUTMZone().

Returns:

UTM zone number. Negative in the southern hemisphere and positive in the northern hemisphere. If the SRS is not UTM, zero will be returned.

Return type:

int

HasPointMotionOperation(SpatialReference self) bool

Check if a CRS has an associated point motion operation.

See OGRSpatialReference::HasPointMotionOperation().

Return type:

bool

HasTOWGS84(SpatialReference self) bool

Return whether the SRS has a TOWGS84 parameter.

See OGRSpatialReference::GetTOWGS84().

Return type:

bool

ImportFromCF1(keyValues, units='')

Import a CRS from netCDF CF-1 definitions.

http://cfconventions.org/cf-conventions/cf-conventions.html#appendix-grid-mappings

ImportFromEPSG(SpatialReference self, int arg) OGRErr

Initialize SRS based on EPSG geographic, projected or vertical CRS code.

Since GDAL 3.0, this method is identical to ImportFromEPSGA().

See OGRSpatialReference::importFromEPSG().

Parameters:

arg (int) -- EPSG code to search in PROJ database

Returns:

OGRERR_NONE on success, or an error code on failure

Return type:

int

Examples

>>> srs = osr.SpatialReference()
>>> srs.ImportFromEPSG(4326)
0
ImportFromEPSGA(SpatialReference self, int arg) OGRErr

Initialize SRS based on EPSG geographic, projected or vertical CRS code.

Since GDAL 3.0, this method is identical to ImportFromEPSG().

See OGRSpatialReference::importFromEPSGA().

Parameters:

arg (int) -- EPSG code to search in PROJ database

Returns:

OGRERR_NONE on success, or an error code on failure

Return type:

int

ImportFromERM(SpatialReference self, char const * proj, char const * datum, char const * units) OGRErr
ImportFromESRI(SpatialReference self, char ** ppszInput) OGRErr
ImportFromMICoordSys(SpatialReference self, char const * pszCoordSys) OGRErr
ImportFromOzi(SpatialReference self, char const *const * papszLines) OGRErr
ImportFromPCI(SpatialReference self, char const * proj, char const * units="METRE", double [17] argin=0) OGRErr
ImportFromProj4(SpatialReference self, char * ppszInput) OGRErr

Initialize SRS based on PROJ coordinate string.

See OGRSpatialReference::importFromProj4().

Parameters:

ppszInput (str) -- PROJ coordinate string

Returns:

OGRERR_NONE on success, or OGRERR_CORRUPT_DATA on failure

Return type:

int

Examples

>>> srs = osr.SpatialReference()
>>> srs.ImportFromProj4('+proj=utm +zone=18 +datum=WGS84')
0
ImportFromUSGS(SpatialReference self, long proj_code, long zone=0, double [15] argin=0, long datum_code=0) OGRErr
ImportFromUrl(SpatialReference self, char * url) OGRErr

Initialize SRS based on a URL.

This method will download the spatial reference at a given URL and feed it into SetFromUserInput() for you.

See OGRSpatialReference::importFromUrl().

Parameters:

url (str)

Returns:

OGRERR_NONE on success, or an error code on failure

Return type:

int

ImportFromWkt(SpatialReference self, char ** ppszInput) OGRErr

Import from WKT string.

See OGRSpatialReference::importFromWkt().

Parameters:

ppszInput (str) -- WKT string

Returns:

OGRERR_NONE if import succeeds, or OGRERR_CORRUPT_DATA if it fails for any reason.

Return type:

int

ImportFromXML(SpatialReference self, char const * xmlString) OGRErr
IsCompound(SpatialReference self) int

Check if this CRS is a compound CRS.

See OGRSpatialReference::IsCompound().

Returns:

1 if the CRS is compound, 0 otherwise

Return type:

int

IsDerivedGeographic(SpatialReference self) int

Check if this CRS is a derived geographic CRS, such as a rotated long/lat grid.

See OGRSpatialReference::IsDerivedGeographic().

Returns:

1 if the CRS is derived geographic, 0 otherwise

Return type:

int

IsDerivedProjected(SpatialReference self) int
IsDynamic(SpatialReference self) bool

Check if this CRS is a dynamic coordinate CRS.

See OGRSpatialReference::IsDynamic().

Return type:

bool

IsGeocentric(SpatialReference self) int

Check if this SRS is a geocentric coordinate system.

See OGRSpatialReference::IsGeocentric().

Returns:

1 if the SRS is geocentric, 0 otherwise

Return type:

int

IsGeographic(SpatialReference self) int

Check if this SRS is a geographic coordinate system.

See OGRSpatialReference::IsGeographic().

Returns:

1 if the SRS is geographic, 0 otherwise

Return type:

int

IsLocal(SpatialReference self) int

Check if this CRS is a local CRS.

See OGRSpatialReference::IsLocal().

Returns:

1 if the SRS is local, 0 otherwise

Return type:

int

IsProjected(SpatialReference self) int

Check if this SRS is a projected coordinate system.

See OGRSpatialReference::IsProjected().

Returns:

1 if the SRS is projected, 0 otherwise

Return type:

int

IsSame(SpatialReference self, SpatialReference rhs, char ** options=None) int

Determine if two spatial references describe the same system.

See OGRSpatialReference::IsSame().

Parameters:
Returns:

1 if the spatial references describe the same system, 0 otherwise

Return type:

int

IsSameGeogCS(SpatialReference self, SpatialReference rhs) int

Determine if two spatial references share the same geographic coordinate system.

See OGRSpatialReference::IsSameGeogCS().

Parameters:
Returns:

1 if the spatial references have the same GeogCS, 0 otherwise

Return type:

int

IsSameVertCS(SpatialReference self, SpatialReference rhs) int

Determine if two spatial references share the same vertical coordinate system.

See OGRSpatialReference::IsSameVertCS().

Parameters:
Returns:

1 if the spatial references have the same VertCS, 0 otherwise

Return type:

int

IsVertical(SpatialReference self) int

Check if this is a vertical coordinate system.

See OGRSpatialReference::IsVertical().

Returns:

1 if the CRS is vertical, 0 otherwise

Return type:

int

MorphFromESRI(SpatialReference self) OGRErr
MorphToESRI(SpatialReference self) OGRErr
PromoteTo3D(SpatialReference self, char const * name=None) OGRErr
SetACEA(SpatialReference self, double stdp1, double stdp2, double clat, double clong, double fe, double fn) OGRErr
SetAE(SpatialReference self, double clat, double clong, double fe, double fn) OGRErr
SetAngularUnits(SpatialReference self, char const * name, double to_radians) OGRErr
SetAttrValue(SpatialReference self, char const * name, char const * value) OGRErr
SetAuthority(SpatialReference self, char const * pszTargetKey, char const * pszAuthority, int nCode) OGRErr
SetAxisMappingStrategy(SpatialReference self, OSRAxisMappingStrategy strategy)
SetBonne(SpatialReference self, double stdp, double cm, double fe, double fn) OGRErr
SetCEA(SpatialReference self, double stdp1, double cm, double fe, double fn) OGRErr
SetCS(SpatialReference self, double clat, double clong, double fe, double fn) OGRErr
SetCompoundCS(SpatialReference self, char const * name, SpatialReference horizcs, SpatialReference vertcs) OGRErr
SetCoordinateEpoch(SpatialReference self, double coordinateEpoch)
SetDataAxisToSRSAxisMapping(SpatialReference self, int nList) OGRErr
SetEC(SpatialReference self, double stdp1, double stdp2, double clat, double clong, double fe, double fn) OGRErr
SetEckertIV(SpatialReference self, double cm, double fe, double fn) OGRErr
SetEckertVI(SpatialReference self, double cm, double fe, double fn) OGRErr
SetEquirectangular(SpatialReference self, double clat, double clong, double fe, double fn) OGRErr
SetEquirectangular2(SpatialReference self, double clat, double clong, double pseudostdparallellat, double fe, double fn) OGRErr
SetFromUserInput(SpatialReference self, char const * name, char ** options=None) OGRErr
SetGEOS(SpatialReference self, double cm, double satelliteheight, double fe, double fn) OGRErr
SetGH(SpatialReference self, double cm, double fe, double fn) OGRErr
SetGS(SpatialReference self, double cm, double fe, double fn) OGRErr
SetGaussSchreiberTMercator(SpatialReference self, double clat, double clong, double sc, double fe, double fn) OGRErr
SetGeocCS(SpatialReference self, char const * name="unnamed") OGRErr
SetGeogCS(SpatialReference self, char const * pszGeogName, char const * pszDatumName, char const * pszEllipsoidName, double dfSemiMajor, double dfInvFlattening, char const * pszPMName="Greenwich", double dfPMOffset=0.0, char const * pszUnits="degree", double dfConvertToRadians=0.0174532925199433) OGRErr
SetGnomonic(SpatialReference self, double clat, double clong, double fe, double fn) OGRErr
SetHOM(SpatialReference self, double clat, double clong, double azimuth, double recttoskew, double scale, double fe, double fn) OGRErr
SetHOM2PNO(SpatialReference self, double clat, double dfLat1, double dfLong1, double dfLat2, double dfLong2, double scale, double fe, double fn) OGRErr
SetIGH(SpatialReference self) OGRErr
SetKrovak(SpatialReference self, double clat, double clong, double azimuth, double pseudostdparallellat, double scale, double fe, double fn) OGRErr
SetLAEA(SpatialReference self, double clat, double clong, double fe, double fn) OGRErr
SetLCC(SpatialReference self, double stdp1, double stdp2, double clat, double clong, double fe, double fn) OGRErr
SetLCC1SP(SpatialReference self, double clat, double clong, double scale, double fe, double fn) OGRErr
SetLCCB(SpatialReference self, double stdp1, double stdp2, double clat, double clong, double fe, double fn) OGRErr
SetLinearUnits(SpatialReference self, char const * name, double to_meters) OGRErr
SetLinearUnitsAndUpdateParameters(SpatialReference self, char const * name, double to_meters) OGRErr
SetLocalCS(SpatialReference self, char const * pszName) OGRErr
SetMC(SpatialReference self, double clat, double clong, double fe, double fn) OGRErr
SetMercator(SpatialReference self, double clat, double clong, double scale, double fe, double fn) OGRErr
SetMercator2SP(SpatialReference self, double stdp1, double clat, double clong, double fe, double fn) OGRErr
SetMollweide(SpatialReference self, double cm, double fe, double fn) OGRErr
SetNZMG(SpatialReference self, double clat, double clong, double fe, double fn) OGRErr
SetNormProjParm(SpatialReference self, char const * name, double val) OGRErr
SetOS(SpatialReference self, double dfOriginLat, double dfCMeridian, double scale, double fe, double fn) OGRErr
SetOrthographic(SpatialReference self, double clat, double clong, double fe, double fn) OGRErr
SetPS(SpatialReference self, double clat, double clong, double scale, double fe, double fn) OGRErr
SetPolyconic(SpatialReference self, double clat, double clong, double fe, double fn) OGRErr
SetProjCS(SpatialReference self, char const * name="unnamed") OGRErr
SetProjParm(SpatialReference self, char const * name, double val) OGRErr
SetProjection(SpatialReference self, char const * arg) OGRErr
SetRobinson(SpatialReference self, double clong, double fe, double fn) OGRErr
SetSOC(SpatialReference self, double latitudeoforigin, double cm, double fe, double fn) OGRErr
SetSinusoidal(SpatialReference self, double clong, double fe, double fn) OGRErr
SetStatePlane(SpatialReference self, int zone, int is_nad83=1, char const * unitsname="", double units=0.0) OGRErr
SetStereographic(SpatialReference self, double clat, double clong, double scale, double fe, double fn) OGRErr
SetTM(SpatialReference self, double clat, double clong, double scale, double fe, double fn) OGRErr
SetTMG(SpatialReference self, double clat, double clong, double fe, double fn) OGRErr
SetTMSO(SpatialReference self, double clat, double clong, double scale, double fe, double fn) OGRErr
SetTMVariant(SpatialReference self, char const * pszVariantName, double clat, double clong, double scale, double fe, double fn) OGRErr
SetTOWGS84(SpatialReference self, double p1, double p2, double p3, double p4=0.0, double p5=0.0, double p6=0.0, double p7=0.0) OGRErr
SetTargetLinearUnits(SpatialReference self, char const * target, char const * name, double to_meters) OGRErr
SetUTM(SpatialReference self, int zone, int north=1) OGRErr
SetVDG(SpatialReference self, double clong, double fe, double fn) OGRErr
SetVertCS(SpatialReference self, char const * VertCSName="unnamed", char const * VertDatumName="unnamed", int VertDatumType=0) OGRErr
SetVerticalPerspective(SpatialReference self, double topoOriginLat, double topoOriginLon, double topoOriginHeight, double viewPointHeight, double fe, double fn) OGRErr
SetWellKnownGeogCS(SpatialReference self, char const * name) OGRErr
StripVertical(SpatialReference self) OGRErr
Validate(SpatialReference self) OGRErr

CoordinateTransformation

class osgeo.osr.CoordinateTransformation(*args)

Python proxy of an OGRCoordinateTransformation.

GetInverse(CoordinateTransformation self) CoordinateTransformation
TransformBounds(CoordinateTransformation self, double minx, double miny, double maxx, double maxy, int densify_pts)

Transform a boundary, densifying the edges to account for nonlinear transformations along these edges.

See OCTTransformBounds().

Parameters:
  • minx (float) -- Minimum bounding coordinate of the first axis in source CRS

  • miny (float) -- Minimum bounding coordinate of the second axis in source CRS

  • maxx (float) -- Maximum bounding coordinate of the first axis in source CRS

  • maxy (float) -- Maximum bounding coordinate of the second axis in source CRS

  • densify_pts (int) -- The number of points to use to densify the bounding polygon. Recommended to use 21.

Returns:

Transformed values of xmin, ymin, xmax, ymax

Return type:

tuple

Examples

>>> ct.TransformBounds(-72.5, 44.2, -72.4, 44.3, 21)
(7415356.140468472, -51238192.683464445, 7454323.154814391, -51210287.42581475)
TransformPoint(CoordinateTransformation self, double [3] inout)
TransformPoint(CoordinateTransformation self, double [4] inout) None
TransformPoint(CoordinateTransformation self, double x, double y, double z=0.0) None
TransformPoint(CoordinateTransformation self, double x, double y, double z, double t) None

Transform a single point.

See OCTTransform().

Returns:

A tuple of (x, y, z) or (x, y, z, t) values, depending on the input.

Return type:

tuple

Examples

>>> wgs84 = osr.SpatialReference()
>>> wgs84.ImportFromEPSG(4326)
0
>>> vt_sp = osr.SpatialReference()
>>> vt_sp.ImportFromEPSG(5646)
0
>>> ct = osr.CoordinateTransformation(wgs84, ps)
>>> ct.TransformPoint(-72.58, 44.26)
(7390620.052019633, -51202148.77747277, 0.0)
>>> ct.TransformPoint(-72.58, 44.26, 103)
(7390620.052019633, -51202148.77747277, 103.0)
TransformPointWithErrorCode(CoordinateTransformation self, double x, double y, double z, double t)

Variant of TransformPoint() that provides an error code.

See OCTTransformEx().

Parameters:
  • x (float)

  • y (float)

  • z (float)

  • t (float)

Returns:

tuple of (x, y, z, t, error) values

Return type:

tuple

TransformPoints(CoordinateTransformation self, int nCount)

Transform multiple points.

See OCTTransform().

Parameters:

arg -- A list of tuples, or a 2xN, 3xN, or 4xN numpy array

Returns:

A list of tuples of (x, y, z) or (x, y, z, t) values, depending on the input.

Return type:

list

Examples

>>> ct.TransformPoints([(-72.58, 44.26), (-72.59, 44.26)])
[(7390620.052019633, -51202148.77747277, 0.0), (7387261.070131293, -51200373.68798984, 0.0)]
>>> import numpy as np
>>> ct.TransformPoints(np.array([[-72.58, 44.26], [-72.59, 44.26]]))
[(7390620.052019633, -51202148.77747277, 0.0), (7387261.070131293, -51200373.68798984, 0.0)]
class osgeo.osr.CoordinateTransformationOptions(*args)

Proxy of C++ OGRCoordinateTransformationOptions class.

SetAreaOfInterest(CoordinateTransformationOptions self, double westLongitudeDeg, double southLatitudeDeg, double eastLongitudeDeg, double northLatitudeDeg) bool
SetBallparkAllowed(CoordinateTransformationOptions self, bool allowBallpark) bool
SetDesiredAccuracy(CoordinateTransformationOptions self, double accuracy) bool
SetOnlyBest(CoordinateTransformationOptions self, bool onlyBest) bool
SetOperation(CoordinateTransformationOptions self, char const * operation, bool inverseCT=False) bool
osgeo.osr.CreateCoordinateTransformation(SpatialReference src, SpatialReference dst, CoordinateTransformationOptions options=None) CoordinateTransformation

Create a CoordinateTransformation using a set of CoordinateTransformationOptions.

See OCTNewCoordinateTransformationEx().

Parameters:
Return type:

CoordinateTransformation