kiwi-postgis  Version 0.1.0.0
SVGWriter Class Reference

Writes the Well-Known Text representation of a Geometry. More...

Collaboration diagram for SVGWriter:

Public Member Functions

 SVGWriter ()
 Creates a new SVGWriter with default settings. More...
 
String write (Geometry geometry)
 Converts a Geometry to its Well-known Text representation. More...
 
void write (Geometry geometry, Writer writer) throws IOException
 Converts a Geometry to its Well-known Text representation. More...
 
String writeFormatted (Geometry geometry)
 Same as write, but with newlines and spaces to make the well-known text more readable. More...
 
void writeFormatted (Geometry geometry, Writer writer) throws IOException
 Same as write, but with newlines and spaces to make the well-known text more readable. More...
 

Static Public Member Functions

static String stringOfChar (char ch, int count)
 Returns a String of repeated characters. More...
 

Private Member Functions

void writeFormatted (Geometry geometry, boolean useFormatting, Writer writer) throws IOException
 Converts a Geometry to its Well-known Text representation. More...
 
void appendGeometryTaggedText (Geometry geometry, int level, Writer writer) throws IOException
 Converts a Geometry to <Geometry Tagged Text> format, then appends it to the writer. More...
 
void appendPointTaggedText (Coordinate coordinate, int level, Writer writer, PrecisionModel precisionModel) throws IOException
 Converts a Coordinate to <Point Tagged Text> format, then appends it to the writer. More...
 
void appendLineStringTaggedText (LineString lineString, int level, Writer writer) throws IOException
 Converts a LineString to <LineString Tagged Text> format, then appends it to the writer. More...
 
void appendLinearRingTaggedText (LinearRing linearRing, int level, Writer writer) throws IOException
 Converts a LinearRing to <LinearRing Tagged Text> format, then appends it to the writer. More...
 
void appendPolygon (Polygon polygon, int level, Writer writer) throws IOException
 Converts a Polygon to <Polygon Tagged Text> format, then appends it to the writer. More...
 
void appendMultiPointTaggedText (MultiPoint multipoint, int level, Writer writer) throws IOException
 Converts a MultiPoint to <MultiPoint Tagged Text> format, then appends it to the writer. More...
 
void appendMultiLineStringTaggedText (MultiLineString multiLineString, int level, Writer writer) throws IOException
 Converts a MultiLineString to <MultiLineString Tagged Text> format, then appends it to the writer. More...
 
void appendMultiPolygonTaggedText (MultiPolygon multiPolygon, int level, Writer writer) throws IOException
 Converts a MultiPolygon to <MultiPolygon Tagged Text> format, then appends it to the writer. More...
 
void appendGeometryCollectionTaggedText (GeometryCollection geometryCollection, int level, Writer writer) throws IOException
 Converts a GeometryCollection to <GeometryCollection Tagged Text> format, then appends it to the writer. More...
 
void appendPoint (Coordinate coordinate, int level, Writer writer, PrecisionModel precisionModel) throws IOException
 Converts a Coordinate to <Point Text> format, then appends it to the writer. More...
 
void appendCoordinate (CoordinateSequence seq, int i, Writer writer) throws IOException
 Appends the i'th coordinate from the sequence to the writer. More...
 
void appendCoordinate (Coordinate coordinate, Writer writer) throws IOException
 Converts a Coordinate to <Point> format, then appends it to the writer. More...
 
String writeNumber (double d)
 Converts a double to a String, not in scientific notation. More...
 
void appendSequencePath (CoordinateSequence seq, int level, boolean doIndent, Writer writer) throws IOException
 Converts a LineString to <LineString Text> format, then appends it to the writer. More...
 
void appendSequencePoints (CoordinateSequence seq, int level, boolean doIndent, Writer writer) throws IOException
 
void appendLineString (LineString lineString, int level, boolean doIndent, Writer writer) throws IOException
 Converts a LineString to <LineString Text> format, then appends it to the writer. More...
 
void appendPolygonPolygon (Polygon polygon, int level, boolean indentFirst, Writer writer) throws IOException
 Converts a Polygon to <Polygon Text> format, then appends it to the writer. More...
 
void appendPolygonPath (Polygon polygon, int level, boolean indentFirst, Writer writer) throws IOException
 
void appendPathStart (boolean useFillRule, Writer writer) throws IOException
 
void appendPathEnd (Writer writer) throws IOException
 
void appendMultiPointText (MultiPoint multiPoint, int level, Writer writer) throws IOException
 Converts a MultiPoint to <MultiPoint Text> format, then appends it to the writer. More...
 
