forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreprojection.cpp
More file actions
91 lines (74 loc) · 2.26 KB
/
Copy pathreprojection.cpp
File metadata and controls
91 lines (74 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2021 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include <osmium/geom/mercator_projection.hpp>
#include "format.hpp"
#include "reprojection.hpp"
namespace {
osmium::geom::Coordinates lonlat2merc(osmium::geom::Coordinates coords)
{
if (coords.y > 89.99) {
coords.y = 89.99;
} else if (coords.y < -89.99) {
coords.y = -89.99;
}
return osmium::geom::lonlat_to_mercator(coords);
}
class latlon_reprojection_t : public reprojection
{
public:
osmium::geom::Coordinates reproject(osmium::Location loc) const
noexcept override
{
return osmium::geom::Coordinates{loc.lon_without_check(),
loc.lat_without_check()};
}
osmium::geom::Coordinates target_to_tile(osmium::geom::Coordinates c) const
noexcept override
{
return lonlat2merc(c);
}
int target_srs() const noexcept override { return PROJ_LATLONG; }
char const *target_desc() const noexcept override { return "Latlong"; }
};
class merc_reprojection_t : public reprojection
{
public:
osmium::geom::Coordinates reproject(osmium::Location loc) const override
{
osmium::geom::Coordinates const coords{loc.lon_without_check(),
loc.lat_without_check()};
return lonlat2merc(coords);
}
osmium::geom::Coordinates target_to_tile(osmium::geom::Coordinates c) const
noexcept override
{
return c;
}
int target_srs() const noexcept override { return PROJ_SPHERE_MERC; }
char const *target_desc() const noexcept override
{
return "Spherical Mercator";
}
};
} // anonymous namespace
std::shared_ptr<reprojection> reprojection::create_projection(int srs)
{
switch (srs) {
case PROJ_LATLONG:
return std::make_shared<latlon_reprojection_t>();
case PROJ_SPHERE_MERC:
return std::make_shared<merc_reprojection_t>();
default:
break;
}
if (srs <= 0) {
throw std::runtime_error{"Invalid projection SRID '{}'."_format(srs)};
}
return make_generic_projection(srs);
}