GEOS: WKTWriter.h Source File

GEOS 3.3.8

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

- File List

WKTWriter.h
1 /**********************************************************************
2 * $Id: WKTWriter.h 3293 2011-04-22 13:51:38Z strk $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
8 * Copyright (C) 2005-2006 Refractions Research Inc.
9 * Copyright (C) 2001-2002 Vivid Solutions Inc.
10 *
11 * This is free software; you can redistribute and/or modify it under
12 * the terms of the GNU Lesser General Public Licence as published
13 * by the Free Software Foundation.
14 * See the COPYING file for more information.
15 *
16 **********************************************************************
17 *
18 * Last port: io/WKTWriter.java rev. 1.34 (JTS-1.7)
19 *
20 **********************************************************************/
21
22 #ifndef GEOS_IO_WKTWRITER_H
23 #define GEOS_IO_WKTWRITER_H
24
25 #include <geos/export.h>
26
27 #include <string>
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
80 class GEOS_DLL WKTWriter {
81 public:
82 WKTWriter();
83 ~WKTWriter();
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 setOld3D(bool useOld3D ) { old3D = useOld3D; }
154
155 /*
156 * \brief
157 * Returns the output dimension used by the
158 * <code>WKBWriter</code>.
159 */
160 int getOutputDimension() const { return defaultOutputDimension; }
161
162 /*
163 * Sets the output dimension used by the <code>WKBWriter</code>.
164 *
165 * @param newOutputDimension Supported values are 2 or 3.
166 * Note that 3 indicates up to 3 dimensions will be
167 * written but 2D WKB is still produced for 2D geometries.
168 */
169 void setOutputDimension(int newOutputDimension);
170
171 protected:
172
173 int decimalPlaces;
174
175 void appendGeometryTaggedText(const geom::Geometry *geometry, int level, Writer *writer);
176
177 void appendPointTaggedText(
178 const geom::Coordinate* coordinate,
179 int level, Writer *writer);
180
181 void appendLineStringTaggedText(
182 const geom::LineString *lineString,
183 int level, Writer *writer);
184
185 void appendLinearRingTaggedText(
186 const geom::LinearRing *lineString,
187 int level, Writer *writer);
188
189 void appendPolygonTaggedText(
190 const geom::Polygon *polygon,
191 int level, Writer *writer);
192
193 void appendMultiPointTaggedText(
194 const geom::MultiPoint *multipoint,
195 int level, Writer *writer);
196
197 void appendMultiLineStringTaggedText(
198 const geom::MultiLineString *multiLineString,
199 int level,Writer *writer);
200
201 void appendMultiPolygonTaggedText(
202 const geom::MultiPolygon *multiPolygon,
203 int level, Writer *writer);
204
205 void appendGeometryCollectionTaggedText(
206 const geom::GeometryCollection *geometryCollection,
207 int level,Writer *writer);
208
209 void appendPointText(const geom::Coordinate* coordinate, int level,
210 Writer *writer);
211
212 void appendCoordinate(const geom::Coordinate* coordinate,
213 Writer *writer);
214
215 std::string writeNumber(double d);
216
217 void appendLineStringText(
218 const geom::LineString *lineString,
219 int level, bool doIndent, Writer *writer);
220
221 void appendPolygonText(
222 const geom::Polygon *polygon,
223 int level, bool indentFirst, Writer *writer);
224
225 void appendMultiPointText(
226 const geom::MultiPoint *multiPoint,
227 int level, Writer *writer);
228
229 void appendMultiLineStringText(
230 const geom::MultiLineString *multiLineString,
231 int level, bool indentFirst,Writer *writer);
232
233 void appendMultiPolygonText(
234 const geom::MultiPolygon *multiPolygon,
235 int level, Writer *writer);
236
237 void appendGeometryCollectionText(
238 const geom::GeometryCollection *geometryCollection,
239 int level,Writer *writer);
240
241 private:
242
243 enum {
244 INDENT = 2
245 };
246
247 // static const int INDENT = 2;
248
249 bool isFormatted;
250
251 int roundingPrecision;
252
253 bool trim;
254
255 int level;
256
257 int defaultOutputDimension;
258 int outputDimension;
259 bool old3D;
260
261 void writeFormatted(
262 const geom::Geometry *geometry,
263 bool isFormatted, Writer *writer);
264
265 void indent(int level, Writer *writer);
266 };
267
268 } // namespace geos::io
269 } // namespace geos
270
271 #ifdef _MSC_VER
272 #pragma warning(pop)
273 #endif
274
275 #endif // #ifndef GEOS_IO_WKTWRITER_H
276
277 /**********************************************************************
278 * $Log$
279 * Revision 1.3 2006/06/12 16:55:53 strk
280 * fixed compiler warnings, fixed some methods to omit unused parameters.
281 *
282 * Revision 1.2 2006/03/22 16:58:35 strk
283 * Removed (almost) all inclusions of geom.h.
284 * Removed obsoleted .cpp files.
285 * Fixed a bug in WKTReader not using the provided CoordinateSequence
286 * implementation, optimized out some memory allocations.
287 *
288 * Revision 1.1 2006/03/20 18:18:15 strk
289 * io.h header split
290 *
291 **********************************************************************/