com.vividsolutions.jts.io

Class WKTWriter


public class WKTWriter
extends java.lang.Object

Outputs the Well-Known Text representation of a Geometry. The Well-known Text format is defined in the OGC Simple Features Specification for SQL.

The WKTWriter outputs coordinates rounded to the precision model. No more than the maximum number of necessary decimal places will be output.

A non-standard LINEARRING tag is used for LinearRings. The SFS WKT spec does not define a special tag for LinearRings. Under it, rings are output using LINESTRING.

Version:
1.7
See Also:
WKTReader

Constructor Summary

WKTWriter()

Method Summary

static String
stringOfChar(char ch, int count)
Returns a String of repeated characters.
static String
toLineString(Coordinate p0, Coordinate p1)
Generates the WKT for a 2-point LineString.
static String
toLineString(CoordinateSequence seq)
Generates the WKT for a N-point LineString.
static String
toPoint(Coordinate p0)
Generates the WKT for a Point.
String
write(Geometry geometry)
Converts a Geometry to its Well-known Text representation.
void
write(Geometry geometry, Writer writer)
Converts a Geometry to its Well-known Text representation.
String
writeFormatted(Geometry geometry)
Same as write, but with newlines and spaces to make the well-known text more readable.
void
writeFormatted(Geometry geometry, Writer writer)
Same as write, but with newlines and spaces to make the well-known text more readable.

Constructor Details

WKTWriter

public WKTWriter()

Method Details

stringOfChar

public static String stringOfChar(char ch,
                                  int count)
Returns a String of repeated characters.
Parameters:
ch - the character to repeat
count - the number of times to repeat the character
Returns:
a String of characters

toLineString

public static String toLineString(Coordinate p0,
                                  Coordinate p1)
Generates the WKT for a 2-point LineString.
Parameters:
p0 - the first coordinate
p1 - the second coordinate
Returns:
the WKT

toLineString

public static String toLineString(CoordinateSequence seq)
Generates the WKT for a N-point LineString.
Parameters:
seq - the sequence to outpout
Returns:
the WKT

toPoint

public static String toPoint(Coordinate p0)
Generates the WKT for a Point.
Parameters:
p0 - the point coordinate
Returns:
the WKT

write

public String write(Geometry geometry)
Converts a Geometry to its Well-known Text representation.
Parameters:
geometry - a Geometry to process
Returns:
a string (see the OpenGIS Simple Features Specification)

write

public void write(Geometry geometry,
                  Writer writer)
            throws IOException
Converts a Geometry to its Well-known Text representation.
Parameters:
geometry - a Geometry to process

writeFormatted

public String writeFormatted(Geometry geometry)
Same as write, but with newlines and spaces to make the well-known text more readable.
Parameters:
geometry - a Geometry to process
Returns:
a string (see the OpenGIS Simple Features Specification), with newlines and spaces

writeFormatted

public 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:
geometry - a Geometry to process