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