forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreprojection-generic-proj4.cpp
More file actions
72 lines (56 loc) · 2.04 KB
/
Copy pathreprojection-generic-proj4.cpp
File metadata and controls
72 lines (56 loc) · 2.04 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
/**
* 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 "format.hpp"
#include "reprojection.hpp"
#include <osmium/geom/projection.hpp>
namespace {
/**
* Generic projection using proj library.
*/
class generic_reprojection_t : public reprojection
{
public:
explicit generic_reprojection_t(int srs) : m_target_srs(srs), pj_target(srs)
{}
osmium::geom::Coordinates reproject(osmium::Location loc) const override
{
double const lon = osmium::geom::deg_to_rad(loc.lon_without_check());
double const lat = osmium::geom::deg_to_rad(loc.lat_without_check());
return osmium::geom::transform(pj_source, pj_target,
osmium::geom::Coordinates{lon, lat});
}
osmium::geom::Coordinates
target_to_tile(osmium::geom::Coordinates coords) const override
{
return osmium::geom::transform(pj_target, pj_tile, coords);
}
int target_srs() const noexcept override { return m_target_srs; }
char const *target_desc() const noexcept override
{
return pj_get_def(pj_target.get(), 0);
}
private:
int m_target_srs;
osmium::geom::CRS pj_target;
/// The projection of the source data. Always lat/lon (EPSG:4326).
osmium::geom::CRS pj_source{PROJ_LATLONG};
/**
* The projection used for tiles. Currently this is fixed to be Spherical
* Mercator. You will usually have tiles in the same projection as used
* for PostGIS, but it is theoretically possible to have your PostGIS data
* in, say, lat/lon but still create tiles in Spherical Mercator.
*/
osmium::geom::CRS pj_tile{PROJ_SPHERE_MERC};
};
} // anonymous namespace
std::shared_ptr<reprojection> reprojection::make_generic_projection(int srs)
{
return std::make_shared<generic_reprojection_t>(srs);
}
std::string get_proj_version() { return "[API 4] {}"_format(pj_get_release()); }