void appendMultiLineStringText (MultiLineString multiLineString, int level, boolean indentFirst, Writer writer) throws IOException
 Converts a MultiLineString to <MultiLineString Text> format, then appends it to the writer. More...
 
void appendMultiPolygonText (MultiPolygon multiPolygon, int level, Writer writer) throws IOException
 Converts a MultiPolygon to <MultiPolygon Text> format, then appends it to the writer. More...
 
void appendGeometryCollectionText (GeometryCollection geometryCollection, int level, Writer writer) throws IOException
 Converts a GeometryCollection to <GeometryCollectionText> format, then appends it to the writer. More...
 
void indentCoords (int coordIndex, int level, Writer writer) throws IOException
 
void indent (int level, Writer writer) throws IOException
 

Static Private Member Functions

static DecimalFormat createFormatter (PrecisionModel precisionModel)
 Creates the DecimalFormat used to write doubles with a sufficient number of decimal places. More...
 

Private Attributes

int outputDimension = 2
 
DecimalFormat formatter
 
boolean isFormatted = false
 
boolean useFormatting = false
 
int level = 0
 
int coordsPerLine = -1
 
String indentTabStr = " "
 

Static Private Attributes

static final int INDENT = 2
 

Detailed Description

Writes the Well-Known Text representation of a Geometry.

The Well-Known Text format is defined in the OGC Simple Features Specification for SQL. See WKTReader for a formal specification of the format syntax.

The WKTWriter outputs coordinates rounded to the precision model. Only the maximum number of decimal places necessary to represent the ordinates to the required precision will be output.

The SFS WKT spec does not define a special tag for LinearRings. Under the spec, rings are output as LINESTRINGs. In order to allow precisely specifying constructed geometries, JTS also supports a non-standard LINEARRING tag which is used to output LinearRings.

Version
1.7
See also
WKTReader

Constructor & Destructor Documentation

◆ SVGWriter()

SVGWriter ( )

Creates a new SVGWriter with default settings.

97  {
98  }

Member Function Documentation

◆ appendCoordinate() [1/2]

void appendCoordinate ( CoordinateSequence  seq,
int  i,
Writer  writer 
) throws IOException
private

Appends the i'th coordinate from the sequence to the writer.

Parameters
seqthe CoordinateSequence to process
ithe index of the coordinate to write
writerthe output writer to append to

References SVGWriter.writeNumber().

Referenced by SVGWriter.appendSequencePath(), and SVGWriter.appendSequencePoints().

360  {
361  writer.write(writeNumber(seq.getX(i)) + "," + writeNumber(seq.getY(i)));
362  }
String writeNumber(double d)
Converts a double to a String, not in scientific notation.
Definition: SVGWriter.java:389

◆ appendCoordinate() [2/2]

void appendCoordinate ( Coordinate  coordinate,
Writer  writer 
) throws IOException
private

Converts a Coordinate to <Point> format, then appends it to the writer.

Parameters
coordinatethe Coordinate to process
writerthe output writer to append to

References SVGWriter.writeNumber().

373  {
374  writer.write(writeNumber(coordinate.x) + " " + writeNumber(coordinate.y));
375  if (outputDimension >= 3 && ! Double.isNaN(coordinate.z)) {
376  writer.write(" ");
377  writer.write(writeNumber(coordinate.z));
378  }
379  }
String writeNumber(double d)
Converts a double to a String, not in scientific notation.
Definition: SVGWriter.java:389
double y
The y-ordinate.
Definition: Coordinate.java:89
int outputDimension
Definition: SVGWriter.java:85
double x
The x-ordinate.
Definition: Coordinate.java:84
double z
The z-ordinate.
Definition: Coordinate.java:96

◆ appendGeometryCollectionTaggedText()

void appendGeometryCollectionTaggedText ( GeometryCollection  geometryCollection,
int  level,
Writer  writer 
) throws IOException
private

Converts a GeometryCollection to <GeometryCollection Tagged Text> format, then appends it to the writer.

Parameters
geometryCollectionthe GeometryCollection to process
writerthe output writer to append to

References SVGWriter.appendGeometryCollectionText().

Referenced by SVGWriter.appendGeometryTaggedText().

331  {
332  appendGeometryCollectionText(geometryCollection, level, writer);
333  }
int level
Definition: SVGWriter.java:89
void appendGeometryCollectionText(GeometryCollection geometryCollection, int level, Writer writer)
Converts a GeometryCollection to <GeometryCollectionText> format, then appends it to the writer...
Definition: SVGWriter.java:569

◆ appendGeometryCollectionText()

void appendGeometryCollectionText ( GeometryCollection  geometryCollection,
int  level,
Writer  writer 
) throws IOException
private

Converts a GeometryCollection to <GeometryCollectionText> format, then appends it to the writer.

