OTB  9.0.0
Orfeo Toolbox
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
otb::SpatialReference Class Reference

#include <otbSpatialReference.h>

+ Collaboration diagram for otb::SpatialReference:

Public Types

enum  hemisphere {
  hemisphere::north,
  hemisphere::south
}
 
typedef std::unique_ptr< OGRSpatialReference, internal::OGRSpatialReferenceDeleterOGRSpatialReferencePtr
 

Public Member Functions

bool NormalizeESRI ()
 
SpatialReferenceoperator= (const SpatialReference &other) noexcept
 
 SpatialReference (const SpatialReference &other) noexcept
 
unsigned int ToEPSG () const
 
std::string ToWkt () const
 

Static Public Member Functions

static SpatialReference FromDescription (const std::string &sr_description)
 
static SpatialReference FromEPSG (unsigned int epsg)
 
static SpatialReference FromGeogCS (const std::string &GeogName, const std::string &DatumName, const std::string &SpheroidName, const double SemiMajor, const double InvFlattening)
 
static SpatialReference FromUTM (unsigned int zone, hemisphere hem)
 
static SpatialReference FromWGS84 ()
 
static void UTMFromGeoPoint (double lon, double lat, unsigned int &zone, hemisphere &hem)
 

Private Member Functions

 SpatialReference (const OGRSpatialReference *ref)
 
 SpatialReference (OGRSpatialReferencePtr ref)
 

Private Attributes

OGRSpatialReferencePtr m_SR
 

Friends

class CoordinateTransformation
 
OTBGdalAdapters_EXPORT friend bool operator!= (const SpatialReference &sr1, const SpatialReference &sr2) noexcept
 
OTBGdalAdapters_EXPORT friend bool operator== (const SpatialReference &sr1, const SpatialReference &sr2) noexcept
 

Detailed Description

This class is a wrapper around OGRSpatialReference.

This class is a wrapper around OGRSpatialReference. It aims at manipulating spatial reference within OTB, in a safe and easy way. The class provides several constructors that all enforce the RAII: either they fail or they provide a definitive, valid object.

Building a SpatialReference requires to call one of the From*() method. There are no public constructors (apart from copy and assignment)

Definition at line 79 of file otbSpatialReference.h.

Member Typedef Documentation

◆ OGRSpatialReferencePtr

Definition at line 86 of file otbSpatialReference.h.

Member Enumeration Documentation

◆ hemisphere

Build a SpatialReference from a UTM zone passed to OGRSpatialReference::SetUTM() from GDAL

Parameters
zoneUTM zone to use
hemhemisphere::north or hemisphere::south
Exceptions
InvalidSRDescriptionExceptionin case of failure of setUTM()
Enumerator
north 
south 

Definition at line 127 of file otbSpatialReference.h.

Constructor & Destructor Documentation

◆ SpatialReference() [1/3]

otb::SpatialReference::SpatialReference ( const SpatialReference other)
noexcept

Copy constructor.

◆ SpatialReference() [2/3]

otb::SpatialReference::SpatialReference ( const OGRSpatialReference *  ref)
private

Constructor from wrapped type. ref will be cloned.

◆ SpatialReference() [3/3]

otb::SpatialReference::SpatialReference ( OGRSpatialReferencePtr  ref)
private

Constructor from unique_ptr to wrapped type. On success (no throw) the passed unique_ptr will be cleared, and ownership transferred

Member Function Documentation

◆ FromDescription()

static SpatialReference otb::SpatialReference::FromDescription ( const std::string &  sr_description)
static

Build a SpatialRereference from a description string. The description string is passed to OGRSpatialReference:SetFromUserInput() from GDAL. Currently, supported syntax is:

  • Well Known Text definition
  • "EPSG:n" and "EPSGA:n" form EPSG codes
  • PROJ definitions
  • WMS auto projections ...
    Parameters
    descriptiona string containing the description of the spatial reference to parse
    Exceptions
    InvalidSRDescriptionExceptionin case of failure of SetFromUserInput()

