GEOS  3.13.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 
24 #include <geos/io/ByteOrderDataInStream.h> // for composition
25 
26 #include <iosfwd> // ostream, istream
27 #include <memory>
28 // #include <vector>
29 #include <array>
30 
31 #define BAD_GEOM_TYPE_MSG "Bad geometry type encountered in"
32 
33 #ifdef _MSC_VER
34 #pragma warning(push)
35 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36 #endif
37 
38 // Forward declarations
39 namespace geos {
40 namespace geom {
41 
42 class GeometryFactory;
43 class Coordinate;
44 class Geometry;
45 class GeometryCollection;
46 class Point;
47 class LineString;
48 class LinearRing;
49 class Polygon;
50 class MultiPoint;
51 class MultiLineString;
52 class MultiPolygon;
53 class PrecisionModel;
54 class CoordinateSequence;
55 
56 } // namespace geom
57 } // namespace geos
58 
59 
60 namespace geos {
61 namespace io {
62 
79 class GEOS_DLL WKBReader {
80 
81 public:
82 
84 
87 
88  void setFixStructure(bool doFixStructure);
89 
98  std::unique_ptr<geom::Geometry> read(std::istream& is);
99 
109  std::unique_ptr<geom::Geometry> read(const unsigned char* buf, size_t size);
110 
119  std::unique_ptr<geom::Geometry> readHEX(std::istream& is);
120 
127  static std::ostream& printHEX(std::istream& is, std::ostream& os);
128 
129 private:
130 
131  const geom::GeometryFactory& factory;
132 
133  // for now support the WKB standard only - may be generalized later
134  unsigned int inputDimension;
135  bool hasZ;
136  bool hasM;
137  bool fixStructure;
138 
140 
141  std::array<double, 4> ordValues;
142 
143  std::unique_ptr<geom::Geometry> readGeometry();
144 
145  std::unique_ptr<geom::Point> readPoint();
146 
147  std::unique_ptr<geom::LineString> readLineString();
148 
149  std::unique_ptr<geom::LinearRing> readLinearRing();
150 
151  std::unique_ptr<geom::Polygon> readPolygon();
152 
153  std::unique_ptr<geom::MultiPoint> readMultiPoint();
154 
155  std::unique_ptr<geom::MultiLineString> readMultiLineString();
156 
157  std::unique_ptr<geom::MultiPolygon> readMultiPolygon();
158 
159  std::unique_ptr<geom::GeometryCollection> readGeometryCollection();
160 
161  std::unique_ptr<geom::CoordinateSequence> readCoordinateSequence(unsigned int); // throws IOException
162 
163  void minMemSize(int geomType, uint64_t size);
164 
165  void readCoordinate(); // throws IOException
166 
167  // Declare type as noncopyable
168  WKBReader(const WKBReader& other) = delete;
169  WKBReader& operator=(const WKBReader& rhs) = delete;
170 };
171 
172 } // namespace io
173 } // namespace geos
174 
175 #ifdef _MSC_VER
176 #pragma warning(pop)
177 #endif
178 
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:65
Allows reading an stream of primitive datatypes from an underlying istream, with the representation b...
Definition: ByteOrderDataInStream.h:40
Reads a Geometry from Well-Known Binary format.
Definition: WKBReader.h:79
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.
WKBReader()
Inizialize parser with default GeometryFactory.
static std::ostream & printHEX(std::istream &is, std::ostream &os)
Print WKB in HEX form to out stream.
std::unique_ptr< geom::Geometry > read(std::istream &is)
Reads a Geometry from an istream.
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25