Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/command-line-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "logging.hpp"
#include "options.hpp"
#include "pgsql.hpp"
#include "projection.hpp"
#include "reprojection.hpp"
#include "util.hpp"
#include "version.hpp"
Expand Down Expand Up @@ -244,7 +245,7 @@ void check_options_expire(options_t *options) {
}

if (options->expire_tiles_zoom != 0 &&
options->projection->target_srs() != 3857) {
options->projection->target_srs() != PROJ_SPHERE_MERC) {
log_warn("Expire has been enabled (with -e or --expire-tiles) but "
"target SRS is not Mercator (EPSG:3857). Expire disabled!");
options->expire_tiles_zoom = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/expire-tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "format.hpp"
#include "geom-functions.hpp"
#include "options.hpp"
#include "projection.hpp"
#include "reprojection.hpp"
#include "table.hpp"
#include "tile.hpp"
Expand Down Expand Up @@ -146,7 +147,7 @@ void expire_tiles::from_geometry(geom::geometry_t const &geom,
void expire_tiles::from_geometry_if_3857(geom::geometry_t const &geom,
expire_config_t const &expire_config)
{
if (geom.srid() == 3857) {
if (geom.srid() == PROJ_SPHERE_MERC) {
from_geometry(geom, expire_config);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/flex-lua-geom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "geom-functions.hpp"
#include "geom-pole-of-inaccessibility.hpp"
#include "lua-utils.hpp"
#include "projection.hpp"

#include <lua.hpp>

Expand Down Expand Up @@ -73,7 +74,7 @@ int geom_spherical_area(lua_State *lua_state)
{
auto const *const input_geometry = unpack_geometry(lua_state);

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

try {
if (input_geometry->srid() != 4326) {
if (input_geometry->srid() != PROJ_LATLONG) {
throw std::runtime_error{
"Can not transform already transformed geometry."};
}
Expand Down
3 changes: 2 additions & 1 deletion src/flex-lua-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "lua-utils.hpp"
#include "output-flex.hpp"
#include "pgsql-capabilities.hpp"
#include "projection.hpp"
#include "util.hpp"

#include <lua.hpp>
Expand Down Expand Up @@ -219,7 +220,7 @@ void parse_and_set_expire_options(lua_State *lua_state,
return;
}

if (!column->is_geometry_column() || column->srid() != 3857) {
if (!column->is_geometry_column() || column->srid() != PROJ_SPHERE_MERC) {
throw std::runtime_error{"Expire only allowed for geometry"
" columns in Web Mercator projection."};
}
Expand Down
7 changes: 4 additions & 3 deletions src/flex-table-column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "format.hpp"
#include "pgsql-capabilities.hpp"
#include "projection.hpp"
#include "util.hpp"

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

if (proj == "merc" || proj == "mercator") {
m_srid = 3857;
m_srid = PROJ_SPHERE_MERC;
return;
}

if (proj == "latlong" || proj == "latlon" || proj == "wgs84") {
m_srid = 4326;
m_srid = PROJ_LATLONG;
return;
}

Expand Down Expand Up @@ -197,7 +198,7 @@ std::string flex_table_column_t::sql_create() const
void flex_table_column_t::add_expire(expire_config_t const &config)
{
assert(is_geometry_column());
assert(srid() == 3857);
assert(srid() == PROJ_SPHERE_MERC);
m_expires.push_back(config);
}

Expand Down
5 changes: 3 additions & 2 deletions src/flex-table-column.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "expire-config.hpp"
#include "expire-tiles.hpp"
#include "geom.hpp"
#include "projection.hpp"

#include <cassert>
#include <cstdint>
Expand Down Expand Up @@ -99,7 +100,7 @@ class flex_table_column_t
bool needs_isvalid() const noexcept
{
assert(is_geometry_column());
return !m_create_only && m_srid != 4326 &&
return !m_create_only && m_srid != PROJ_LATLONG &&
m_type != table_column_type::point;
}

Expand Down Expand Up @@ -158,7 +159,7 @@ class flex_table_column_t
/**
* For geometry columns only: The projection SRID. Default is web mercator.
*/
int m_srid = 3857;
int m_srid = PROJ_SPHERE_MERC;

/// NOT NULL constraint
bool m_not_null = false;
Expand Down
3 changes: 2 additions & 1 deletion src/flex-table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "flex-index.hpp"
#include "flex-table-column.hpp"
#include "pgsql.hpp"
#include "projection.hpp"
#include "reprojection.hpp"
#include "thread-pool.hpp"
#include "util.hpp"
Expand Down Expand Up @@ -145,7 +146,7 @@ class flex_table_t

int srid() const noexcept
{
return has_geom_column() ? geom_column().srid() : 4326;
return has_geom_column() ? geom_column().srid() : PROJ_LATLONG;
}

std::string build_sql_prepare_get_wkb() const;
Expand Down
3 changes: 2 additions & 1 deletion src/gen/gen-rivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "logging.hpp"
#include "params.hpp"
#include "pgsql.hpp"
#include "projection.hpp"
#include "util.hpp"
#include "wkb.hpp"

Expand Down Expand Up @@ -341,7 +342,7 @@ SELECT "{id_column}", "{width_column}", "{name_column}", "{geom_column}"
timer(m_timer_write).start();
connection().exec("BEGIN");
for (auto &edge : edges) {
geom::geometry_t const geom{std::move(edge.points), 3857};
geom::geometry_t const geom{std::move(edge.points), PROJ_SPHERE_MERC};
auto const wkb = geom_to_ewkb(geom);
connection().exec_prepared("ins", edge.id, edge.width,
get_name(names, edge.id), binary_param(wkb));
Expand Down
4 changes: 3 additions & 1 deletion src/gen/raster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* For a full list of authors see the git log.
*/

#include "projection.hpp"

#include <cstdint>
#include <string>

Expand Down Expand Up @@ -41,7 +43,7 @@ struct wkb_raster_header
double ipY = 0.0;
double skewX = 0.0;
double skewY = 0.0;
int32_t srid = 3857;
int32_t srid = PROJ_SPHERE_MERC;
uint16_t width = 0;
uint16_t height = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion src/gen/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "canvas.hpp"
#include "geom-boost-adaptor.hpp"
#include "projection.hpp"
#include "tile.hpp"

#include <cassert>
Expand Down Expand Up @@ -114,7 +115,7 @@ tracer_t::build_geometries(tile_t const &tile, potrace_path_t const *plist,
m_num_points += ring.size();

if (path->sign == '+') {
geometries.emplace_back(geom::polygon_t{}, 3857)
geometries.emplace_back(geom::polygon_t{}, PROJ_SPHERE_MERC)
.get<geom::polygon_t>()
.outer() = std::move(ring);
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/geom-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "geom-boost-adaptor.hpp"
#include "overloaded.hpp"
#include "projection.hpp"

#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -228,7 +229,7 @@ class transform_visitor
void transform(geometry_t *output, geometry_t const &input,
reprojection const &reprojection)
{
assert(input.srid() == 4326);
assert(input.srid() == PROJ_LATLONG);

set_to_same_type(output, input);
output->set_srid(reprojection.target_srs());
Expand Down Expand Up @@ -385,7 +386,7 @@ double spherical_area(polygon_t const &geom)

double spherical_area(geometry_t const &geom)
{
assert(geom.srid() == 4326);
assert(geom.srid() == PROJ_LATLONG);

return std::abs(geom.visit(overloaded{
[&](geom::nullgeom_t const & /*input*/) { return 0.0; },
Expand Down
20 changes: 12 additions & 8 deletions src/geom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Basic geometry types and functions.
*/

#include "projection.hpp"

#include <osmium/osm/location.hpp>

#include <algorithm>
Expand Down Expand Up @@ -274,31 +276,33 @@ class geometry_t

// point_t is small and trivially copyable, no move needed like for the
// other constructors.
constexpr explicit geometry_t(point_t geom, int srid = 4326)
constexpr explicit geometry_t(point_t geom, int srid = PROJ_LATLONG)
: m_geom(geom), m_srid(srid)
{}

constexpr explicit geometry_t(linestring_t &&geom, int srid = 4326)
constexpr explicit geometry_t(linestring_t &&geom, int srid = PROJ_LATLONG)
: m_geom(std::move(geom)), m_srid(srid)
{}

constexpr explicit geometry_t(polygon_t &&geom, int srid = 4326)
constexpr explicit geometry_t(polygon_t &&geom, int srid = PROJ_LATLONG)
: m_geom(std::move(geom)), m_srid(srid)
{}

constexpr explicit geometry_t(multipoint_t &&geom, int srid = 4326)
constexpr explicit geometry_t(multipoint_t &&geom, int srid = PROJ_LATLONG)
: m_geom(std::move(geom)), m_srid(srid)
{}

constexpr explicit geometry_t(multilinestring_t &&geom, int srid = 4326)
constexpr explicit geometry_t(multilinestring_t &&geom,
int srid = PROJ_LATLONG)
: m_geom(std::move(geom)), m_srid(srid)
{}

constexpr explicit geometry_t(multipolygon_t &&geom, int srid = 4326)
constexpr explicit geometry_t(multipolygon_t &&geom,
int srid = PROJ_LATLONG)
: m_geom(std::move(geom)), m_srid(srid)
{}

constexpr explicit geometry_t(collection_t &&geom, int srid = 4326)
constexpr explicit geometry_t(collection_t &&geom, int srid = PROJ_LATLONG)
: m_geom(std::move(geom)), m_srid(srid)
{}

Expand Down Expand Up @@ -397,7 +401,7 @@ class geometry_t
multilinestring_t, multipolygon_t, collection_t>
m_geom = nullgeom_t{};

int m_srid = 4326;
int m_srid = PROJ_LATLONG;

}; // class geometry_t

Expand Down
3 changes: 2 additions & 1 deletion src/locator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "overloaded.hpp"
#include "pgsql-capabilities.hpp"
#include "pgsql.hpp"
#include "projection.hpp"
#include "wkb.hpp"

#include <iterator>
Expand Down Expand Up @@ -63,7 +64,7 @@ void locator_t::add_regions(pg_conn_t const &db_connection,
std::string const name = result.get_value(n, 0);
auto geometry = ewkb_to_geom(util::decode_hex(result.get(n, 1)));

if (geometry.srid() == 4326) {
if (geometry.srid() == PROJ_LATLONG) {
add_region(name, geometry);
} else {
log_warn("Ignoring locator geometry that is not in WGS84 (4326)");
Expand Down
14 changes: 9 additions & 5 deletions src/output-flex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "osmtypes.hpp"
#include "pgsql-capabilities.hpp"
#include "pgsql.hpp"
#include "projection.hpp"
#include "properties.hpp"
#include "reprojection.hpp"
#include "thread-pool.hpp"
Expand Down Expand Up @@ -1191,8 +1192,9 @@ output_flex_t::output_flex_t(output_flex_t const *other,
}

for (auto &expire_output : *m_expire_outputs) {
m_expire_tiles.emplace_back(expire_output.maxzoom(),
reprojection::create_projection(3857));
m_expire_tiles.emplace_back(
expire_output.maxzoom(),
reprojection::create_projection(PROJ_SPHERE_MERC));
}
}

Expand Down Expand Up @@ -1235,7 +1237,8 @@ output_flex_t::output_flex_t(std::shared_ptr<middle_query_t> const &mid,
eo.set_maxzoom(options.expire_tiles_zoom);

for (auto &table : *m_tables) {
if (table.has_geom_column() && table.geom_column().srid() == 3857) {
if (table.has_geom_column() &&
table.geom_column().srid() == PROJ_SPHERE_MERC) {
expire_config_t config{};
config.expire_output = m_expire_outputs->size() - 1;
if (options.expire_tiles_max_bbox > 0.0) {
Expand All @@ -1255,8 +1258,9 @@ output_flex_t::output_flex_t(std::shared_ptr<middle_query_t> const &mid,
}

for (auto &expire_output : *m_expire_outputs) {
m_expire_tiles.emplace_back(expire_output.maxzoom(),
reprojection::create_projection(3857));
m_expire_tiles.emplace_back(
expire_output.maxzoom(),
reprojection::create_projection(PROJ_SPHERE_MERC));
}

create_expire_tables(*m_expire_outputs, get_options()->connection_params);
Expand Down
3 changes: 2 additions & 1 deletion src/output-pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "osmtypes.hpp"
#include "output-pgsql.hpp"
#include "pgsql.hpp"
#include "projection.hpp"
#include "reprojection.hpp"
#include "taginfo-impl.hpp"
#include "tagtransform.hpp"
Expand All @@ -51,7 +52,7 @@ double calculate_area(bool reproject_area, geom::geometry_t const &geom4326,
geom::geometry_t const &projected_geom)
{
static thread_local auto const proj3857 =
reprojection::create_projection(3857);
reprojection::create_projection(PROJ_SPHERE_MERC);

if (reproject_area) {
auto const ogeom = geom::transform(geom4326, *proj3857);
Expand Down
16 changes: 16 additions & 0 deletions src/projection.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef OSM2PGSQL_PROJECTION_HPP
#define OSM2PGSQL_PROJECTION_HPP

/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2025 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/

constexpr int PROJ_LATLONG = 4326;
constexpr int PROJ_SPHERE_MERC = 3857;

#endif // OSM2PGSQL_PROJECTION_HPP
7 changes: 1 addition & 6 deletions src/reprojection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@
*/

#include "geom.hpp"
#include "projection.hpp"

#include <memory>
#include <string>

enum Projection
{
PROJ_LATLONG = 4326,
PROJ_SPHERE_MERC = 3857
};

/**
* Virtual base class used for projecting OSM WGS84 coordinates into a
* different coordinate system. Most commonly this will be used to convert
Expand Down
Loading