GEOS 3.4.2

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

WKTWriter.h
1 /**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
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 setOld3D(bool useOld3D ) { old3D = useOld3D; }
153
154 /*
155 * \brief
156 * Returns the output dimension used by the
157 * <code>WKBWriter</code>.
158 */
159 int getOutputDimension() const { return defaultOutputDimension; }
160
161 /*
162 * Sets the output dimension used by the <code>WKBWriter</code>.
163 *
164 * @param newOutputDimension Supported values are 2 or 3.
165 * Note that 3 indicates up to 3 dimensions will be
166 * written but 2D WKB is still produced for 2D geometries.
167 */
168 void setOutputDimension(int newOutputDimension);
169
170 protected:
171
172 int decimalPlaces;
173
174 void appendGeometryTaggedText(const geom::Geometry *geometry, int level, Writer *writer);
175
176 void appendPointTaggedText(
177 const geom::Coordinate* coordinate,
178 int level, Writer *writer);
179
180 void appendLineStringTaggedText(
181 const geom::LineString *lineString,
182 int level, Writer *writer);
183
184 void appendLinearRingTaggedText(
185 const geom::LinearRing *lineString,
186 int level, Writer *writer);
187
188 void appendPolygonTaggedText(
189 const geom::Polygon *polygon,
190 int level, Writer *writer);
191
192 void appendMultiPointTaggedText(
193 const geom::MultiPoint *multipoint,
194 int level, Writer *writer);
195
196 void appendMultiLineStringTaggedText(
197 const geom::MultiLineString *multiLineString,
198 int level,Writer *writer);
199
200 void appendMultiPolygonTaggedText(
201 const geom::MultiPolygon *multiPolygon,
202 int level, Writer *writer);
203
204 void appendGeometryCollectionTaggedText(
205 const geom::GeometryCollection *geometryCollection,
206 int level,Writer *writer);
207
208 void appendPointText(const geom::Coordinate* coordinate, int level,
209 Writer *writer);
210
211 void appendCoordinate(const geom::Coordinate* coordinate,
212 Writer *writer);
213
214 std::string writeNumber(double d);
215
216 void appendLineStringText(
217 const geom::LineString *lineString,
218 int level, bool doIndent, Writer *writer);
219
220 void appendPolygonText(
221 const geom::Polygon *polygon,
222 int level, bool indentFirst, Writer *writer);
223
224 void appendMultiPointText(
225 const geom::MultiPoint *multiPoint,
226 int level, Writer *writer);
227
228 void appendMultiLineStringText(
229 const geom::MultiLineString *multiLineString,
230 int level, bool indentFirst,Writer *writer);
231
232 void appendMultiPolygonText(
233 const geom::MultiPolygon *multiPolygon,
234 int level, Writer *writer);
235
236 void appendGeometryCollectionText(
237 const geom::GeometryCollection *geometryCollection,
238 int level,Writer *writer);
239
240 private:
241
242 enum {
243 INDENT = 2
244 };
245
246 // static const int INDENT = 2;
247
248 bool isFormatted;
249
250 int roundingPrecision;
251
252 bool trim;
253
254 int level;
255
256 int defaultOutputDimension;
257 int outputDimension;
258 bool old3D;
259
260 void writeFormatted(
261 const geom::Geometry *geometry,
262 bool isFormatted, Writer *writer);
263
264 void indent(int level, Writer *writer);
265 };
266
267 } // namespace geos::io
268 } // namespace geos
269
270 #ifdef _MSC_VER
271 #pragma warning(pop)
272 #endif
273
274 #endif // #ifndef GEOS_IO_WKTWRITER_H