GEOS 3.15.0dev
WKBReader.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2005-2006 Refractions Research Inc.
7 * Copyright (C) 2001-2002 Vivid Solutions Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: io/WKBReader.java rev. 1.1 (JTS-1.7)
17 *
18 **********************************************************************/
19
20#pragma once
21
22#include <geos/export.h>
23#include <geos/geom/Geometry.h>
24#include <geos/geom/GeometryTypeName.h>
25#include <geos/io/ByteOrderDataInStream.h> // for composition
26
27#include <iosfwd> // ostream, istream
28#include <memory>
29// #include <vector>
30#include <array>
31
32#ifdef _MSC_VER
33#pragma warning(push)
34#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35#endif
36
37// Forward declarations
38namespace geos {
39namespace geom {
40
41class GeometryFactory;
42class Coordinate;
43class CircularString;
44class CompoundCurve;
45class CurvePolygon;
46class Geometry;
47enum GeometryTypeId : int;
48class GeometryCollection;
49class Point;
50class LineString;
51class LinearRing;
52class Polygon;
53class MultiCurve;
54class MultiPoint;
55class MultiLineString;
56class MultiPolygon;
57class MultiSurface;
58class PrecisionModel;
59class CoordinateSequence;
60class SimpleCurve;
61
62} // namespace geom
63} // namespace geos
64
65
66namespace geos {
67namespace io {
68
85class GEOS_DLL WKBReader {
86
87public:
88
90
93
94 void setFixStructure(bool doFixStructure);
95
104 std::unique_ptr<geom::Geometry> read(std::istream& is);
105
115 std::unique_ptr<geom::Geometry> read(const unsigned char* buf, size_t size);
116
125 std::unique_ptr<geom::Geometry> readHEX(std::istream& is);
126
135 std::unique_ptr<geom::Geometry> readHEX(const std::string& hex);
136
143 static std::ostream& printHEX(std::istream& is, std::ostream& os);
144
145private:
146
147 const geom::GeometryFactory& factory;
148
149 // for now support the WKB standard only - may be generalized later
150 unsigned int inputDimension;
151 bool hasZ;
152 bool hasM;
153 bool fixStructure;
154
156
157 std::array<double, 4> ordValues;
158
159 int parseDepth_ = 0;
160
161 std::unique_ptr<geom::Geometry> readGeometry();
162
163 std::unique_ptr<geom::Point> readPoint();
164
165 std::unique_ptr<geom::LineString> readLineString();
166
167 std::unique_ptr<geom::LinearRing> readLinearRing();
168
169 std::unique_ptr<geom::CircularString> readCircularString();
170
171 std::unique_ptr<geom::CompoundCurve> readCompoundCurve();
172
173 std::unique_ptr<geom::Polygon> readPolygon();
174
175 std::unique_ptr<geom::CurvePolygon> readCurvePolygon();
176
177 std::unique_ptr<geom::MultiPoint> readMultiPoint();
178
179 std::unique_ptr<geom::MultiLineString> readMultiLineString();
180
181 std::unique_ptr<geom::MultiCurve> readMultiCurve();
182
183 std::unique_ptr<geom::MultiPolygon> readMultiPolygon();
184
185 std::unique_ptr<geom::MultiSurface> readMultiSurface();
186
187 std::unique_ptr<geom::GeometryCollection> readGeometryCollection();
188
189 std::unique_ptr<geom::CoordinateSequence> readCoordinateSequence(unsigned int); // throws IOException
190
191 void minMemSize(geom::GeometryTypeId geomType, uint64_t size) const;
192
193 void readCoordinate(); // throws IOException
194
195 template<typename T>
196 std::unique_ptr<T> readChild()
197 {
198 auto g = readGeometry();
199 if (dynamic_cast<const T*>(g.get())) {
200 return std::unique_ptr<T>(static_cast<T*>(g.release()));
201 }
202 throw io::ParseException(std::string("Expected ") + geom::GeometryTypeName<T>::name + " but got " + g->getGeometryType());
203 }
204
205 // Declare type as noncopyable
206 WKBReader(const WKBReader& other) = delete;
207 WKBReader& operator=(const WKBReader& rhs) = delete;
208};
209
210} // namespace io
211} // namespace geos
212
213#ifdef _MSC_VER
214#pragma warning(pop)
215#endif
216
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:71
Allows reading an stream of primitive datatypes from an underlying istream, with the representation b...
Definition ByteOrderDataInStream.h:40
Notifies a parsing error.
Definition ParseException.h:33
Reads a Geometry from Well-Known Binary format.
Definition WKBReader.h:85
static std::ostream & printHEX(std::istream &is, std::ostream &os)
Print WKB in HEX form to out stream.
WKBReader()
Initialize parser with default GeometryFactory.
std::unique_ptr< geom::Geometry > readHEX(const std::string &hex)
Reads a Geometry hex format.
std::unique_ptr< geom::Geometry > read(const unsigned char *buf, size_t size)
Reads a Geometry from a buffer.
std::unique_ptr< geom::Geometry > readHEX(std::istream &is)
Reads a Geometry from an istream in hex format.
std::unique_ptr< geom::Geometry > read(std::istream &is)
Reads a Geometry from an istream.
GeometryTypeId
Geometry types.
Definition Geometry.h:73
Basic namespace for all GEOS functionalities.
Definition geos.h:38