1#ifndef OSMIUM_GEOM_OGR_HPP
2#define OSMIUM_GEOM_OGR_HPP
48#include <ogr_geometry.h>
61 class OGRFactoryImpl {
65 using point_type = std::unique_ptr<OGRPoint>;
66 using linestring_type = std::unique_ptr<OGRLineString>;
67 using polygon_type = std::unique_ptr<OGRPolygon>;
68 using multipolygon_type = std::unique_ptr<OGRMultiPolygon>;
69 using ring_type = std::unique_ptr<OGRLinearRing>;
73 linestring_type m_linestring{
nullptr};
74 multipolygon_type m_multipolygon{
nullptr};
75 polygon_type m_polygon{
nullptr};
76 ring_type m_ring{
nullptr};
80 explicit OGRFactoryImpl(
int ) {
85 static point_type make_point(
const osmium::geom::Coordinates& xy) {
86 return std::make_unique<OGRPoint>(xy.
x, xy.
y);
91 void linestring_start() {
92 m_linestring = std::make_unique<OGRLineString>();
95 void linestring_add_location(
const osmium::geom::Coordinates& xy) {
96 assert(!!m_linestring);
97 m_linestring->addPoint(xy.
x, xy.
y);
100 linestring_type linestring_finish(
size_t ) {
101 assert(!!m_linestring);
102 return std::move(m_linestring);
107 void polygon_start() {
108 m_ring = std::make_unique<OGRLinearRing>();
111 void polygon_add_location(
const osmium::geom::Coordinates& xy) {
113 m_ring->addPoint(xy.
x, xy.
y);
116 polygon_type polygon_finish(
size_t ) {
117 auto polygon = std::make_unique<OGRPolygon>();
118 polygon->addRingDirectly(m_ring.release());
124 void multipolygon_start() {
125 m_multipolygon = std::make_unique<OGRMultiPolygon>();
128 void multipolygon_polygon_start() {
129 m_polygon = std::make_unique<OGRPolygon>();
132 void multipolygon_polygon_finish() {
133 assert(!!m_multipolygon);
135 m_multipolygon->addGeometryDirectly(m_polygon.release());
138 void multipolygon_outer_ring_start() {
139 m_ring = std::make_unique<OGRLinearRing>();
142 void multipolygon_outer_ring_finish() {
145 m_polygon->addRingDirectly(m_ring.release());
148 void multipolygon_inner_ring_start() {
149 m_ring = std::make_unique<OGRLinearRing>();
152 void multipolygon_inner_ring_finish() {
155 m_polygon->addRingDirectly(m_ring.release());
158 void multipolygon_add_location(
const osmium::geom::Coordinates& xy) {
161 m_ring->addPoint(xy.
x, xy.
y);
164 multipolygon_type multipolygon_finish() {
165 assert(!!m_multipolygon);
166 return std::move(m_multipolygon);
173 template <
typename TProjection = IdentityProjection>
Definition factory.hpp:149
Everything related to geometry handling.
Definition coordinates.hpp:46
GeometryFactory< osmium::geom::detail::OGRFactoryImpl, TProjection > OGRFactory
Definition ogr.hpp:174
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
double y
Definition coordinates.hpp:51
double x
Definition coordinates.hpp:50