GEOS  3.9.1dev
WKTWriter.h
Go to the documentation of this file.
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 #ifndef GEOS_IO_WKTWRITER_H
22 #define GEOS_IO_WKTWRITER_H
23 
24 #include <geos/export.h>
25 
26 #include <string>
27 #include <cctype>
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
35 namespace geos {
36 namespace geom {
37 class Coordinate;
38 class CoordinateSequence;
39 class Geometry;
40 class GeometryCollection;
41 class Point;
42 class LineString;
43 class LinearRing;
44 class Polygon;
45 class MultiPoint;
46 class MultiLineString;
47 class MultiPolygon;
48 class PrecisionModel;
49 }
50 namespace io {
51 class Writer;
52 }
53 }
54 
55 
56 namespace geos {
57 namespace io {
58 
81 public:
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 
133  void setRoundingPrecision(int p0);
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
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 
179 protected:
180 
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);
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 
249 private:
250 
251  enum {
252  INDENT = 2
253  };
254 
255 // static const int INDENT = 2;
256 
258 
260 
261  bool trim;
262 
263  int level;
264 
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);
274 };
275 
276 } // namespace geos::io
277 } // namespace geos
278 
279 #ifdef _MSC_VER
280 #pragma warning(pop)
281 #endif
282 
283 #endif // #ifndef GEOS_IO_WKTWRITER_H
#define GEOS_DLL
Definition: export.h:28
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
uint8_t defaultOutputDimension
Definition: WKTWriter.h:265
uint8_t outputDimension
Definition: WKTWriter.h:266
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Represents a linear polygon, which may include holes.
Definition: Polygon.h:64
Outputs the textual representation of a Geometry. See also WKTReader.
Definition: WKTWriter.h:80
Represents a collection of heterogeneous Geometry objects.
Basic namespace for all GEOS functionalities.
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple...
Definition: LinearRing.h:54
The internal representation of a list of coordinates inside a Geometry.
int getOutputDimension() const
Definition: WKTWriter.h:165
void setOld3D(bool useOld3D)
Definition: WKTWriter.h:154
Models a collection of LineStrings.