OTB  10.0.0
Orfeo Toolbox
otbSpatialReference.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef otbSpatialReference_h
21 #define otbSpatialReference_h
22 
23 #include "OTBGdalAdaptersExport.h"
24 
25 #include <cassert>
26 #include <memory>
27 #include <string>
28 
29 #if defined(_MSC_VER)
30 #pragma warning(disable : 4251)
31 // Disable following warning :
32 // warning C4251: 'otb::SpatialReference::m_SR':
33 // class 'std::unique_ptr<OGRSpatialReference,OGRSpatialReferenceDeleter>' needs
34 // to have dll-interface to be used by clients of class 'otb::SpatialReference'
35 // As long as otb::SpatialReference::m_SR is private no need to export this type.
36 #endif
37 
38 // causes warning C4251 on Windows
39 #include "ogr_spatialref.h"
40 
41 class OGRSpatialReference;
42 
43 namespace otb
44 {
45 // Destructor of OGRSpatialReference
46 namespace internal
47 {
48 struct OTBGdalAdapters_EXPORT OGRSpatialReferenceDeleter
49 {
50 public:
51  void operator()(OGRSpatialReference* del) const;
52 };
53 }
54 
55 // Forward declaration needed for the operators declared bellow.
56 class SpatialReference;
57 
59 OTBGdalAdapters_EXPORT bool operator==(const SpatialReference& sr1, const SpatialReference& sr2) noexcept;
60 
62 OTBGdalAdapters_EXPORT bool operator!=(const SpatialReference& sr1, const SpatialReference& sr2) noexcept;
63 
80 class OTBGdalAdapters_EXPORT SpatialReference
81 {
83  OTBGdalAdapters_EXPORT friend bool operator==(const SpatialReference& sr1, const SpatialReference& sr2) noexcept;
84  OTBGdalAdapters_EXPORT friend bool operator!=(const SpatialReference& sr1, const SpatialReference& sr2) noexcept;
85 
86 public:
87  typedef std::unique_ptr<OGRSpatialReference, internal::OGRSpatialReferenceDeleter> OGRSpatialReferencePtr;
100  static SpatialReference FromDescription(const std::string& sr_description);
101 
108 
117  static SpatialReference FromEPSG(unsigned int epsg);
118 
128  enum class hemisphere
129  {
130  north,
131  south
132  };
133 
134  static SpatialReference FromUTM(unsigned int zone, hemisphere hem);
135 
148  static SpatialReference FromGeogCS(const std::string& GeogName, const std::string& DatumName,
149  const std::string& SpheroidName, const double SemiMajor,
150  const double InvFlattening);
151 
153  SpatialReference(const SpatialReference& other) noexcept;
154 
156  SpatialReference& operator=(const SpatialReference& other) noexcept;
157 
162  std::string ToWkt() const;
163 
170 
175  unsigned int ToEPSG() const;
176 
177 #if GDAL_VERSION_NUM >= 3000000
182  void SetAxisMappingStrategy(OSRAxisMappingStrategy strategy);
183 #endif
184 
194  static void UTMFromGeoPoint(double lon, double lat, unsigned int& zone, hemisphere& hem);
195 
196 private:
198  SpatialReference(const OGRSpatialReference* ref);
199 
203 
204  // unique ptr to the internal OGRSpatialReference
206 };
207 
209 OTBGdalAdapters_EXPORT std::ostream& operator<<(std::ostream& o, const SpatialReference::hemisphere& hem);
210 
212 OTBGdalAdapters_EXPORT std::ostream& operator<<(std::ostream& o, const SpatialReference& i);
213 }
214 #endif
This class is a wrapper around OGRCoordinateTransformation.
This class is a wrapper around OGRSpatialReference.
OGRSpatialReferencePtr m_SR
SpatialReference(OGRSpatialReferencePtr ref)
SpatialReference(const OGRSpatialReference *ref)
Constructor from wrapped type. ref will be cloned.
static SpatialReference FromGeogCS(const std::string &GeogName, const std::string &DatumName, const std::string &SpheroidName, const double SemiMajor, const double InvFlattening)
Build a SpatialReference from the datum, ellipsoid, prime meridian and angular units.
static void UTMFromGeoPoint(double lon, double lat, unsigned int &zone, hemisphere &hem)
static SpatialReference FromWGS84()
SpatialReference & operator=(const SpatialReference &other) noexcept
Assignment operator.
OTBGdalAdapters_EXPORT friend bool operator!=(const SpatialReference &sr1, const SpatialReference &sr2) noexcept
Different operator (based on OGRSpatialReference::IsSame())
std::string ToWkt() const
static SpatialReference FromUTM(unsigned int zone, hemisphere hem)
SpatialReference(const SpatialReference &other) noexcept
Copy constructor.
static SpatialReference FromEPSG(unsigned int epsg)
static SpatialReference FromDescription(const std::string &sr_description)
OTBGdalAdapters_EXPORT friend bool operator==(const SpatialReference &sr1, const SpatialReference &sr2) noexcept
Equal operator (based on OGRSpatialReference::IsSame())
std::unique_ptr< OGRSpatialReference, internal::OGRSpatialReferenceDeleter > OGRSpatialReferencePtr
unsigned int ToEPSG() const
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
OTBCommon_EXPORT std::ostream & operator<<(std::ostream &os, const otb::StringToHTML &str)
constexpr bool operator==(extents< StaticExtentsL... > const &lhs, extents< StaticExtentsR... > const &rhs)
Definition: otbExtents.h:150
constexpr bool operator!=(extents< StaticExtentsL... > const &lhs, extents< StaticExtentsR... > const &rhs)
Definition: otbExtents.h:164
void operator()(OGRSpatialReference *del) const