GEOS  3.8.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 #ifndef GEOS_IO_WKTWRITER_H
22 #define GEOS_IO_WKTWRITER_H
23 
24 #include <geos/export.h>
25 
26 #include <string>
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
34 namespace geos {
35 namespace geom {
36 class Coordinate;
37 class CoordinateSequence;
38 class Geometry;
39 class GeometryCollection;
40 class Point;
41 class LineString;
42 class LinearRing;
43 class Polygon;
44 class MultiPoint;
45 class MultiLineString;
46 class MultiPolygon;
47 class PrecisionModel;
48 }
49 namespace io {
50 class Writer;
51 }
52 }
53 
54 
55 namespace geos {
56 namespace io {
57 
79 class GEOS_DLL WKTWriter {
80 public:
81  WKTWriter();
82  ~WKTWriter();
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 
132  void setRoundingPrecision(int p0);
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(int newOutputDimension);
177 
178 protected:
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);
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 
248 private:
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  int defaultOutputDimension;
265  int 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);
273 };
274 
275 } // namespace geos::io
276 } // namespace geos
277 
278 #ifdef _MSC_VER
279 #pragma warning(pop)
280 #endif
281 
282 #endif // #ifndef GEOS_IO_WKTWRITER_H
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Models a collection of Polygons.
Definition: MultiPolygon.h:59
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:187
Definition: LineString.h:69
Represents a linear polygon, which may include holes.
Definition: Polygon.h:65
Outputs the textual representation of a Geometry. See also WKTReader.
Definition: WKTWriter.h:79
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:55
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
Definition: MultiPoint.h:54
Models an OGC SFS LinearRing.
Definition: LinearRing.h:56
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
void setOld3D(bool useOld3D)
Definition: WKTWriter.h:153
Models a collection of (}s.
Definition: MultiLineString.h:51