Parameters
geometryCollectionthe GeometryCollection to process
writerthe output writer to append to

References SVGWriter.appendGeometryTaggedText(), and SVGWriter.level.

Referenced by SVGWriter.appendGeometryCollectionTaggedText().

572  {
573  int level2 = level;
574  for (int i = 0; i < geometryCollection.getNumGeometries(); i++) {
575  if (i > 0) {
576  level2 = level + 1;
577  }
578  appendGeometryTaggedText(geometryCollection.getGeometryN(i), level2, writer);
579  }
580  }
int level
Definition: SVGWriter.java:89
void appendGeometryTaggedText(Geometry geometry, int level, Writer writer)
Converts a Geometry to <Geometry Tagged Text> format, then appends it to the writer.
Definition: SVGWriter.java:183

◆ appendGeometryTaggedText()

void appendGeometryTaggedText ( Geometry  geometry,
int  level,
Writer  writer 
) throws IOException
private

Converts a Geometry to <Geometry Tagged Text> format, then appends it to the writer.

Parameters
geometrythe Geometry to process
writerthe output writer to append to

References SVGWriter.appendGeometryCollectionTaggedText(), SVGWriter.appendLinearRingTaggedText(), SVGWriter.appendLineStringTaggedText(), SVGWriter.appendMultiLineStringTaggedText(), SVGWriter.appendMultiPointTaggedText(), SVGWriter.appendMultiPolygonTaggedText(), SVGWriter.appendPointTaggedText(), SVGWriter.appendPolygon(), SVGWriter.indent(), and SVGWriter.level.

Referenced by SVGWriter.appendGeometryCollectionText(), and SVGWriter.writeFormatted().

185  {
186  indent(level, writer);
187 
188  if (geometry instanceof Point) {
189  Point point = (Point) geometry;
190  appendPointTaggedText(point.getCoordinate(), level, writer, point.getPrecisionModel());
191  }
192  else if (geometry instanceof LinearRing) {
193  appendLinearRingTaggedText((LinearRing) geometry, level, writer);
194  }
195  else if (geometry instanceof LineString) {
196  appendLineStringTaggedText((LineString) geometry, level, writer);
197  }
198  else if (geometry instanceof Polygon) {
199  appendPolygon((Polygon) geometry, level, writer);
200  }
201  else if (geometry instanceof MultiPoint) {
202  appendMultiPointTaggedText((MultiPoint) geometry, level, writer);
203  }
204  else if (geometry instanceof MultiLineString) {
205  appendMultiLineStringTaggedText((MultiLineString) geometry, level, writer);
206  }
207  else if (geometry instanceof MultiPolygon) {
208  appendMultiPolygonTaggedText((MultiPolygon) geometry, level, writer);
209  }
210  else if (geometry instanceof GeometryCollection) {
211  appendGeometryCollectionTaggedText((GeometryCollection) geometry, level, writer);
212  }
213  else {
214  Assert.shouldNeverReachHere("Unsupported Geometry implementation:"
215  + geometry.getClass());
216  }
217 
218 
219  }
void appendMultiPolygonTaggedText(MultiPolygon multiPolygon, int level, Writer writer)
Converts a MultiPolygon to <MultiPolygon Tagged Text> format, then appends it to the writer...
Definition: SVGWriter.java:315
void appendPolygon(Polygon polygon, int level, Writer writer)
Converts a Polygon to <Polygon Tagged Text> format, then appends it to the writer.
Definition: SVGWriter.java:270
void appendMultiPointTaggedText(MultiPoint multipoint, int level, Writer writer)
Converts a MultiPoint to <MultiPoint Tagged Text> format, then appends it to the writer.
Definition: SVGWriter.java:288
int level
Definition: SVGWriter.java:89
void appendMultiLineStringTaggedText(MultiLineString multiLineString, int level, Writer writer)
Converts a MultiLineString to <MultiLineString Tagged Text> format, then appends it to the writer...
Definition: SVGWriter.java:301
void appendGeometryCollectionTaggedText(GeometryCollection geometryCollection, int level, Writer writer)
Converts a GeometryCollection to <GeometryCollection Tagged Text> format, then appends it to the writ...
Definition: SVGWriter.java:328
void appendLinearRingTaggedText(LinearRing linearRing, int level, Writer writer)
Converts a LinearRing to <LinearRing Tagged Text> format, then appends it to the writer.
Definition: SVGWriter.java:257
void appendPointTaggedText(Coordinate coordinate, int level, Writer writer, PrecisionModel precisionModel)
Converts a Coordinate to <Point Tagged Text> format, then appends it to the writer.
Definition: SVGWriter.java:230
void appendLineStringTaggedText(LineString lineString, int level, Writer writer)
Converts a LineString to <LineString Tagged Text> format, then appends it to the writer.
Definition: SVGWriter.java:244
void indent(int level, Writer writer)
Definition: SVGWriter.java:591

