GEOS 3.11.1
WKTWriter.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7 * Copyright (C) 2005-2006 Refractions Research Inc.
8 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9 *
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
14 *
15 **********************************************************************
16 *
17 * Last port: io/WKTWriter.java rev. 1.34 (JTS-1.7)
18 *
19 **********************************************************************/
20
21#pragma once
22
23#include <geos/export.h>
24
25#include <string>
26#include <cctype>
27#include <cstdint>
28
29#ifdef _MSC_VER
30#pragma warning(push)
31#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
32#endif
33
34// Forward declarations
35namespace geos {
36namespace geom {
37class Coordinate;
38class CoordinateSequence;
39class Geometry;
40class GeometryCollection;
41class Point;
42class LineString;
43class LinearRing;
44class Polygon;
45class MultiPoint;
46class MultiLineString;
47class MultiPolygon;
48class PrecisionModel;
49}
50namespace io {
51class Writer;
52}
53}
54
55
56namespace geos {
57namespace io {
58
80class GEOS_DLL WKTWriter {
81public:
82 WKTWriter();
83 ~WKTWriter() = default;
84
85 //string(count, ch) can be used for this
86 //static string stringOfChar(char ch, int count);
87
89 std::string write(const geom::Geometry* geometry);
90
91 // Send Geometry's WKT to the given Writer
92 void write(const geom::Geometry* geometry, Writer* writer);
93
94 std::string writeFormatted(const geom::Geometry* geometry);
95
96 void writeFormatted(const geom::Geometry* geometry, Writer* writer);
97
105 static std::string toLineString(const geom::CoordinateSequence& seq);
106
115 static std::string toLineString(const geom::Coordinate& p0, const geom::Coordinate& p1);
116
124 static std::string toPoint(const geom::Coordinate& p0);
125
134
141 void setTrim(bool p0);
142
153 void
154 setOld3D(bool useOld3D)
155 {
156 old3D = useOld3D;
157 }
158
159 /*
160 * \brief
161 * Returns the output dimension used by the
162 * <code>WKBWriter</code>.
163 */
164 int
165 getOutputDimension() const
166 {
167 return defaultOutputDimension;
168 }
169
170 /*
171 * Sets the output dimension used by the <code>WKBWriter</code>.
172 *
173 * @param newOutputDimension Supported values are 2 or 3.
174 * Note that 3 indicates up to 3 dimensions will be
175 * written but 2D WKB is still produced for 2D geometries.
176 */
177 void setOutputDimension(uint8_t newOutputDimension);
178
179protected:
180
181 int decimalPlaces;
182
183 void appendGeometryTaggedText(const geom::Geometry* geometry, int level, Writer* writer);
184
185 void appendPointTaggedText(
186 const geom::Coordinate* coordinate,
187 int level, Writer* writer);
188
189 void appendLineStringTaggedText(
190 const geom::LineString* lineString,
191 int level, Writer* writer);
192
193 void appendLinearRingTaggedText(
194 const geom::LinearRing* lineString,
195 int level, Writer* writer);
196
197 void appendPolygonTaggedText(
198 const geom::Polygon* polygon,
199 int level, Writer* writer);
200
201 void appendMultiPointTaggedText(
202 const geom::MultiPoint* multipoint,
203 int level, Writer* writer);
204
205 void appendMultiLineStringTaggedText(
206 const geom::MultiLineString* multiLineString,
207 int level, Writer* writer);
208
209 void appendMultiPolygonTaggedText(
210 const geom::MultiPolygon* multiPolygon,
211 int level, Writer* writer);
212
213 void appendGeometryCollectionTaggedText(
214 const geom::GeometryCollection* geometryCollection,
215 int level, Writer* writer);
216
217 void appendPointText(const geom::Coordinate* coordinate, int level,
218 Writer* writer);
219
220 void appendCoordinate(const geom::Coordinate* coordinate,
221 Writer* writer);
222
223 std::string writeNumber(double d) const;
224
225 void appendLineStringText(
226 const geom::LineString* lineString,
227 int level, bool doIndent, Writer* writer);
228
229 void appendPolygonText(
230 const geom::Polygon* polygon,
231 int level, bool indentFirst, Writer* writer);
232
233 void appendMultiPointText(
234 const geom::MultiPoint* multiPoint,
235 int level, Writer* writer);
236
237 void appendMultiLineStringText(
238 const geom::MultiLineString* multiLineString,
239 int level, bool indentFirst, Writer* writer);
240
241 void appendMultiPolygonText(
242 const geom::MultiPolygon* multiPolygon,
243 int level, Writer* writer);
244
245 void appendGeometryCollectionText(
246 const geom::GeometryCollection* geometryCollection,
247 int level, Writer* writer);
248
249private:
250
251 enum {
252 INDENT = 2
253 };
254
255// static const int INDENT = 2;
256
257 bool isFormatted;
258
259 int roundingPrecision;
260
261 bool trim;
262
263 int level;
264
265 uint8_t defaultOutputDimension;
266 uint8_t outputDimension;
267 bool old3D;
268
269 void writeFormatted(
270 const geom::Geometry* geometry,
271 bool isFormatted, Writer* writer);
272
273 void indent(int level, Writer* writer) const;
274};
275
276} // namespace geos::io
277} // namespace geos
278
279#ifdef _MSC_VER
280#pragma warning(pop)
281#endif
282
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:52
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: LineString.h:66
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:55
Models a collection of LineStrings.
Definition: MultiLineString.h:50
Definition: MultiPoint.h:51
Definition: MultiPolygon.h:59
Represents a linear polygon, which may include holes.
Definition: Polygon.h:61
Outputs the textual representation of a Geometry. See also WKTReader.
Definition: WKTWriter.h:80
static std::string toPoint(const geom::Coordinate &p0)
static std::string toLineString(const geom::Coordinate &p0, const geom::Coordinate &p1)
void setOld3D(bool useOld3D)
Definition: WKTWriter.h:154
void setTrim(bool p0)
void setRoundingPrecision(int p0)
std::string write(const geom::Geometry *geometry)
Returns WKT string for the given Geometry.
static std::string toLineString(const geom::CoordinateSequence &seq)
Basic namespace for all GEOS functionalities.
Definition: geos.h:39