Libosmium  2.4.1
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ogr.hpp
Go to the documentation of this file.
1 #ifndef OSMIUM_GEOM_OGR_HPP
2 #define OSMIUM_GEOM_OGR_HPP
3 
4 /*
5 
6 This file is part of Osmium (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2015 Jochen Topf <jochen@topf.org> and others (see README).
9 
10 Boost Software License - Version 1.0 - August 17th, 2003
11 
12 Permission is hereby granted, free of charge, to any person or organization
13 obtaining a copy of the software and accompanying documentation covered by
14 this license (the "Software") to use, reproduce, display, distribute,
15 execute, and transmit the Software, and to prepare derivative works of the
16 Software, and to permit third-parties to whom the Software is furnished to
17 do so, all subject to the following:
18 
19 The copyright notices in the Software and this entire statement, including
20 the above license grant, this restriction and the following disclaimer,
21 must be included in all copies of the Software, in whole or in part, and
22 all derivative works of the Software, unless such copies or derivative
23 works are solely in the form of machine-executable object code generated by
24 a source language processor.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 DEALINGS IN THE SOFTWARE.
33 
34 */
35 
45 #include <cassert>
46 #include <cstddef>
47 #include <memory>
48 #include <utility>
49 
50 #include <ogr_geometry.h>
51 
53 #include <osmium/geom/factory.hpp>
54 
55 namespace osmium {
56 
57  namespace geom {
58 
59  namespace detail {
60 
61  class OGRFactoryImpl {
62 
63  public:
64 
65  typedef std::unique_ptr<OGRPoint> point_type;
66  typedef std::unique_ptr<OGRLineString> linestring_type;
67  typedef std::unique_ptr<OGRPolygon> polygon_type;
68  typedef std::unique_ptr<OGRMultiPolygon> multipolygon_type;
69  typedef std::unique_ptr<OGRLinearRing> ring_type;
70 
71  private:
72 
73  linestring_type m_linestring;
74  multipolygon_type m_multipolygon;
75  polygon_type m_polygon;
76  ring_type m_ring;
77 
78  public:
79 
80  OGRFactoryImpl() = default;
81 
82  /* Point */
83 
84  point_type make_point(const osmium::geom::Coordinates& xy) const {
85  return point_type(new OGRPoint(xy.x, xy.y));
86  }
87 
88  /* LineString */
89 
90  void linestring_start() {
91  m_linestring = std::unique_ptr<OGRLineString>(new OGRLineString());
92  }
93 
94  void linestring_add_location(const osmium::geom::Coordinates& xy) {
95  assert(!!m_linestring);
96  m_linestring->addPoint(xy.x, xy.y);
97  }
98 
99  linestring_type linestring_finish(size_t /* num_points */) {
100  return std::move(m_linestring);
101  }
102 
103  /* Polygon */
104 
105  void polygon_start() {
106  m_ring = std::unique_ptr<OGRLinearRing>(new OGRLinearRing());
107  }
108 
109  void polygon_add_location(const osmium::geom::Coordinates& xy) {
110  assert(!!m_ring);
111  m_ring->addPoint(xy.x, xy.y);
112  }
113 
114  polygon_type polygon_finish(size_t /* num_points */) {
115  std::unique_ptr<OGRPolygon> polygon = std::unique_ptr<OGRPolygon>(new OGRPolygon());
116  polygon->addRingDirectly(m_ring.release());
117  return polygon;
118  }
119 
120  /* MultiPolygon */
121 
122  void multipolygon_start() {
123  m_multipolygon.reset(new OGRMultiPolygon());
124  }
125 
126  void multipolygon_polygon_start() {
127  m_polygon.reset(new OGRPolygon());
128  }
129 
130  void multipolygon_polygon_finish() {
131  assert(!!m_multipolygon);
132  assert(!!m_polygon);
133  m_multipolygon->addGeometryDirectly(m_polygon.release());
134  }
135 
136  void multipolygon_outer_ring_start() {
137  m_ring.reset(new OGRLinearRing());
138  }
139 
140  void multipolygon_outer_ring_finish() {
141  assert(!!m_polygon);
142  assert(!!m_ring);
143  m_polygon->addRingDirectly(m_ring.release());
144  }
145 
146  void multipolygon_inner_ring_start() {
147  m_ring.reset(new OGRLinearRing());
148  }
149 
150  void multipolygon_inner_ring_finish() {
151  assert(!!m_polygon);
152  assert(!!m_ring);
153  m_polygon->addRingDirectly(m_ring.release());
154  }
155 
156  void multipolygon_add_location(const osmium::geom::Coordinates& xy) {
157  assert(!!m_polygon);
158  assert(!!m_ring);
159  m_ring->addPoint(xy.x, xy.y);
160  }
161 
162  multipolygon_type multipolygon_finish() {
163  assert(!!m_multipolygon);
164  return std::move(m_multipolygon);
165  }
166 
167  }; // class OGRFactoryImpl
168 
169  } // namespace detail
170 
171  template <class TProjection = IdentityProjection>
173 
174  } // namespace geom
175 
176 } // namespace osmium
177 
178 #endif // OSMIUM_GEOM_OGR_HPP
double y
Definition: coordinates.hpp:50
Definition: factory.hpp:146
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
Definition: coordinates.hpp:47
double x
Definition: coordinates.hpp:49