◆ appendLinearRingTaggedText()

void appendLinearRingTaggedText ( LinearRing  linearRing,
int  level,
Writer  writer 
) throws IOException
private

Converts a LinearRing to <LinearRing Tagged Text> format, then appends it to the writer.

Parameters
linearRingthe LinearRing to process
writerthe output writer to append to

References SVGWriter.appendLineString().

Referenced by SVGWriter.appendGeometryTaggedText().

259  {
260  appendLineString(linearRing, level, false, writer);
261  }
int level
Definition: SVGWriter.java:89
void appendLineString(LineString lineString, int level, boolean doIndent, Writer writer)
Converts a LineString to <LineString Text> format, then appends it to the writer. ...
Definition: SVGWriter.java:448

◆ appendLineString()

void appendLineString ( LineString  lineString,
int  level,
boolean  doIndent,
Writer  writer 
) throws IOException
private

Converts a LineString to <LineString Text> format, then appends it to the writer.

Parameters
lineStringthe LineString to process
writerthe output writer to append to

References SVGWriter.appendSequencePoints(), SVGWriter.indent(), and SVGWriter.level.

Referenced by SVGWriter.appendLinearRingTaggedText(), SVGWriter.appendLineStringTaggedText(), and SVGWriter.appendMultiLineStringText().

450  {
451  if (doIndent) indent(level, writer);
452  writer.write("<polyline fill='none' points='");
453  appendSequencePoints(lineString.getCoordinateSequence(), level, doIndent, writer);
454  writer.write("'/>\n");
455  }
int level
Definition: SVGWriter.java:89
void appendSequencePoints(CoordinateSequence seq, int level, boolean doIndent, Writer writer)
Definition: SVGWriter.java:420
void indent(int level, Writer writer)
Definition: SVGWriter.java:591

◆ appendLineStringTaggedText()

void appendLineStringTaggedText ( LineString  lineString,
int  level,
Writer  writer 
) throws IOException
private

Converts a LineString to <LineString Tagged Text> format, then appends it to the writer.

Parameters
lineStringthe LineString to process
writerthe output writer to append to

References SVGWriter.appendLineString().

Referenced by SVGWriter.appendGeometryTaggedText().

246  {
247  appendLineString(lineString, level, false, writer);
248  }
int level
Definition: SVGWriter.java:89
void appendLineString(LineString lineString, int level, boolean doIndent, Writer writer)
Converts a LineString to <LineString Text> format, then appends it to the writer. ...
Definition: SVGWriter.java:448

◆ appendMultiLineStringTaggedText()

void appendMultiLineStringTaggedText ( MultiLineString  multiLineString,
int  level,
Writer  writer 
) throws IOException
private

Converts a MultiLineString to <MultiLineString Tagged Text> format, then appends it to the writer.

Parameters
multiLineStringthe MultiLineString to process
writerthe output writer to append to

References SVGWriter.appendMultiLineStringText().

Referenced by SVGWriter.appendGeometryTaggedText().

304  {
305  appendMultiLineStringText(multiLineString, level, false, writer);
306  }
int level
Definition: SVGWriter.java:89
void appendMultiLineStringText(MultiLineString multiLineString, int level, boolean indentFirst, Writer writer)
Converts a MultiLineString to <MultiLineString Text> format, then appends it to the writer...
Definition: SVGWriter.java:526

◆ appendMultiLineStringText()

void appendMultiLineStringText ( MultiLineString  multiLineString,
int  level,
boolean  indentFirst,
Writer  writer 
) throws IOException
private

Converts a MultiLineString to <MultiLineString Text> format, then appends it to the writer.

Parameters
multiLineStringthe MultiLineString to process
writerthe output writer to append to

References SVGWriter.appendLineString(), and SVGWriter.level.

Referenced by SVGWriter.appendMultiLineStringTaggedText().

529  {
530  int level2 = level;
531  boolean doIndent = indentFirst;
532  for (int i = 0; i < multiLineString.getNumGeometries(); i++) {
533  if (i > 0) {
534  level2 = level + 1;
535  doIndent = true;
536  }
537  appendLineString((LineString) multiLineString.getGeometryN(i), level2, doIndent, writer);
538  }
539  }
int level
Definition: SVGWriter.java:89
void appendLineString(LineString lineString, int level, boolean doIndent, Writer writer)
Converts a LineString to <LineString Text> format, then appends it to the writer. ...
Definition: SVGWriter.java:448

