Skip to content

Commit 944c086

Browse files
committed
Use symbolic names for projections
1 parent 3c7d0e2 commit 944c086

22 files changed

+99
-62
lines changed

contrib/libosmium/include/osmium/geom/factory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ namespace osmium {
133133
}
134134

135135
static int epsg() noexcept {
136-
return 4326;
136+
return PROJ_LATLON;
137137
}
138138

139139
static std::string proj_string() noexcept {

src/command-line-parser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "logging.hpp"
1515
#include "options.hpp"
1616
#include "pgsql.hpp"
17+
#include "projection.hpp"
1718
#include "reprojection.hpp"
1819
#include "util.hpp"
1920
#include "version.hpp"
@@ -244,7 +245,7 @@ void check_options_expire(options_t *options) {
244245
}
245246

246247
if (options->expire_tiles_zoom != 0 &&
247-
options->projection->target_srs() != 3857) {
248+
options->projection->target_srs() != PROJ_SPHERE_MERC) {
248249
log_warn("Expire has been enabled (with -e or --expire-tiles) but "
249250
"target SRS is not Mercator (EPSG:3857). Expire disabled!");
250251
options->expire_tiles_zoom = 0;

src/expire-tiles.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "format.hpp"
2929
#include "geom-functions.hpp"
3030
#include "options.hpp"
31+
#include "projection.hpp"
3132
#include "reprojection.hpp"
3233
#include "table.hpp"
3334
#include "tile.hpp"
@@ -146,7 +147,7 @@ void expire_tiles::from_geometry(geom::geometry_t const &geom,
146147
void expire_tiles::from_geometry_if_3857(geom::geometry_t const &geom,
147148
expire_config_t const &expire_config)
148149
{
149-
if (geom.srid() == 3857) {
150+
if (geom.srid() == PROJ_SPHERE_MERC) {
150151
from_geometry(geom, expire_config);
151152
}
152153
}

src/flex-lua-geom.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "geom-functions.hpp"
1313
#include "geom-pole-of-inaccessibility.hpp"
1414
#include "lua-utils.hpp"
15+
#include "projection.hpp"
1516

1617
#include <lua.hpp>
1718

@@ -73,7 +74,7 @@ int geom_spherical_area(lua_State *lua_state)
7374
{
7475
auto const *const input_geometry = unpack_geometry(lua_state);
7576

76-
if (input_geometry->srid() != 4326) {
77+
if (input_geometry->srid() != PROJ_LATLONG) {
7778
throw std::runtime_error{"Can only calculate spherical area for "
7879
"geometries in WGS84 (4326) coordinates."};
7980
}
@@ -282,7 +283,7 @@ int geom_transform(lua_State *lua_state)
282283
auto const srid = static_cast<int>(luaL_checkinteger(lua_state, 2));
283284

284285
try {
285-
if (input_geometry->srid() != 4326) {
286+
if (input_geometry->srid() != PROJ_LATLONG) {
286287
throw std::runtime_error{
287288
"Can not transform already transformed geometry."};
288289
}

src/flex-lua-table.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "lua-utils.hpp"
1717
#include "output-flex.hpp"
1818
#include "pgsql-capabilities.hpp"
19+
#include "projection.hpp"
1920
#include "util.hpp"
2021

2122
#include <lua.hpp>
@@ -219,7 +220,7 @@ void parse_and_set_expire_options(lua_State *lua_state,
219220
return;
220221
}
221222

222-
if (!column->is_geometry_column() || column->srid() != 3857) {
223+
if (!column->is_geometry_column() || column->srid() != PROJ_SPHERE_MERC) {
223224
throw std::runtime_error{"Expire only allowed for geometry"
224225
" columns in Web Mercator projection."};
225226
}

src/flex-table-column.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "format.hpp"
1313
#include "pgsql-capabilities.hpp"
14+
#include "projection.hpp"
1415
#include "util.hpp"
1516

1617
#include <cassert>
@@ -105,12 +106,12 @@ void flex_table_column_t::set_projection(char const *projection)
105106
auto const proj = lowercase(projection);
106107

107108
if (proj == "merc" || proj == "mercator") {
108-
m_srid = 3857;
109+
m_srid = PROJ_SPHERE_MERC;
109110
return;
110111
}
111112

112113
if (proj == "latlong" || proj == "latlon" || proj == "wgs84") {
113-
m_srid = 4326;
114+
m_srid = PROJ_LATLONG;
114115
return;
115116
}
116117

@@ -197,7 +198,7 @@ std::string flex_table_column_t::sql_create() const
197198
void flex_table_column_t::add_expire(expire_config_t const &config)
198199
{
199200
assert(is_geometry_column());
200-
assert(srid() == 3857);
201+
assert(srid() == PROJ_SPHERE_MERC);
201202
m_expires.push_back(config);
202203
}
203204

src/flex-table-column.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "expire-config.hpp"
1414
#include "expire-tiles.hpp"
1515
#include "geom.hpp"
16+
#include "projection.hpp"
1617

1718
#include <cassert>
1819
#include <cstdint>
@@ -99,7 +100,7 @@ class flex_table_column_t
99100
bool needs_isvalid() const noexcept
100101
{
101102
assert(is_geometry_column());
102-
return !m_create_only && m_srid != 4326 &&
103+
return !m_create_only && m_srid != PROJ_LATLONG &&
103104
m_type != table_column_type::point;
104105
}
105106

@@ -158,7 +159,7 @@ class flex_table_column_t
158159
/**
159160
* For geometry columns only: The projection SRID. Default is web mercator.
160161
*/
161-
int m_srid = 3857;
162+
int m_srid = PROJ_SPHERE_MERC;
162163

163164
/// NOT NULL constraint
164165
bool m_not_null = false;

src/flex-table.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "flex-index.hpp"
1515
#include "flex-table-column.hpp"
1616
#include "pgsql.hpp"
17+
#include "projection.hpp"
1718
#include "reprojection.hpp"
1819
#include "thread-pool.hpp"
1920
#include "util.hpp"
@@ -145,7 +146,7 @@ class flex_table_t
145146

146147
int srid() const noexcept
147148
{
148-
return has_geom_column() ? geom_column().srid() : 4326;
149+
return has_geom_column() ? geom_column().srid() : PROJ_LATLONG;
149150
}
150151

151152
std::string build_sql_prepare_get_wkb() const;

src/gen/gen-rivers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "logging.hpp"
1515
#include "params.hpp"
1616
#include "pgsql.hpp"
17+
#include "projection.hpp"
1718
#include "util.hpp"
1819
#include "wkb.hpp"
1920

@@ -341,7 +342,7 @@ SELECT "{id_column}", "{width_column}", "{name_column}", "{geom_column}"
341342
timer(m_timer_write).start();
342343
connection().exec("BEGIN");
343344
for (auto &edge : edges) {
344-
geom::geometry_t const geom{std::move(edge.points), 3857};
345+
geom::geometry_t const geom{std::move(edge.points), PROJ_SPHERE_MERC};
345346
auto const wkb = geom_to_ewkb(geom);
346347
connection().exec_prepared("ins", edge.id, edge.width,
347348
get_name(names, edge.id), binary_param(wkb));

src/gen/raster.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* For a full list of authors see the git log.
1111
*/
1212

13+
#include "projection.hpp"
14+
1315
#include <cstdint>
1416
#include <string>
1517

@@ -41,7 +43,7 @@ struct wkb_raster_header
4143
double ipY = 0.0;
4244
double skewX = 0.0;
4345
double skewY = 0.0;
44-
int32_t srid = 3857;
46+
int32_t srid = PROJ_SPHERE_MERC;
4547
uint16_t width = 0;
4648
uint16_t height = 0;
4749
};

0 commit comments

Comments
 (0)