Skip to content

Commit 49d378b

Browse files
committed
Add adaptor making boost::geometry work with our geometry classes
Adds dependency on boost::geometry.
1 parent 0e234ef commit 49d378b

File tree

3 files changed

+89
-2
lines changed

3 files changed

+89
-2
lines changed

.github/actions/win-install/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ runs:
55

66
steps:
77
- name: Install packages
8-
run: vcpkg install bzip2:x64-windows expat:x64-windows zlib:x64-windows proj4:x64-windows boost-system:x64-windows boost-filesystem:x64-windows boost-property-tree:x64-windows lua:x64-windows libpq:x64-windows
8+
run: vcpkg install bzip2:x64-windows expat:x64-windows zlib:x64-windows proj4:x64-windows boost-geometry:x64-windows boost-system:x64-windows boost-filesystem:x64-windows boost-property-tree:x64-windows lua:x64-windows libpq:x64-windows
99
shell: bash
1010

1111
- name: Install psycopg2 and beahve

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ Required libraries are
4848
* [proj](https://proj.org/)
4949
* [bzip2](http://www.bzip.org/)
5050
* [zlib](https://www.zlib.net/)
51-
* [Boost libraries](https://www.boost.org/), including system and filesystem
51+
* [Boost libraries](https://www.boost.org/), including geometry, system and
52+
filesystem
5253
* [PostgreSQL](https://www.postgresql.org/) client libraries
5354
* [Lua](https://www.lua.org/) (Optional, used for Lua tag transforms
5455
and the flex output)

src/geom-boost-adaptor.hpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#ifndef OSM2PGSQL_GEOM_BOOST_ADAPTOR_HPP
2+
#define OSM2PGSQL_GEOM_BOOST_ADAPTOR_HPP
3+
4+
/**
5+
* SPDX-License-Identifier: GPL-2.0-or-later
6+
*
7+
* This file is part of osm2pgsql (https://osm2pgsql.org/).
8+
*
9+
* Copyright (C) 2006-2022 by the osm2pgsql developer community.
10+
* For a full list of authors see the git log.
11+
*/
12+
13+
#include "geom.hpp"
14+
15+
#include <boost/geometry.hpp>
16+
#include <boost/geometry/geometries/register/linestring.hpp>
17+
#include <boost/geometry/geometries/register/multi_linestring.hpp>
18+
#include <boost/geometry/geometries/register/multi_point.hpp>
19+
#include <boost/geometry/geometries/register/multi_polygon.hpp>
20+
#include <boost/geometry/geometries/register/point.hpp>
21+
#include <boost/geometry/geometries/register/ring.hpp>
22+
23+
BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(geom::point_t, double, cs::cartesian,
24+
x, y, set_x, set_y)
25+
BOOST_GEOMETRY_REGISTER_LINESTRING(geom::linestring_t)
26+
BOOST_GEOMETRY_REGISTER_RING(geom::ring_t)
27+
28+
BOOST_GEOMETRY_REGISTER_MULTI_POINT(geom::multipoint_t)
29+
BOOST_GEOMETRY_REGISTER_MULTI_LINESTRING(geom::multilinestring_t)
30+
BOOST_GEOMETRY_REGISTER_MULTI_POLYGON(geom::multipolygon_t)
31+
32+
namespace boost {
33+
namespace geometry {
34+
namespace traits {
35+
template <>
36+
struct point_order<::geom::ring_t>
37+
{
38+
static const order_selector value = counterclockwise;
39+
};
40+
41+
template <>
42+
struct tag<::geom::polygon_t>
43+
{
44+
using type = polygon_tag;
45+
};
46+
template <>
47+
struct ring_const_type<::geom::polygon_t>
48+
{
49+
using type = ::geom::ring_t const &;
50+
};
51+
template <>
52+
struct ring_mutable_type<::geom::polygon_t>
53+
{
54+
using type = ::geom::ring_t &;
55+
};
56+
template <>
57+
struct interior_const_type<::geom::polygon_t>
58+
{
59+
using type = std::vector<::geom::ring_t> const;
60+
};
61+
template <>
62+
struct interior_mutable_type<::geom::polygon_t>
63+
{
64+
using type = std::vector<::geom::ring_t>;
65+
};
66+
67+
template <>
68+
struct exterior_ring<::geom::polygon_t>
69+
{
70+
// NOLINTNEXTLINE(google-runtime-references)
71+
static auto &get(::geom::polygon_t &p) { return p.outer(); }
72+
static auto &get(::geom::polygon_t const &p) { return p.outer(); }
73+
};
74+
75+
template <>
76+
struct interior_rings<::geom::polygon_t>
77+
{
78+
// NOLINTNEXTLINE(google-runtime-references)
79+
static auto get(::geom::polygon_t &p) { return p.inners(); }
80+
static auto get(::geom::polygon_t const &p) { return p.inners(); }
81+
};
82+
} // namespace traits
83+
} // namespace geometry
84+
} // namespace boost
85+
86+
#endif // OSM2PGSQL_GEOM_BOOST_ADAPTOR_HPP

0 commit comments

Comments
 (0)