public class WKTWriter extends Object
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 LinearRing
s.
Under the spec, rings are output as LINESTRING
s.
In order to allow precisely specifying constructed geometries,
JTS also supports a non-standard LINEARRING
tag which is used
to output LinearRings.
WKTReader
Constructor and Description |
---|
WKTWriter()
Creates a new WKTWriter with default settings
|
WKTWriter(int outputDimension)
Creates a writer that writes
Geometry s with
the given output dimension (2 to 4). |
Modifier and Type | Method and Description |
---|---|
static String |
format(Coordinate p) |
EnumSet<Ordinate> |
getOutputOrdinates()
Gets a bit-pattern defining which ordinates should be
|
void |
setFormatted(boolean isFormatted)
Sets whether the output will be formatted.
|
void |
setMaxCoordinatesPerLine(int coordsPerLine)
Sets the maximum number of coordinates per line
written in formatted output.
|
void |
setOutputOrdinates(EnumSet<Ordinate> outputOrdinates)
Sets the
Ordinate that are to be written. |
void |
setPrecisionModel(PrecisionModel precisionModel)
Sets a
PrecisionModel that should be used on the ordinates written. |
void |
setTab(int size)
Sets the tab size to use for indenting.
|
static String |
toLineString(Coordinate[] coord)
Generates the WKT for a LINESTRING
specified by a
CoordinateSequence . |
static String |
toLineString(Coordinate p0,
Coordinate p1)
Generates the WKT for a LINESTRING
specified by two
Coordinate s. |
static String |
toLineString(CoordinateSequence seq)
Generates the WKT for a LINESTRING
specified by a
CoordinateSequence . |
static String |
toPoint(Coordinate p0)
Generates the WKT for a POINT
specified by a
Coordinate . |
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. |
public WKTWriter()
public WKTWriter(int outputDimension)
Geometry
s with
the given output dimension (2 to 4).
The output follows the following rules:
Double.NaN
)Double.NaN
)Double.NaN
)setOutputOrdinates(EnumSet)
outputDimension
- the coordinate dimension to output (2 to 4)public static String toPoint(Coordinate p0)
Coordinate
.p0
- the point coordinatepublic static String toLineString(CoordinateSequence seq)
CoordinateSequence
.seq
- the sequence to writepublic static String toLineString(Coordinate[] coord)
CoordinateSequence
.coord
- the sequence to writepublic static String toLineString(Coordinate p0, Coordinate p1)
Coordinate
s.p0
- the first coordinatep1
- the second coordinatepublic static String format(Coordinate p)
public void setFormatted(boolean isFormatted)
isFormatted
- true if the output is to be formattedpublic void setMaxCoordinatesPerLine(int coordsPerLine)
coordsPerLine
- the number of coordinates per line to output.public void setTab(int size)
size
- the number of spaces to use as the tab stringIllegalArgumentException
- if the size is non-positivepublic void setOutputOrdinates(EnumSet<Ordinate> outputOrdinates)
Ordinate
that are to be written. Possible members are:
Values of Ordinate.X
and Ordinate.Y
are always assumed and not
particularly checked for.outputOrdinates
- A set of Ordinate
valuespublic EnumSet<Ordinate> getOutputOrdinates()
setOutputOrdinates(EnumSet)
public void setPrecisionModel(PrecisionModel precisionModel)
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.
precisionModel
- the flag indicating if Coordinate.z
/{} is actually a measure value.public String write(Geometry geometry)
Geometry
to its Well-known Text representation.geometry
- a Geometry
to processpublic void write(Geometry geometry, Writer writer) throws IOException
Geometry
to its Well-known Text representation.geometry
- a Geometry
to processIOException
public String writeFormatted(Geometry geometry)
write
, but with newlines and spaces to make the
well-known text more readable.geometry
- a Geometry
to processpublic void writeFormatted(Geometry geometry, Writer writer) throws IOException
write
, but with newlines and spaces to make the
well-known text more readable.geometry
- a Geometry
to processIOException
Copyright © 2024. All rights reserved.