◆ appendMultiPointTaggedText()

void appendMultiPointTaggedText ( MultiPoint  multipoint,
int  level,
Writer  writer 
) throws IOException
private

Converts a MultiPoint to <MultiPoint Tagged Text> format, then appends it to the writer.

Parameters
multipointthe MultiPoint to process
writerthe output writer to append to

References SVGWriter.appendMultiPointText().

Referenced by SVGWriter.appendGeometryTaggedText().

290  {
291  appendMultiPointText(multipoint, level, writer);
292  }
void appendMultiPointText(MultiPoint multiPoint, int level, Writer writer)
Converts a MultiPoint to <MultiPoint Text> format, then appends it to the writer. ...
Definition: SVGWriter.java:502
int level
Definition: SVGWriter.java:89

◆ appendMultiPointText()

void appendMultiPointText ( MultiPoint  multiPoint,
int  level,
Writer  writer 
) throws IOException
private

Converts a MultiPoint to <MultiPoint Text> format, then appends it to the writer.

Parameters
multiPointthe MultiPoint to process
writerthe output writer to append to

References SVGWriter.appendPoint(), and SVGWriter.level.

Referenced by SVGWriter.appendMultiPointTaggedText().

504  {
505  if (multiPoint.isEmpty()) {
506  writer.write(" ");
507  }
508  else {
509  int level2 = level;
510  for (int i = 0; i < multiPoint.getNumGeometries(); i++) {
511  if (i > 0) {
512  level2 = level + 1;
513  }
514  appendPoint(multiPoint.getGeometryN(i).getCoordinate(), level2, writer, multiPoint.getPrecisionModel());
515  }
516  }
517  }
int level
Definition: SVGWriter.java:89
void appendPoint(Coordinate coordinate, int level, Writer writer, PrecisionModel precisionModel)
Converts a Coordinate to <Point Text> format, then appends it to the writer.
Definition: SVGWriter.java:344

◆ appendMultiPolygonTaggedText()

void appendMultiPolygonTaggedText ( MultiPolygon  multiPolygon,
int  level,
Writer  writer 
) throws IOException
private

Converts a MultiPolygon to <MultiPolygon Tagged Text> format, then appends it to the writer.

Parameters
multiPolygonthe MultiPolygon to process
writerthe output writer to append to

References SVGWriter.appendMultiPolygonText().

Referenced by SVGWriter.appendGeometryTaggedText().

317  {
318  appendMultiPolygonText(multiPolygon, level, writer);
319  }
int level
Definition: SVGWriter.java:89
void appendMultiPolygonText(MultiPolygon multiPolygon, int level, Writer writer)
Converts a MultiPolygon to <MultiPolygon Text> format, then appends it to the writer.
Definition: SVGWriter.java:548

◆ appendMultiPolygonText()

void appendMultiPolygonText ( MultiPolygon  multiPolygon,
int  level,
Writer  writer 
) throws IOException
private

Converts a MultiPolygon to <MultiPolygon Text> format, then appends it to the writer.

Parameters
multiPolygonthe MultiPolygon to process
writerthe output writer to append to

References SVGWriter.appendPolygon(), and SVGWriter.level.

Referenced by SVGWriter.appendMultiPolygonTaggedText().

550  {
551  int level2 = level;
552  boolean doIndent = false;
553  for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
554  if (i > 0) {
555  level2 = level + 1;
556  doIndent = true;
557  }
558  appendPolygon((Polygon) multiPolygon.getGeometryN(i), level2, writer);
559  }
560  }
void appendPolygon(Polygon polygon, int level, Writer writer)
Converts a Polygon to <Polygon Tagged Text> format, then appends it to the writer.
Definition: SVGWriter.java:270
int level
Definition: SVGWriter.java:89

◆ appendPathEnd()

void appendPathEnd ( Writer  writer) throws IOException
private
490  {
491  writer.write("' />\n");
492  }

◆ appendPathStart()

void appendPathStart ( boolean  useFillRule,
Writer  writer 
) throws IOException
private
486  {
487  String fillRule = useFillRule ? "fill-rule='evenodd' " : "";
488  writer.write("<path " + fillRule + "d='");
489  }

◆ appendPoint()

void appendPoint ( Coordinate  coordinate,
int  level,
Writer  writer,
PrecisionModel  precisionModel 
) throws IOException
private

Converts a Coordinate to <Point Text> format, then appends it to the writer.

Parameters
coordinatethe Coordinate to process
writerthe output writer to append to
precisionModelthe PrecisionModel to use to convert from a precise coordinate to an external coordinate

Referenced by SVGWriter.appendMultiPointText(), and SVGWriter.appendPointTaggedText().

