Libosmium  2.3.0
Fast and flexible C++ library for working with OpenStreetMap data
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 #ifdef _MSC_VER
51 # pragma warning(push)
52 # pragma warning(disable : 4458)
53 # pragma warning(disable : 4251)
54 #else
55 # pragma GCC diagnostic push
56 # ifdef __clang__
57 # pragma GCC diagnostic ignored "-Wdocumentation-unknown-command"
58 # endif
59 # pragma GCC diagnostic ignored "-Wfloat-equal"
60 # pragma GCC diagnostic ignored "-Wold-style-cast"
61 # pragma GCC diagnostic ignored "-Wpadded"
62 # pragma GCC diagnostic ignored "-Wredundant-decls"
63 # pragma GCC diagnostic ignored "-Wshadow"
64 #endif
65 
66 /* Strictly speaking the following include would be enough here,
67  but everybody using this file will very likely need the other includes,
68  so we are adding them here, so that not everybody will need all those
69  pragmas to disable warnings. */
70 //#include <ogr_geometry.h>
71 #include <ogr_api.h>
72 #include <ogrsf_frmts.h>
73 
74 #ifdef _MSC_VER
75 # pragma warning(pop)
76 #else
77 # pragma GCC diagnostic pop
78 #endif
79 
81 #include <osmium/geom/factory.hpp>
82 
83 namespace osmium {
84 
85  namespace geom {
86 
87  namespace detail {
88 
89  class OGRFactoryImpl {
90 
91  public:
92 
93  typedef std::unique_ptr<OGRPoint> point_type;
94  typedef std::unique_ptr<OGRLineString> linestring_type;
95  typedef std::unique_ptr<OGRPolygon> polygon_type;
96  typedef std::unique_ptr<OGRMultiPolygon> multipolygon_type;
97  typedef std::unique_ptr<OGRLinearRing> ring_type;
98 
99  private:
100 
101  linestring_type m_linestring;
102  multipolygon_type m_multipolygon;
103  polygon_type m_polygon;
104  ring_type m_ring;
105 
106  public:
107 
108  OGRFactoryImpl() = default;
109 
110  /* Point */
111 
112  point_type make_point(const osmium::geom::Coordinates& xy) const {
113  return point_type(new OGRPoint(xy.x, xy.y));
114  }
115 
116  /* LineString */
117 
118  void linestring_start() {
119  m_linestring = std::unique_ptr<OGRLineString>(new OGRLineString());
120  }
121 
122  void linestring_add_location(const osmium::geom::Coordinates& xy) {
123  assert(!!m_linestring);
124  m_linestring->addPoint(xy.x, xy.y);
125  }
126 
127  linestring_type linestring_finish(size_t /* num_points */) {
128  return std::move(m_linestring);
129  }
130 
131  /* Polygon */
132 
133  void polygon_start() {
134  m_ring = std::unique_ptr<OGRLinearRing>(new OGRLinearRing());
135  }
136 
137  void polygon_add_location(const osmium::geom::Coordinates& xy) {
138  assert(!!m_ring);
139  m_ring->addPoint(xy.x, xy.y);
140  }
141 
142  polygon_type polygon_finish(size_t /* num_points */) {
143  std::unique_ptr<OGRPolygon> polygon = std::unique_ptr<OGRPolygon>(new OGRPolygon());
144  polygon->addRingDirectly(m_ring.release());
145  return polygon;
146  }
147 
148  /* MultiPolygon */
149 
150  void multipolygon_start() {
151  m_multipolygon.reset(new OGRMultiPolygon());
152  }
153 
154  void multipolygon_polygon_start() {
155  m_polygon.reset(new OGRPolygon());
156  }
157 
158  void multipolygon_polygon_finish() {
159  assert(!!m_multipolygon);
160  assert(!!m_polygon);
161  m_multipolygon->addGeometryDirectly(m_polygon.release());
162  }
163 
164  void multipolygon_outer_ring_start() {
165  m_ring.reset(new OGRLinearRing());
166  }
167 
168  void multipolygon_outer_ring_finish() {
169  assert(!!m_polygon);
170  assert(!!m_ring);
171  m_polygon->addRingDirectly(m_ring.release());
172  }
173 
174  void multipolygon_inner_ring_start() {
175  m_ring.reset(new OGRLinearRing());
176  }
177 
178  void multipolygon_inner_ring_finish() {
179  assert(!!m_polygon);
180  assert(!!m_ring);
181  m_polygon->addRingDirectly(m_ring.release());
182  }
183 
184  void multipolygon_add_location(const osmium::geom::Coordinates& xy) {
185  assert(!!m_polygon);
186  assert(!!m_ring);
187  m_ring->addPoint(xy.x, xy.y);
188  }
189 
190  multipolygon_type multipolygon_finish() {
191  assert(!!m_multipolygon);
192  return std::move(m_multipolygon);
193  }
194 
195  }; // class OGRFactoryImpl
196 
197  } // namespace detail
198 
199  template <class TProjection = IdentityProjection>
201 
202  } // namespace geom
203 
204 } // namespace osmium
205 
206 #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