WKBReader.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2005-2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: io/WKBReader.java rev. 1.1 (JTS-1.7)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryTypeName.h>
#include <geos/io/ByteOrderDataInStream.h> // for composition
#include <iosfwd> // ostream, istream
#include <memory>
// #include <vector>
#include <array>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
#endif
// Forward declarations
namespace geos {
namespace geom {
class GeometryFactory;
class Coordinate;
class CircularString;
class CompoundCurve;
class CurvePolygon;
class Geometry;
enum GeometryTypeId : int;
class GeometryCollection;
class Point;
class LineString;
class LinearRing;
class Polygon;
class MultiCurve;
class MultiPoint;
class MultiLineString;
class MultiPolygon;
class MultiSurface;
class PrecisionModel;
class CoordinateSequence;
class SimpleCurve;
} // namespace geom
} // namespace geos
namespace geos {
namespace io {
class GEOS_DLL WKBReader {
public:
WKBReader(geom::GeometryFactory const& f);
WKBReader();
void setFixStructure(bool doFixStructure);
std::unique_ptr<geom::Geometry> read(std::istream& is);
std::unique_ptr<geom::Geometry> read(const unsigned char* buf, size_t size);
std::unique_ptr<geom::Geometry> readHEX(std::istream& is);
static std::ostream& printHEX(std::istream& is, std::ostream& os);
private:
const geom::GeometryFactory& factory;
// for now support the WKB standard only - may be generalized later
unsigned int inputDimension;
bool hasZ;
bool hasM;
bool fixStructure;
ByteOrderDataInStream dis;
std::array<double, 4> ordValues;
std::unique_ptr<geom::Geometry> readGeometry();
std::unique_ptr<geom::Point> readPoint();
std::unique_ptr<geom::LineString> readLineString();
std::unique_ptr<geom::LinearRing> readLinearRing();
std::unique_ptr<geom::CircularString> readCircularString();
std::unique_ptr<geom::CompoundCurve> readCompoundCurve();
std::unique_ptr<geom::Polygon> readPolygon();
std::unique_ptr<geom::CurvePolygon> readCurvePolygon();
std::unique_ptr<geom::MultiPoint> readMultiPoint();
std::unique_ptr<geom::MultiLineString> readMultiLineString();
std::unique_ptr<geom::MultiCurve> readMultiCurve();
std::unique_ptr<geom::MultiPolygon> readMultiPolygon();
std::unique_ptr<geom::MultiSurface> readMultiSurface();
std::unique_ptr<geom::GeometryCollection> readGeometryCollection();
std::unique_ptr<geom::CoordinateSequence> readCoordinateSequence(unsigned int); // throws IOException
void minMemSize(geom::GeometryTypeId geomType, uint64_t size) const;
void readCoordinate(); // throws IOException
template<typename T>
std::unique_ptr<T> readChild()
{
auto g = readGeometry();
if (dynamic_cast<const T*>(g.get())) {
return std::unique_ptr<T>(static_cast<T*>(g.release()));
}
throw io::ParseException(std::string("Expected ") + geom::GeometryTypeName<T>::name + " but got " + g->getGeometryType());
}
// Declare type as noncopyable
WKBReader(const WKBReader& other) = delete;
WKBReader& operator=(const WKBReader& rhs) = delete;
};
} // namespace io
} // namespace geos
#ifdef _MSC_VER
#pragma warning(pop)
#endif
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::geom::GeometryCollection
Represents a collection of heterogeneous Geometry objects.
Definition GeometryCollection.h:51
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::geom::LineString
Definition LineString.h:66
geos::geom::LinearRing
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
geos::geom::MultiLineString
Models a collection of LineStrings.
Definition MultiLineString.h:49
geos::geom::MultiPoint
Definition MultiPoint.h:50
geos::geom::MultiPolygon
Definition MultiPolygon.h:58
geos::geom::Point
Definition Point.h:61
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
geos::geom::PrecisionModel
Specifies the precision model of the Coordinate in a Geometry.
Definition PrecisionModel.h:87
geos::io::ByteOrderDataInStream
Allows reading an stream of primitive datatypes from an underlying istream, with the representation b...
Definition ByteOrderDataInStream.h:40
geos::io::ParseException
Notifies a parsing error.
Definition ParseException.h:33
geos::io::WKBReader::printHEX
static std::ostream & printHEX(std::istream &is, std::ostream &os)
Print WKB in HEX form to out stream.
geos::io::WKBReader::WKBReader
WKBReader()
Initialize parser with default GeometryFactory.
geos::io::WKBReader::read
std::unique_ptr< geom::Geometry > read(const unsigned char *buf, size_t size)
Reads a Geometry from a buffer.
geos::io::WKBReader::readHEX
std::unique_ptr< geom::Geometry > readHEX(std::istream &is)
Reads a Geometry from an istream in hex format.
geos::io::WKBReader::read
std::unique_ptr< geom::Geometry > read(std::istream &is)
Reads a Geometry from an istream.
geos::geom
Definition Angle.h:26
geos::geom::GeometryTypeId
GeometryTypeId
Geometry types.
Definition Geometry.h:73
geos::io
Contains the interfaces for converting JTS objects to and from other formats.
Definition Geometry.h:65
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38