347  {
348  writer.write("<circle cx='" + coordinate.x + "' cy='" + coordinate.y + "' r='1' />\n");
349  }
double y
The y-ordinate.
Definition: Coordinate.java:89
double x
The x-ordinate.
Definition: Coordinate.java:84

◆ appendPointTaggedText()

void appendPointTaggedText ( Coordinate  coordinate,
int  level,
Writer  writer,
PrecisionModel  precisionModel 
) throws IOException
private

Converts a Coordinate to <Point Tagged Text> format, then appends it to the writer.

Parameters
coordinatethe Coordinate to process
writerthe output writer to append to
precisionModelthe PrecisionModel to use to convert from a precise coordinate to an external coordinate

References SVGWriter.appendPoint().

Referenced by SVGWriter.appendGeometryTaggedText().

233  {
234  appendPoint(coordinate, level, writer, precisionModel);
235  }
int level
Definition: SVGWriter.java:89
void appendPoint(Coordinate coordinate, int level, Writer writer, PrecisionModel precisionModel)
Converts a Coordinate to <Point Text> format, then appends it to the writer.
Definition: SVGWriter.java:344

◆ appendPolygon()

void appendPolygon ( Polygon  polygon,
int  level,
Writer  writer 
) throws IOException
private

Converts a Polygon to <Polygon Tagged Text> format, then appends it to the writer.

Parameters
polygonthe Polygon to process
writerthe output writer to append to

References SVGWriter.appendPolygonPath(), and SVGWriter.appendPolygonPolygon().

Referenced by SVGWriter.appendGeometryTaggedText(), and SVGWriter.appendMultiPolygonText().

272  {
273  if (polygon.getNumInteriorRing() == 0) {
274  appendPolygonPolygon(polygon, level, false, writer);
275  }
276  else {
277  appendPolygonPath(polygon, level, false, writer);
278  }
279  }
int level
Definition: SVGWriter.java:89
void appendPolygonPolygon(Polygon polygon, int level, boolean indentFirst, Writer writer)
Converts a Polygon to <Polygon Text> format, then appends it to the writer.
Definition: SVGWriter.java:464
void appendPolygonPath(Polygon polygon, int level, boolean indentFirst, Writer writer)
Definition: SVGWriter.java:473

◆ appendPolygonPath()

void appendPolygonPath ( Polygon  polygon,
int  level,
boolean  indentFirst,
Writer  writer 
) throws IOException
private

References SVGWriter.appendSequencePath(), SVGWriter.indent(), and SVGWriter.level.

Referenced by SVGWriter.appendPolygon().

475  {
476  if (indentFirst) indent(level, writer);
477  writer.write("<path fill-rule='evenodd' d='");
478  appendSequencePath(polygon.getExteriorRing().getCoordinateSequence(), level, false, writer);
479  for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
480  writer.write(" ");
481  appendSequencePath(polygon.getInteriorRingN(i).getCoordinateSequence(), level + 1, true, writer);
482  }
483  writer.write("' />\n");
484  }
int level
Definition: SVGWriter.java:89
void appendSequencePath(CoordinateSequence seq, int level, boolean doIndent, Writer writer)
Converts a LineString to <LineString Text> format, then appends it to the writer. ...
Definition: SVGWriter.java:400
void indent(int level, Writer writer)
Definition: SVGWriter.java:591

◆ appendPolygonPolygon()

void appendPolygonPolygon ( Polygon  polygon,
int  level,
boolean  indentFirst,
Writer  writer 
) throws IOException
private

Converts a Polygon to <Polygon Text> format, then appends it to the writer.

Parameters
polygonthe Polygon to process
writerthe output writer to append to

References SVGWriter.appendSequencePoints(), SVGWriter.indent(), and SVGWriter.level.

Referenced by SVGWriter.appendPolygon().

466  {
467  if (indentFirst) indent(level, writer);
468  writer.write("<polygon points='");
469  appendSequencePoints(polygon.getExteriorRing().getCoordinateSequence(), level, false, writer);
470  writer.write("' />\n");
471  }
int level
Definition: SVGWriter.java:89
void appendSequencePoints(CoordinateSequence seq, int level, boolean doIndent, Writer writer)
Definition: SVGWriter.java:420
void indent(int level, Writer writer)
Definition: SVGWriter.java:591

◆ appendSequencePath()

void appendSequencePath ( CoordinateSequence  seq,
int  level,
boolean  doIndent,
Writer  writer 
) throws IOException
private

Converts a LineString to <LineString Text> format, then appends it to the writer.

Parameters
lineStringthe LineString to process
writerthe output writer to append to

References SVGWriter.appendCoordinate(), and SVGWriter.indent().