Referenced by otb::GenericMapProjection< TDirectionOfMapping, TScalarType, NInputDimensions, NOutputDimensions >::SetWkt().

◆ FromEPSG()

static SpatialReference otb::SpatialReference::FromEPSG ( unsigned int  epsg)
static

Build a SpatialReference from an epsg code

Parameters
epsgEPSG code passed to OGRSpatialReference::importFromEPSGA() from GDAL
Exceptions
InvalidSRDescriptionExceptionin case of failure of importFromEPSGA()

Referenced by otb::MapFileProductWriter< TInputImage >::InitializeVectorData(), otb::MapFileProductWriter< TInputImage >::Tiling(), and otb::MapFileProductWriter< TInputImage >::Write().

◆ FromGeogCS()

static SpatialReference otb::SpatialReference::FromGeogCS ( const std::string &  GeogName,
const std::string &  DatumName,
const std::string &  SpheroidName,
const double  SemiMajor,
const double  InvFlattening 
)
static

Build a SpatialReference from the datum, ellipsoid, prime meridian and angular units.

See OGRSpatialReference::SetGeogCS for more details.

Parameters
GeogNameuser visible name for the geographic coordinate system
DatumNamekey name for this datum.
SpheroidNameuser visible spheroid name
SemiMajorthe semi major axis of the spheroid
InvFlatteningthe inverse flattening for the spheroid
Exceptions
InvalidSRDescriptionExceptionin case of failure of FromGeogCS()

◆ FromUTM()

static SpatialReference otb::SpatialReference::FromUTM ( unsigned int  zone,
hemisphere  hem 
)
static

◆ FromWGS84()

static SpatialReference otb::SpatialReference::FromWGS84 ( )
static

◆ NormalizeESRI()

bool otb::SpatialReference::NormalizeESRI ( )

Try to normalize spatial reference fields to be compatible with ESRI.

Returns
True on success. Not modified if false is returned

◆ operator=()

SpatialReference& otb::SpatialReference::operator= ( const SpatialReference other)
noexcept

Assignment operator.

◆ ToEPSG()

unsigned int otb::SpatialReference::ToEPSG ( ) const

Convert the spatial reference to an EPSG code

Returns
If no EPSG code was found or the EPSG code

◆ ToWkt()

std::string otb::SpatialReference::ToWkt ( ) const

Export the spatial reference to a Well Known Text string

Returns
A string containing the Well Known Text description

Referenced by otb::GenericRSResampleImageFilter< TInputImage, TOutputImage >::SetOutputParametersFromMap().

◆ UTMFromGeoPoint()

static void otb::SpatialReference::UTMFromGeoPoint ( double  lon,
double  lat,
unsigned int &  zone,
hemisphere hem 
)
static

Find which UTM zone a given (lat,lon) point falls in.

Precondition
-180<=lon<=180
-90<=lat<=90
Parameters
lonPoint longitude
latPoint latitude
zoneOutput UTM zone
hemoutput hemisphere

Referenced by otb::GenericRSResampleImageFilter< TInputImage, TOutputImage >::SetOutputParametersFromMap().

Friends And Related Function Documentation

◆ CoordinateTransformation

friend class CoordinateTransformation
friend

Definition at line 81 of file otbSpatialReference.h.

◆ operator!=

OTBGdalAdapters_EXPORT friend bool operator!= ( const SpatialReference sr1,
const SpatialReference sr2 
)
friend

Different operator (based on OGRSpatialReference::IsSame())

◆ operator==

OTBGdalAdapters_EXPORT friend bool operator== ( const SpatialReference sr1,
const SpatialReference sr2 
)
friend

Equal operator (based on OGRSpatialReference::IsSame())

Member Data Documentation

◆ m_SR

OGRSpatialReferencePtr otb::SpatialReference::m_SR
private

Definition at line 204 of file otbSpatialReference.h.


The documentation for this class was generated from the following file: