Class WKTWriter

Hierarchy: Object , WKTWriter
public class WKTWriter
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.

See also:
WKTReader

Other

  • version: 1.7
public WKTWriter()
Creates a new WKTWriter with default settings
public WKTWriter(int outputDimension)
Creates a writer that writes Geometrys with the given output dimension (2 to 4). The output follows the following rules:
  • If the specified output dimension is 3 and the z is measure flag is set to true, the Z value of coordinates will be written if it is present (i.e. if it is not Double.NaN)
  • If the specified output dimension is 3 and the z is measure flag is set to false, the Measure value of coordinates will be written if it is present (i.e. if it is not Double.NaN)
  • If the specified output dimension is 4, the Z value of coordinates will be written even if it is not present when the Measure value is present.The Measrue value of coordinates will be written if it is present (i.e. if it is not Double.NaN)
Parameters:
outputDimension - outputDimension the coordinate dimension to output (2 to 4)
public static String toPoint(Coordinate p0)
Generates the WKT for a POINT specified by a Coordinate.
Parameters:
p0 - p0 the point coordinate
Returns:
the WKT
public static String toLineString(CoordinateSequence seq)
Generates the WKT for a LINESTRING specified by a CoordinateSequence.
Parameters:
seq - seq the sequence to write
Returns:
the WKT string
public static String toLineString(Coordinate[] coord)
Generates the WKT for a LINESTRING specified by a CoordinateSequence.
Parameters:
coord - coord the sequence to write
Returns:
the WKT string
public static String toLineString(Coordinate p0, Coordinate p1)
Generates the WKT for a LINESTRING specified by two Coordinates.
Parameters:
p0 - p0 the first coordinate
p1 - p1 the second coordinate
Returns:
the WKT
public static String format(Coordinate p)
public void setFormatted(boolean isFormatted)
Sets whether the output will be formatted.
Parameters:
isFormatted - isFormatted true if the output is to be formatted
public void setMaxCoordinatesPerLine(int coordsPerLine)
Sets the maximum number of coordinates per line written in formatted output. If the provided coordinate number is <= 0, coordinates will be written all on one line.
Parameters:
coordsPerLine - coordsPerLine the number of coordinates per line to output.
public void setTab(int size)
Sets the tab size to use for indenting.
Parameters:
size - size the number of spaces to use as the tab string
Throws:
IllegalArgumentException - IllegalArgumentException if the size is non-positive
public void setOutputOrdinates(EnumSet<Ordinate> outputOrdinates)
Sets the Ordinate that are to be written. Possible members are: Values of Ordinate.X and Ordinate.Y are always assumed and not particularly checked for.
Parameters:
outputOrdinates - outputOrdinates A set of Ordinate values
public EnumSet<Ordinate> getOutputOrdinates()
Gets a bit-pattern defining which ordinates should be
See also:
#setOutputOrdinates(EnumSet)
Returns:
an ordinate bit-pattern
public void setPrecisionModel(PrecisionModel precisionModel)
Sets a PrecisionModel that should be used on the ordinates written.

If none/null is assigned, the precision model of the Geometry.getFactory() is used.

Note: The precision model is applied to all ordinate values, not just x and y.

Parameters:
precisionModel - precisionModel the flag indicating if Coordinate.z /{} is actually a measure value.
public String write(Geometry geometry)
Converts a Geometry to its Well-known Text representation.
Parameters:
geometry - geometry a Geometry to process
Returns:
a <Geometry Tagged Text> string (see the OpenGIS Simple Features Specification)
public void write(Geometry geometry, Writer writer)
Converts a Geometry to its Well-known Text representation.
Parameters:
geometry - geometry a Geometry to process
public String writeFormatted(Geometry geometry)
Same as write, but with newlines and spaces to make the well-known text more readable.
Parameters:
geometry - geometry a Geometry to process
Returns:
a <Geometry Tagged Text> string (see the OpenGIS Simple Features Specification), with newlines and spaces
public void writeFormatted(Geometry geometry, Writer writer)
Same as write, but with newlines and spaces to make the well-known text more readable.
Parameters:
geometry - geometry a Geometry to process