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
28#ifdef _MSC_VER
29#pragma warning(push)
30#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
31#endif
32
33// Forward declarations
34namespace geos {
35namespace geom {
36class Coordinate;
37class CoordinateSequence;
38class Geometry;
39class GeometryCollection;
40class Point;
41class LineString;
42class LinearRing;
43class Polygon;
44class MultiPoint;
45class MultiLineString;
46class MultiPolygon;
47class PrecisionModel;
48}
49namespace io {
50class Writer;
51}
52}
53
54
55namespace geos {
56namespace io {
57
79class GEOS_DLL WKTWriter {
80public:
81 WKTWriter();
82 ~WKTWriter() = default;
83
84 //string(count, ch) can be used for this
85 //static string stringOfChar(char ch, int count);
86
88 std::string write(const geom::Geometry* geometry);
89
90 // Send Geometry's WKT to the given Writer
91 void write(const geom::Geometry* geometry, Writer* writer);
92
93 std::string writeFormatted(const geom::Geometry* geometry);
94
95 void writeFormatted(const geom::Geometry* geometry, Writer* writer);
96
104 static std::string toLineString(const geom::CoordinateSequence& seq);
105
114 static std::string toLineString(const geom::Coordinate& p0, const geom::Coordinate& p1);
115
123 static std::string toPoint(const geom::Coordinate& p0);
124
133
140 void setTrim(bool p0);
141
152 void
153 setOld3D(bool useOld3D)
154 {
155 old3D = useOld3D;
156 }
157
158 /*
159 * \brief
160 * Returns the output dimension used by the
161 * <code>WKBWriter</code>.
162 */
163 int
164 getOutputDimension() const
165 {
166 return defaultOutputDimension;
167 }
168
169 /*
170 * Sets the output dimension used by the <code>WKBWriter</code>.
171 *
172 * @param newOutputDimension Supported values are 2 or 3.
173 * Note that 3 indicates up to 3 dimensions will be
174 * written but 2D WKB is still produced for 2D geometries.
175 */
176 void setOutputDimension(uint8_t newOutputDimension);
177
178protected:
179
180 int decimalPlaces;
181
182 void appendGeometryTaggedText(const geom::Geometry* geometry, int level, Writer* writer);
183
184 void appendPointTaggedText(
185 const geom::Coordinate* coordinate,
186 int level, Writer* writer);
187
188 void appendLineStringTaggedText(
189 const geom::LineString* lineString,
190 int level, Writer* writer);
191
192 void appendLinearRingTaggedText(
193 const geom::LinearRing* lineString,
194 int level, Writer* writer);
195
196 void appendPolygonTaggedText(
197 const geom::Polygon* polygon,
198 int level, Writer* writer);
199
200 void appendMultiPointTaggedText(
201 const geom::MultiPoint* multipoint,
202 int level, Writer* writer);
203
204 void appendMultiLineStringTaggedText(
205 const geom::MultiLineString* multiLineString,
206 int level, Writer* writer);
207
208 void appendMultiPolygonTaggedText(
209 const geom::MultiPolygon* multiPolygon,
210 int level, Writer* writer);
211
212 void appendGeometryCollectionTaggedText(
213 const geom::GeometryCollection* geometryCollection,
214 int level, Writer* writer);
215
216 void appendPointText(const geom::Coordinate* coordinate, int level,
217 Writer* writer);
218
219 void appendCoordinate(const geom::Coordinate* coordinate,
220 Writer* writer);
221
222 std::string writeNumber(double d) const;
223
224 void appendLineStringText(
225 const geom::LineString* lineString,
226 int level, bool doIndent, Writer* writer);
227
228 void appendPolygonText(
229 const geom::Polygon* polygon,
230 int level, bool indentFirst, Writer* writer);
231
232 void appendMultiPointText(
233 const geom::MultiPoint* multiPoint,
234 int level, Writer* writer);
235
236 void appendMultiLineStringText(
237 const geom::MultiLineString* multiLineString,
238 int level, bool indentFirst, Writer* writer);
239
240 void appendMultiPolygonText(
241 const geom::MultiPolygon* multiPolygon,
242 int level, Writer* writer);
243
244 void appendGeometryCollectionText(
245 const geom::GeometryCollection* geometryCollection,
246 int level, Writer* writer);
247
248private:
249
250 enum {
251 INDENT = 2
252 };
253
254// static const int INDENT = 2;
255
256 bool isFormatted;
257
258 int roundingPrecision;
259
260 bool trim;
261
262 int level;
263
264 uint8_t defaultOutputDimension;
265 uint8_t outputDimension;
266 bool old3D;
267
268 void writeFormatted(
269 const geom::Geometry* geometry,
270 bool isFormatted, Writer* writer);
271
272 void indent(int level, Writer* writer) const;
273};
274
275} // namespace geos::io
276} // namespace geos
277
278#ifdef _MSC_VER
279#pragma warning(pop)
280#endif
281
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:79
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:153
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