WKTReader.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/WKTReader.java rev. 1.1 (JTS-1.7)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/Geometry.h>
#include <geos/io/ParseException.h>
#include <geos/io/OrdinateSet.h>
#include <string>
// Forward declarations
namespace geos {
namespace io {
class StringTokenizer;
}
namespace geom {
class Coordinate;
class CoordinateSequence;
class GeometryCollection;
class Point;
class LineString;
class LinearRing;
class CircularString;
class CompoundCurve;
class Polygon;
class CurvePolygon;
class MultiPoint;
class MultiLineString;
class MultiCurve;
class MultiPolygon;
class MultiSurface;
class PrecisionModel;
}
}
namespace geos {
namespace io {
class GEOS_DLL WKTReader {
public:
explicit WKTReader(const geom::GeometryFactory& gf)
: geometryFactory(&gf)
, precisionModel(gf.getPrecisionModel())
, fixStructure(false)
{};
explicit WKTReader(const geom::GeometryFactory* gf)
: geometryFactory(gf)
, precisionModel(gf->getPrecisionModel())
, fixStructure(false)
{};
WKTReader()
: geometryFactory(geom::GeometryFactory::getDefaultInstance())
, precisionModel(geometryFactory->getPrecisionModel())
, fixStructure(false)
{};
~WKTReader() {};
void
setFixStructure(bool doFixStructure) {
fixStructure = doFixStructure;
}
template<typename T>
std::unique_ptr<T> read(const std::string& wkt) const {
auto g = read(wkt);
auto gt = dynamic_cast<const T*>(g.get());
if (!gt) {
// Can improve this message once there's a good way to get a string repr of T
throw io::ParseException("Unexpected WKT type");
}
return std::unique_ptr<T>(static_cast<T*>(g.release()));
}
std::unique_ptr<geom::Geometry> read(const std::string& wellKnownText) const;
protected:
std::unique_ptr<geom::CoordinateSequence> getCoordinates(io::StringTokenizer* tokenizer, OrdinateSet& ordinates) const;
static double getNextNumber(io::StringTokenizer* tokenizer);
static std::string getNextEmptyOrOpener(io::StringTokenizer* tokenizer, OrdinateSet& dim);
static std::string getNextCloserOrComma(io::StringTokenizer* tokenizer);
static std::string getNextCloser(io::StringTokenizer* tokenizer);
static std::string getNextWord(io::StringTokenizer* tokenizer);
std::unique_ptr<geom::Geometry> readGeometryTaggedText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags, const geom::GeometryTypeId* emptyType = nullptr) const;
std::unique_ptr<geom::Point> readPointText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::LineString> readLineStringText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::LinearRing> readLinearRingText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::MultiPoint> readMultiPointText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::Polygon> readPolygonText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::MultiLineString> readMultiLineStringText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::MultiPolygon> readMultiPolygonText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::GeometryCollection> readGeometryCollectionText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::CircularString> readCircularStringText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::CompoundCurve> readCompoundCurveText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::CurvePolygon> readCurvePolygonText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::MultiCurve> readMultiCurveText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::MultiSurface> readMultiSurfaceText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::Curve> readCurveText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
std::unique_ptr<geom::Geometry> readSurfaceText(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags) const;
private:
const geom::GeometryFactory* geometryFactory;
const geom::PrecisionModel* precisionModel;
bool fixStructure;
void getPreciseCoordinate(io::StringTokenizer* tokenizer, OrdinateSet& ordinateFlags, geom::CoordinateXYZM&) const;
static bool isNumberNext(io::StringTokenizer* tokenizer);
static bool isOpenerNext(io::StringTokenizer* tokenizer);
static void readOrdinateFlags(const std::string & s, OrdinateSet& ordinateFlags);
static bool isTypeName(const std::string & type, const std::string & typeName);
};
} // namespace io
} // namespace geos
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::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::OrdinateSet
Utility class to manipulate a set of flags indicating whether X, Y, Z, or M dimensions are present....
Definition OrdinateSet.h:29
geos::io::ParseException
Notifies a parsing error.
Definition ParseException.h:33
geos::io::WKTReader
WKT parser class; see also WKTWriter.
Definition WKTReader.h:64
geos::io::WKTReader::readSurfaceText
std::unique_ptr< geom::Geometry > readSurfaceText(io::StringTokenizer *tokenizer, OrdinateSet &ordinateFlags) const
Read the contents of a POLYGON or a CURVEPOLYGON.
geos::io::WKTReader::read
std::unique_ptr< T > read(const std::string &wkt) const
Parse a WKT string returning a Geometry.
Definition WKTReader.h:107
geos::io::WKTReader::readCurveText
std::unique_ptr< geom::Curve > readCurveText(io::StringTokenizer *tokenizer, OrdinateSet &ordinateFlags) const
Read the contents of a LINEARRING, LINESTRING, CIRCULARSTRING, or COMPOUNDCURVE.
geos::io::WKTReader::WKTReader
WKTReader(const geom::GeometryFactory *gf)
Definition WKTReader.h:82
geos::io::WKTReader::WKTReader
WKTReader()
Initialize parser with default GeometryFactory.
Definition WKTReader.h:92
geos::io::WKTReader::WKTReader
WKTReader(const geom::GeometryFactory &gf)
Initialize parser with given GeometryFactory.
Definition WKTReader.h:75
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