GEOS 3.14.0dev
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#include <geos/io/OrdinateSet.h>
25
26#include <string>
27#include <cctype>
28#include <cstdint>
29
30#ifdef _MSC_VER
31#pragma warning(push)
32#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
33#endif
34
35// Forward declarations
36namespace geos {
37namespace geom {
38class Coordinate;
39class CoordinateXY;
40class CoordinateXYZM;
41class CoordinateSequence;
42class Curve;
43class CompoundCurve;
44class Geometry;
45class GeometryCollection;
46class Point;
47class LineString;
48class LinearRing;
49class Polygon;
50class MultiPoint;
51class MultiLineString;
52class MultiPolygon;
53class PrecisionModel;
54class SimpleCurve;
55class Surface;
56}
57namespace io {
58class Writer;
59}
60}
61
62
63namespace geos {
64namespace io {
65
87class GEOS_DLL WKTWriter {
88public:
89 WKTWriter();
90 ~WKTWriter() = default;
91
92 //string(count, ch) can be used for this
93 //static string stringOfChar(char ch, int count);
94
96 std::string write(const geom::Geometry* geometry);
97
98 std::string write(const geom::Geometry& geometry);
99
100 // Send Geometry's WKT to the given Writer
101 void write(const geom::Geometry* geometry, Writer* writer);
102
103 std::string writeFormatted(const geom::Geometry* geometry);
104
105 void writeFormatted(const geom::Geometry* geometry, Writer* writer);
106
114 static std::string toLineString(const geom::CoordinateSequence& seq);
115
124 static std::string toLineString(const geom::CoordinateXY& p0, const geom::CoordinateXY& p1);
125
133 static std::string toPoint(const geom::Coordinate& p0);
134 static std::string toPoint(const geom::CoordinateXY& p0);
135
144
151 void setTrim(bool p0);
152
160 void setRemoveEmptyDimensions(bool remove)
161 {
162 removeEmptyDimensions = remove;
163 }
164
175 void
176 setOld3D(bool useOld3D)
177 {
178 old3D = useOld3D;
179 }
180
181 /*
182 * \brief
183 * Returns the output dimension used by the
184 * <code>WKTWriter</code>.
185 */
186 int
187 getOutputDimension() const
188 {
189 return defaultOutputDimension;
190 }
191
192 /*
193 * Sets the output dimension used by the <code>WKTWriter</code>.
194 *
195 * @param newOutputDimension Supported values are 2, 3 or 4.
196 * Default since GEOS 3.12 is 4.
197 * Note that 3 indicates up to 3 dimensions will be
198 * written but 2D WKT is still produced for 2D geometries.
199 */
200 void setOutputDimension(uint8_t newOutputDimension);
201
202 static std::string writeNumber(double d, bool trim, uint32_t precision);
203 static int writeTrimmedNumber(double d, uint32_t precision, char* buf);
204
205protected:
206
207 int decimalPlaces;
208
209 void appendGeometryTaggedText(
210 const geom::Geometry& geometry,
211 OrdinateSet outputOrdinates,
212 int level,
213 Writer& writer) const;
214
215 void appendTag(
216 const geom::Geometry& geometry,
217 OrdinateSet outputOrdinates,
218 Writer& writer) const;
219
220 void appendPointTaggedText(
221 const geom::Point& point,
222 OrdinateSet outputOrdinates,
223 int level, Writer& writer) const;
224
225 void appendSimpleCurveTaggedText(
226 const geom::SimpleCurve& lineString,
227 OrdinateSet outputOrdinates,
228 int level, Writer& writer) const;
229
230 void appendCompoundCurveTaggedText(
231 const geom::CompoundCurve& lineString,
232 OrdinateSet outputOrdinates,
233 int level, Writer& writer) const;
234
235 void appendSurfaceTaggedText(
236 const geom::Surface& polygon,
237 OrdinateSet outputOrdinates,
238 int level, Writer& writer) const;
239
240 void appendMultiPointTaggedText(
241 const geom::MultiPoint& multipoint,
242 OrdinateSet outputOrdinates,
243 int level, Writer& writer) const;
244
245 void appendMultiCurveTaggedText(
246 const geom::GeometryCollection& multiCurve,
247 OrdinateSet outputOrdinates,
248 int level, Writer& writer) const;
249
250 void appendMultiSurfaceTaggedText(
251 const geom::GeometryCollection& multiSurface,
252 OrdinateSet outputOrdinates,
253 int level, Writer& writer) const;
254
255 void appendGeometryCollectionTaggedText(
256 const geom::GeometryCollection& geometryCollection,
257 OrdinateSet outputOrdinates,
258 int level, Writer& writer) const;
259
260 void appendOrdinateText(OrdinateSet outputOrdinates,
261 Writer& writer) const;
262
263 void appendSequenceText(const geom::CoordinateSequence& seq,
264 OrdinateSet outputOrdinates,
265 int level,
266 bool doIntent,
267 Writer& writer) const;
268
269 void appendCoordinate(const geom::CoordinateXYZM& coordinate,
270 OrdinateSet outputOrdinates,
271 Writer& writer) const;
272
273 std::string writeNumber(double d) const;
274
275 void appendCurveText(
276 const geom::Curve& lineString,
277 OrdinateSet outputOrdinates,
278 int level, bool doIndent, Writer& writer) const;
279
280 void appendSimpleCurveText(
281 const geom::SimpleCurve& lineString,
282 OrdinateSet outputOrdinates,
283 int level, bool doIndent, Writer& writer) const;
284
285 void appendSurfaceText(
286 const geom::Surface& polygon,
287 OrdinateSet outputOrdinates,
288 int level, bool indentFirst, Writer& writer) const;
289
290 void appendMultiPointText(
291 const geom::MultiPoint& multiPoint,
292 OrdinateSet outputOrdinates,
293 int level, Writer& writer) const;
294
295 void appendMultiCurveText(
296 const geom::GeometryCollection& multiCurve,
297 OrdinateSet outputOrdinates,
298 int level, bool indentFirst, Writer& writer) const;
299
300 void appendMultiSurfaceText(
301 const geom::GeometryCollection& multiSurface,
302 OrdinateSet outputOrdinates,
303 int level, Writer& writer) const;
304
305 void appendGeometryCollectionText(
306 const geom::GeometryCollection& geometryCollection,
307 OrdinateSet outputOrdinates,
308 int level, Writer& writer) const;
309
310private:
311
312 enum {
313 INDENT = 2
314 };
315
316 bool isFormatted;
317
318 int roundingPrecision;
319
320 bool trim;
321
322 bool removeEmptyDimensions = false;
323
324 static constexpr int coordsPerLine = 10;
325
326 uint8_t defaultOutputDimension;
327 bool old3D;
328
329 void writeFormatted(
330 const geom::Geometry* geometry,
331 bool isFormatted, Writer* writer);
332
333 void indent(int level, Writer* writer) const;
334};
335
336} // namespace geos::io
337} // namespace geos
338
339#ifdef _MSC_VER
340#pragma warning(pop)
341#endif
342
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
Represents a collection of heterogeneous Geometry objects.
Definition GeometryCollection.h:51
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
Definition MultiPoint.h:50
Definition Point.h:61
Definition Surface.h:27
Outputs the textual representation of a Geometry. See also WKTReader.
Definition WKTWriter.h:87
static std::string toPoint(const geom::Coordinate &p0)
void setOld3D(bool useOld3D)
Definition WKTWriter.h:176
void setTrim(bool p0)
void setRoundingPrecision(int p0)
static std::string toLineString(const geom::CoordinateXY &p0, const geom::CoordinateXY &p1)
std::string write(const geom::Geometry *geometry)
Returns WKT string for the given Geometry.
void setRemoveEmptyDimensions(bool remove)
setRemoveEmptyDimensions
Definition WKTWriter.h:160
static std::string toLineString(const geom::CoordinateSequence &seq)
Basic namespace for all GEOS functionalities.
Definition geos.h:39