Referenced by SVGWriter.appendPolygonPath().

402  {
403  if (seq.size() == 0) {
404  //writer.write("EMPTY");
405  }
406  else {
407  if (doIndent) indent(level, writer);
408  for (int i = 0; i < seq.size(); i++) {
409  writer.write(" " + ((i == 0) ? "M" : "L"));
410  if (i > 0) {
411  if (coordsPerLine > 0
412  && i % coordsPerLine == 0) {
413  indent(level + 1, writer);
414  }
415  }
416  appendCoordinate(seq, i, writer);
417  }
418  }
419  }
void appendCoordinate(CoordinateSequence seq, int i, Writer writer)
Appends the i&#39;th coordinate from the sequence to the writer.
Definition: SVGWriter.java:358
int level
Definition: SVGWriter.java:89
int coordsPerLine
Definition: SVGWriter.java:90
void indent(int level, Writer writer)
Definition: SVGWriter.java:591

◆ appendSequencePoints()

void appendSequencePoints ( CoordinateSequence  seq,
int  level,
boolean  doIndent,
Writer  writer 
) throws IOException
private

References SVGWriter.appendCoordinate(), and SVGWriter.indent().

Referenced by SVGWriter.appendLineString(), and SVGWriter.appendPolygonPolygon().

422  {
423  if (seq.size() == 0) {
424  //writer.write("EMPTY");
425  }
426  else {
427  if (doIndent) indent(level, writer);
428  for (int i = 0; i < seq.size(); i++) {
429  writer.write(" ");
430  if (i > 0) {
431  if (coordsPerLine > 0
432  && i % coordsPerLine == 0) {
433  indent(level + 1, writer);
434  }
435  }
436  appendCoordinate(seq, i, writer);
437  }
438  }
439  }
void appendCoordinate(CoordinateSequence seq, int i, Writer writer)
Appends the i&#39;th coordinate from the sequence to the writer.
Definition: SVGWriter.java:358
int level
Definition: SVGWriter.java:89
int coordsPerLine
Definition: SVGWriter.java:90
void indent(int level, Writer writer)
Definition: SVGWriter.java:591

◆ createFormatter()

static DecimalFormat createFormatter ( PrecisionModel  precisionModel)
staticprivate

Creates the DecimalFormat used to write doubles with a sufficient number of decimal places.

Parameters
precisionModelthe PrecisionModel used to determine the number of decimal places to write.
Returns
a DecimalFormat that write double s without scientific notation.

References SVGWriter.stringOfChar().

Referenced by SVGWriter.writeFormatted().

58  {
59  // the default number of decimal places is 16, which is sufficient
60  // to accomodate the maximum precision of a double.
61  int decimalPlaces = precisionModel.getMaximumSignificantDigits();
62  // specify decimal separator explicitly to avoid problems in other locales
63  DecimalFormatSymbols symbols = new DecimalFormatSymbols();
64  symbols.setDecimalSeparator('.');
65  String fmtString = "0" + (decimalPlaces > 0 ? "." : "")
66  + stringOfChar('#', decimalPlaces);
67  return new DecimalFormat(fmtString, symbols);
68  }
static String stringOfChar(char ch, int count)
Returns a String of repeated characters.
Definition: SVGWriter.java:77

◆ indent()

void indent ( int  level,
Writer  writer 
) throws IOException
private

References SVGWriter.level.

Referenced by SVGWriter.appendGeometryTaggedText(), SVGWriter.appendLineString(), SVGWriter.appendPolygonPath(), SVGWriter.appendPolygonPolygon(), SVGWriter.appendSequencePath(), SVGWriter.appendSequencePoints(), and SVGWriter.indentCoords().

593  {
594  if (! useFormatting || level <= 0)
595  return;
596  writer.write("\n");
597  for (int i = 0; i < level; i++) {
598  writer.write(indentTabStr);
599  }
600  }
boolean useFormatting
Definition: SVGWriter.java:88
int level
Definition: SVGWriter.java:89
String indentTabStr
Definition: SVGWriter.java:91

◆ indentCoords()

void indentCoords ( int  coordIndex,
int  level,
Writer  writer 
) throws IOException
private

References SVGWriter.indent().

584  {
585  if (coordsPerLine <= 0
586  || coordIndex % coordsPerLine != 0)
587  return;
588  indent(level, writer);
589  }
int level
Definition: SVGWriter.java:89
int coordsPerLine
Definition: SVGWriter.java:90
void indent(int level, Writer writer)
Definition: SVGWriter.java:591

◆ stringOfChar()

static String stringOfChar ( char  ch,
int  count 
)
static

Returns a String of repeated characters.

