OTB  7.2.0
Orfeo Toolbox
otbGenericMapProjection.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2020 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 
21 #ifndef otbGenericMapProjection_hxx
22 #define otbGenericMapProjection_hxx
23 
25 #include "otbMacro.h"
26 
27 namespace otb
28 {
29 
30 template <TransformDirection::TransformationDirection TDirectionOfMapping, class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
32  : Superclass(ParametersDimension), m_MapProjection()
33 {
34 }
35 
36 template <TransformDirection::TransformationDirection TDirectionOfMapping, class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
38 {
39 }
40 
41 template <TransformDirection::TransformationDirection TDirectionOfMapping, class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
43 {
44  if (m_MapProjection)
45  {
46  // Use partial template specialisation instead ?
48  {
49  return m_MapProjection->GetTargetSpatialReference().ToWkt();
50  }
51  else
52  {
53  return m_MapProjection->GetSourceSpatialReference().ToWkt();
54  }
55  }
56  return "";
57 }
58 
59 template <TransformDirection::TransformationDirection TDirectionOfMapping, class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
61 {
63  SpatialReference wktSpatialReference = SpatialReference::FromDescription(projectionRefWkt);
64 
65 #if GDAL_VERSION_NUM >= 3000000
66  wgs84.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
67  wktSpatialReference.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
68 #endif
69 
71  {
72  std::unique_ptr<CoordinateTransformation> newMapProjection(new CoordinateTransformation(wktSpatialReference, wgs84));
73 
74  if (newMapProjection)
75  m_MapProjection.swap(newMapProjection);
76  }
77  else
78  {
79  std::unique_ptr<CoordinateTransformation> newMapProjection(new CoordinateTransformation(wgs84, wktSpatialReference));
80 
81  if (newMapProjection)
82  m_MapProjection.swap(newMapProjection);
83  }
84 
85  this->Modified();
86 }
87 
88 template <TransformDirection::TransformationDirection TDirectionOfMapping, class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
91 {
92  OutputPointType outputPoint;
93 
94  // Can be collapsed
96  {
97  double lon, lat, h;
98  double z = 0.0;
99  if (InputPointType::PointDimension == 3)
100  z = point[2];
101 
102  std::tie(lon, lat, h) = m_MapProjection->Transform(std::make_tuple(point[0], point[1], z));
103 
104  outputPoint[0] = lon;
105  outputPoint[1] = lat;
106  if (OutputPointType::PointDimension == 3)
107  outputPoint[2] = h;
108  }
110  {
111 
112  double x, y, z;
113  double h = 0.0;
114  if (InputPointType::PointDimension == 3)
115  h = point[2];
116  std::tie(x, y, z) = m_MapProjection->Transform(std::make_tuple(point[0], point[1], h));
117  outputPoint[0] = x;
118  outputPoint[1] = y;
119  if (OutputPointType::PointDimension == 3)
120  outputPoint[2] = z;
121  }
122 
123  return outputPoint;
124 }
125 
126 
127 template <TransformDirection::TransformationDirection TDirectionOfMapping, class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
129 {
130  return m_MapProjection != nullptr;
131 }
132 
133 template <TransformDirection::TransformationDirection TDirectionOfMapping, class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
135 {
136  Superclass::PrintSelf(os, indent);
137  os << indent << *m_MapProjection.get() << std::endl;
138 }
139 
140 } // namespace otb
141 
142 #endif
itk::Point< ScalarType, NOutputDimensions > OutputPointType
itk::Point< ScalarType, NInputDimensions > InputPointType
This class is a wrapper around OGRCoordinateTransformation.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
static SpatialReference FromDescription(const std::string &sr_description)
static const TransformDirection::TransformationDirection DirectionOfMapping
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbTransform.h:241
static SpatialReference FromWGS84()
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
This class is a wrapper around OGRSpatialReference.
std::unique_ptr< CoordinateTransformation > m_MapProjection
OutputPointType TransformPoint(const InputPointType &point) const override
virtual void SetWkt(const std::string &projectionRefWkt)
Class to overload method passed to virtual pure in ITK V4.
Definition: otbTransform.h:39