WKTWriter.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
* 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/WKTWriter.java rev. 1.34 (JTS-1.7)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/io/OrdinateSet.h>
#include <string>
#include <cctype>
#include <cstdint>
#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 Coordinate;
class CoordinateXY;
class CoordinateXYZM;
class CoordinateSequence;
class Curve;
class CompoundCurve;
class Geometry;
class GeometryCollection;
class Point;
class LineString;
class LinearRing;
class Polygon;
class MultiPoint;
class MultiLineString;
class MultiPolygon;
class PrecisionModel;
class SimpleCurve;
class Surface;
}
namespace io {
class Writer;
}
}
namespace geos {
namespace io {
class GEOS_DLL WKTWriter {
public:
WKTWriter();
~WKTWriter() = default;
//string(count, ch) can be used for this
//static string stringOfChar(char ch, int count);
std::string write(const geom::Geometry* geometry);
std::string write(const geom::Geometry& geometry);
// Send Geometry's WKT to the given Writer
void write(const geom::Geometry* geometry, Writer* writer);
std::string writeFormatted(const geom::Geometry* geometry);
void writeFormatted(const geom::Geometry* geometry, Writer* writer);
static std::string toLineString(const geom::CoordinateSequence& seq);
static std::string toLineString(const geom::CoordinateXY& p0, const geom::CoordinateXY& p1);
static std::string toPoint(const geom::Coordinate& p0);
static std::string toPoint(const geom::CoordinateXY& p0);
void setRoundingPrecision(int p0);
void setTrim(bool p0);
void setRemoveEmptyDimensions(bool remove)
{
removeEmptyDimensions = remove;
}
void
setOld3D(bool useOld3D)
{
old3D = useOld3D;
}
/*
* \brief
* Returns the output dimension used by the
* <code>WKTWriter</code>.
*/
int
getOutputDimension() const
{
return defaultOutputDimension;
}
/*
* Sets the output dimension used by the <code>WKTWriter</code>.
*
* @param newOutputDimension Supported values are 2, 3 or 4.
* Default since GEOS 3.12 is 4.
* Note that 3 indicates up to 3 dimensions will be
* written but 2D WKT is still produced for 2D geometries.
*/
void setOutputDimension(uint8_t newOutputDimension);
static std::string writeNumber(double d, bool trim, uint32_t precision);
static int writeTrimmedNumber(double d, uint32_t precision, char* buf);
protected:
int decimalPlaces;
void appendGeometryTaggedText(
const geom::Geometry& geometry,
OrdinateSet outputOrdinates,
int level,
Writer& writer) const;
void appendTag(
const geom::Geometry& geometry,
OrdinateSet outputOrdinates,
Writer& writer) const;
void appendPointTaggedText(
const geom::Point& point,
OrdinateSet outputOrdinates,
int level, Writer& writer) const;
void appendSimpleCurveTaggedText(
const geom::SimpleCurve& lineString,
OrdinateSet outputOrdinates,
int level, Writer& writer) const;
void appendCompoundCurveTaggedText(
const geom::CompoundCurve& lineString,
OrdinateSet outputOrdinates,
int level, Writer& writer) const;
void appendSurfaceTaggedText(
const geom::Surface& polygon,
OrdinateSet outputOrdinates,
int level, Writer& writer) const;
void appendMultiPointTaggedText(
const geom::MultiPoint& multipoint,
OrdinateSet outputOrdinates,
int level, Writer& writer) const;
void appendMultiCurveTaggedText(
const geom::GeometryCollection& multiCurve,
OrdinateSet outputOrdinates,
int level, Writer& writer) const;
void appendMultiSurfaceTaggedText(
const geom::GeometryCollection& multiSurface,
OrdinateSet outputOrdinates,
int level, Writer& writer) const;
void appendGeometryCollectionTaggedText(
const geom::GeometryCollection& geometryCollection,
OrdinateSet outputOrdinates,
int level, Writer& writer) const;
void appendOrdinateText(OrdinateSet outputOrdinates,
Writer& writer) const;
void appendSequenceText(const geom::CoordinateSequence& seq,
OrdinateSet outputOrdinates,
int level,
bool doIntent,
Writer& writer) const;
void appendCoordinate(const geom::CoordinateXYZM& coordinate,
OrdinateSet outputOrdinates,
Writer& writer) const;
std::string writeNumber(double d) const;
void appendCurveText(
const geom::Curve& lineString,
OrdinateSet outputOrdinates,
int level, bool doIndent, Writer& writer) const;
void appendSimpleCurveText(
const geom::SimpleCurve& lineString,
OrdinateSet outputOrdinates,
int level, bool doIndent, Writer& writer) const;
void appendSurfaceText(
const geom::Surface& polygon,
OrdinateSet outputOrdinates,
int level, bool indentFirst, Writer& writer) const;
void appendMultiPointText(
const geom::MultiPoint& multiPoint,
OrdinateSet outputOrdinates,
int level, Writer& writer) const;
void appendMultiCurveText(
const geom::GeometryCollection& multiCurve,
OrdinateSet outputOrdinates,
int level, bool indentFirst, Writer& writer) const;
void appendMultiSurfaceText(
const geom::GeometryCollection& multiSurface,
OrdinateSet outputOrdinates,
int level, Writer& writer) const;
void appendGeometryCollectionText(
const geom::GeometryCollection& geometryCollection,
OrdinateSet outputOrdinates,
int level, Writer& writer) const;
private:
enum {
INDENT = 2
};
bool isFormatted;
int roundingPrecision;
bool trim;
bool removeEmptyDimensions = false;
static constexpr int coordsPerLine = 10;
uint8_t defaultOutputDimension;
bool old3D;
void writeFormatted(
const geom::Geometry* geometry,
bool isFormatted, Writer* writer);
void indent(int level, Writer* writer) const;
};
} // namespace geos::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::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::geom::Surface
Definition Surface.h:27
geos::io::WKTWriter::toPoint
static std::string toPoint(const geom::Coordinate &p0)
geos::io::WKTWriter::setOld3D
void setOld3D(bool useOld3D)
Definition WKTWriter.h:176
geos::io::WKTWriter::setTrim
void setTrim(bool p0)
geos::io::WKTWriter::setRoundingPrecision
void setRoundingPrecision(int p0)
geos::io::WKTWriter::toLineString
static std::string toLineString(const geom::CoordinateXY &p0, const geom::CoordinateXY &p1)
geos::io::WKTWriter::write
std::string write(const geom::Geometry *geometry)
Returns WKT string for the given Geometry.
geos::io::WKTWriter::setRemoveEmptyDimensions
void setRemoveEmptyDimensions(bool remove)
setRemoveEmptyDimensions
Definition WKTWriter.h:160
geos::io::WKTWriter::toLineString
static std::string toLineString(const geom::CoordinateSequence &seq)
geos::geom
Definition Angle.h:26
geos::io
Contains the interfaces for converting JTS objects to and from other formats.
Definition Geometry.h:65
geos::precision
Provides classes for manipulating the precision model of Geometries.
Definition namespaces.h:300
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38