Parameters
chthe character to repeat
countthe number of times to repeat the character
Returns
a String of characters

Referenced by SVGWriter.createFormatter().

77  {
78  StringBuffer buf = new StringBuffer();
79  for (int i = 0; i < count; i++) {
80  buf.append(ch);
81  }
82  return buf.toString();
83  }

◆ write() [1/2]

String write ( Geometry  geometry)

Converts a Geometry to its Well-known Text representation.

Parameters
geometrya Geometry to process
Returns
a <Geometry tagged="" text>=""> string (see the OpenGIS Simple Features Specification)

References SVGWriter.writeFormatted().

Referenced by AsSVG.operation().

108  {
109  Writer sw = new StringWriter();
110  try {
111  writeFormatted(geometry, isFormatted, sw);
112  }
113  catch (IOException ex) {
114  Assert.shouldNeverReachHere();
115  }
116  return sw.toString();
117  }
String writeFormatted(Geometry geometry)
Same as write, but with newlines and spaces to make the well-known text more readable.
Definition: SVGWriter.java:138
boolean isFormatted
Definition: SVGWriter.java:87

◆ write() [2/2]

void write ( Geometry  geometry,
Writer  writer 
) throws IOException

Converts a Geometry to its Well-known Text representation.

Parameters
geometrya Geometry to process

References SVGWriter.writeFormatted().

126  {
127  writeFormatted(geometry, false, writer);
128  }
String writeFormatted(Geometry geometry)
Same as write, but with newlines and spaces to make the well-known text more readable.
Definition: SVGWriter.java:138

◆ writeFormatted() [1/3]

String writeFormatted ( Geometry  geometry)

Same as write, but with newlines and spaces to make the well-known text more readable.

Parameters
geometrya Geometry to process
Returns
a <Geometry tagged="" text>=""> string (see the OpenGIS Simple Features Specification), with newlines and spaces

Referenced by SVGWriter.write(), and SVGWriter.writeFormatted().

139  {
140  Writer sw = new StringWriter();
141  try {
142  writeFormatted(geometry, true, sw);
143  }
144  catch (IOException ex) {
145  Assert.shouldNeverReachHere();
146  }
147  return sw.toString();
148  }
String writeFormatted(Geometry geometry)
Same as write, but with newlines and spaces to make the well-known text more readable.
Definition: SVGWriter.java:138

◆ writeFormatted() [2/3]

void writeFormatted ( Geometry  geometry,
Writer  writer 
) throws IOException

Same as write, but with newlines and spaces to make the well-known text more readable.

Parameters
geometrya Geometry to process

References SVGWriter.writeFormatted().

157  {
158  writeFormatted(geometry, true, writer);
159  }
String writeFormatted(Geometry geometry)
Same as write, but with newlines and spaces to make the well-known text more readable.
Definition: SVGWriter.java:138

◆ writeFormatted() [3/3]

void writeFormatted ( Geometry  geometry,
boolean  useFormatting,
Writer  writer 
) throws IOException
private

Converts a Geometry to its Well-known Text representation.

Parameters
geometrya Geometry to process

References SVGWriter.appendGeometryTaggedText(), SVGWriter.createFormatter(), and SVGWriter.useFormatting.

167  {
169  formatter = createFormatter(geometry.getPrecisionModel());
170  //writer.write("<g>\n");
171  appendGeometryTaggedText(geometry, 0, writer);
172  //writer.write("</g>\n");
173  }
static DecimalFormat createFormatter(PrecisionModel precisionModel)
Creates the DecimalFormat used to write doubles with a sufficient number of decimal places...
Definition: SVGWriter.java:58
boolean useFormatting
Definition: SVGWriter.java:88
DecimalFormat formatter
Definition: SVGWriter.java:86
void appendGeometryTaggedText(Geometry geometry, int level, Writer writer)
Converts a Geometry to <Geometry Tagged Text> format, then appends it to the writer.
Definition: SVGWriter.java:183

◆ writeNumber()

String writeNumber ( double  d)
private

Converts a double to a String, not in scientific notation.

Parameters
dthe double to convert
Returns
the double as a String, not in scientific notation

Referenced by SVGWriter.appendCoordinate().

389  {
390  return formatter.format(d);
391  }
DecimalFormat formatter
Definition: SVGWriter.java:86

Member Data Documentation

◆ coordsPerLine

int coordsPerLine = -1
private

◆ formatter

DecimalFormat formatter
private

◆ INDENT

final int INDENT = 2
staticprivate

◆ indentTabStr

String indentTabStr = " "
private

◆ isFormatted

boolean isFormatted = false
private

◆ level

◆ outputDimension

int outputDimension = 2
private

◆ useFormatting

boolean useFormatting = false
private