8 #include <boost/algorithm/string/predicate.hpp>
12 std::unique_ptr<OGRCoordinateTransformation,
13 void(*)(OGRCoordinateTransformation*)>
15 const std::string& coord_sys_from,
const std::string& coord_sys_to) {
16 return createCoordTransf(
17 createSptRef(coord_sys_from), createSptRef(coord_sys_to));
21 if (!
field.isEmpty()) {
23 field.getField()->transform(
25 field.setRefPoint(
field.getField().getCellBorder(0).startPoint());
32 field.setCRS(coord_sys_to);
37 auto new_route =
route.clone();
39 for (
size_t i = 0; i < new_route.sizeVectorSwaths(); ++i) {
41 new_route.getSwaths(i),
field, coord_sys_to));
43 for (
size_t i = 0; i < new_route.sizeConnections(); ++i) {
45 new_route.getConnection(i),
field, coord_sys_to));
56 if (s_end.
len > 0.0) {
59 new_path.addState(s_end);
63 for (
auto&& s : new_path) {
64 s.point = s.point +
field.getRefPoint();
65 s.point->transform(coords.get());
67 for (
size_t i = 0; i < new_path.size() - 1; ++i) {
68 new_path[i].len = new_path[i].point.distance(new_path[i+1].point);
69 new_path[i].angle = (new_path[i+1].point - new_path[i].point).getAngleFromPoint();
82 abs_p->transform(coords.get());
98 for (
auto&& swath :
swaths) {
106 const std::string& coord_sys_from,
const std::string& coord_sys_to) {
114 const std::string& coord_sys_from,
const std::string& coord_sys_to) {
116 for (
auto&& strip : strips) {
117 new_strips.emplace_back(
124 const std::string& coord_sys_from,
const std::string& coord_sys_to) {
126 for (
auto&& swath :
swaths) {
134 const std::string& coord_sys_from,
const std::string& coord_sys_to) {
140 const std::string& coord_sys_from,
const std::string& coord_sys_to) {
141 auto new_path =
path;
143 for (
auto&& s : new_path) {
144 s.point->transform(coords.get());
150 std::string field_crs =
field.getCRS();
151 if (!field_crs.empty() && \
152 field_crs !=
"EPSG:4258" && field_crs !=
"EPSG:4326") {
154 if (is_etrs89_opt && \
155 (
field.getRefPoint().getX() < 32.88 && \
156 field.getRefPoint().getX() > -16.1 && \
157 field.getRefPoint().getY() < 84.73 && \
158 field.getRefPoint().getY() > 40.18) ) {
161 }
else if (field_crs.empty()) {
166 throw std::out_of_range(
167 "Error on transformToUTM: Coordinates are in a local system");
169 if (is_etrs89_opt && \
170 (
field.getRefPoint().getX() < 32.88 && \
171 field.getRefPoint().getX() > -16.1 && \
172 field.getRefPoint().getY() < 84.73 && \
173 field.getRefPoint().getY() > 40.18) ) {
174 field.setCRS(
"EPSG:4258");
175 }
else if (
field.getRefPoint().getX() < 180. && \
176 field.getRefPoint().getX() > -180. && \
177 field.getRefPoint().getY() < 90. && \
178 field.getRefPoint().getY() > -90.) {
179 field.setCRS(
"EPSG:4326");
181 throw std::invalid_argument(
182 "Error on transformToUTM: Coordinates local system was not recognized");
184 field_crs =
field.getCRS();
187 std::string utm_zone = std::string(
"UTM:") +
\
189 floor((
field.getRefPoint().getX() + 180) / 6) + 1)) + \
190 (
field.getRefPoint().getY() > 0 ?
"N" :
"S") + \
191 " datum:" + (
field.getCRS() ==
"EPSG:4258" ?
"ETRS89" :
"WGS84");
193 field.setPrevCRS(field_crs);
198 if (
field.getPrevCRS().empty()) {
199 throw std::invalid_argument(
200 "Error in Transform::transformToUTM. No previous CRS recorded.");
236 auto point =
field.getRefPoint();
241 std::unique_ptr<OGRSpatialReference, void(*)(OGRSpatialReference*)>
243 const std::string& coord_sys,
bool fail_silently) {
245 std::unique_ptr<OGRSpatialReference, void(*)(OGRSpatialReference*)>(
246 new OGRSpatialReference(), [](OGRSpatialReference* ref) {
247 OGRSpatialReference::DestroySpatialReference(ref);});
248 if (coord_sys.empty() && !fail_silently) {
249 throw std::invalid_argument(
"Coordinate system empty");
257 " +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +type=crs" :
259 +
" +units=m +no_defs ");
260 spt_ref->importFromProj4(proj.c_str());
261 }
else if (!fail_silently) {
262 throw std::invalid_argument(
"Coordinate system not recognized");
264 if (GDALVersionInfo(
"VERSION_NUM")[0] ==
'3') {
266 spt_ref->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
272 std::unique_ptr<OGRCoordinateTransformation,
274 std::unique_ptr<OGRSpatialReference,
void(*)(OGRSpatialReference*)> in,
275 std::unique_ptr<OGRSpatialReference,
void(*)(OGRSpatialReference*)> out) {
276 return std::unique_ptr<OGRCoordinateTransformation,
277 void(*)(OGRCoordinateTransformation*)>(
278 OGRCreateCoordinateTransformation(in.get(), out.get()),
279 [](OGRCoordinateTransformation* coord) {
280 OGRCoordinateTransformation::DestroyCT(coord);});