OTB  9.0.0
Orfeo Toolbox
otbSpatialReference.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 <memory>
26 #include <string>
27 
28 #if defined(_MSC_VER)
29 #pragma warning(disable : 4251)
30 // Disable following warning :
31 // warning C4251: 'otb::SpatialReference::m_SR':
32 // class 'std::unique_ptr<OGRSpatialReference,OGRSpatialReferenceDeleter>' needs
33 // to have dll-interface to be used by clients of class 'otb::SpatialReference'
34 // As long as otb::SpatialReference::m_SR is private no need to export this type.
35 #endif
36 
37 // causes warning C4251 on Windows
38 #include "ogr_spatialref.h"
39 
40 class OGRSpatialReference;
41 
42 namespace otb
43 {
44 // Destructor of OGRSpatialReference
45 namespace internal
46 {
47 struct OTBGdalAdapters_EXPORT OGRSpatialReferenceDeleter
48 {
49 public:
50  void operator()(OGRSpatialReference* del) const;
51 };
52 }
53 
54 // Forward declaration needed for the operators declared bellow.
55 class SpatialReference;
56 
58 OTBGdalAdapters_EXPORT bool operator==(const SpatialReference& sr1, const SpatialReference& sr2) noexcept;
59 
61 OTBGdalAdapters_EXPORT bool operator!=(const SpatialReference& sr1, const SpatialReference& sr2) noexcept;
62 
79 class OTBGdalAdapters_EXPORT SpatialReference
80 {
82  OTBGdalAdapters_EXPORT friend bool operator==(const SpatialReference& sr1, const SpatialReference& sr2) noexcept;
83  OTBGdalAdapters_EXPORT friend bool operator!=(const SpatialReference& sr1, const SpatialReference& sr2) noexcept;
84 
85 public:
86  typedef std::unique_ptr<OGRSpatialReference, internal::OGRSpatialReferenceDeleter> OGRSpatialReferencePtr;
99  static SpatialReference FromDescription(const std::string& sr_description);
100 
106  static SpatialReference FromWGS84();
107 
116  static SpatialReference FromEPSG(unsigned int epsg);
117 
127  enum class hemisphere
128  {
129  north,
130  south
131  };
132 
133  static SpatialReference FromUTM(unsigned int zone, hemisphere hem);
134 
147  static SpatialReference FromGeogCS(const std::string& GeogName, const std::string& DatumName,
148  const std::string& SpheroidName, const double SemiMajor,
149  const double InvFlattening);
150 
152  SpatialReference(const SpatialReference& other) noexcept;
153 
155  SpatialReference& operator=(const SpatialReference& other) noexcept;
156 
161  std::string ToWkt() const;
162 
168  bool NormalizeESRI();
169 
174  unsigned int ToEPSG() const;
175 
176 #if GDAL_VERSION_NUM >= 3000000
177 
181  void SetAxisMappingStrategy(OSRAxisMappingStrategy strategy);
182 #endif
183 
193  static void UTMFromGeoPoint(double lon, double lat, unsigned int& zone, hemisphere& hem);
194 
195 private:
197  SpatialReference(const OGRSpatialReference* ref);
198 
201  SpatialReference(OGRSpatialReferencePtr ref);
202 
203  // unique ptr to the internal OGRSpatialReference
205 };
206 
208 OTBGdalAdapters_EXPORT std::ostream& operator<<(std::ostream& o, const SpatialReference::hemisphere& hem);
209 
211 OTBGdalAdapters_EXPORT std::ostream& operator<<(std::ostream& o, const SpatialReference& i);
212 }
213 #endif
otb::CoordinateTransformation
This class is a wrapper around OGRCoordinateTransformation.
Definition: otbCoordinateTransformation.h:77
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::SpatialReference
This class is a wrapper around OGRSpatialReference.
Definition: otbSpatialReference.h:79
otb::operator==
constexpr bool operator==(extents< StaticExtentsL... > const &lhs, extents< StaticExtentsR... > const &rhs)
Definition: otbExtents.h:150
otb::internal::OGRSpatialReferenceDeleter
Definition: otbSpatialReference.h:47
otb::SpatialReference::m_SR
OGRSpatialReferencePtr m_SR
Definition: otbSpatialReference.h:204
otb::SpatialReference::OGRSpatialReferencePtr
std::unique_ptr< OGRSpatialReference, internal::OGRSpatialReferenceDeleter > OGRSpatialReferencePtr
Definition: otbSpatialReference.h:86
otb::operator!=
constexpr bool operator!=(extents< StaticExtentsL... > const &lhs, extents< StaticExtentsR... > const &rhs)
Definition: otbExtents.h:164
otb::operator<<
OTBCommon_EXPORT std::ostream & operator<<(std::ostream &os, const otb::StringToHTML &str)
otb::SpatialReference::hemisphere
hemisphere
Definition: otbSpatialReference.h:127