Package org.locationtech.jts.io
Class WKTWriter
- java.lang.Object
-
- org.locationtech.jts.io.WKTWriter
-
public class WKTWriter extends java.lang.Object
Writes the Well-Known Text representation of aGeometry
. The Well-Known Text format is defined in the OGC Simple Features Specification for SQL. SeeWKTReader
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 asLINESTRING
s. In order to allow precisely specifying constructed geometries, JTS also supports a non-standardLINEARRING
tag which is used to output LinearRings.- Version:
- 1.7
- See Also:
WKTReader
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
format(Coordinate p)
java.util.EnumSet<Ordinate>
getOutputOrdinates()
Gets a bit-pattern defining which ordinates should bevoid
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(java.util.EnumSet<Ordinate> outputOrdinates)
Sets theOrdinate
that are to be written.void
setPrecisionModel(PrecisionModel precisionModel)
Sets aPrecisionModel
that should be used on the ordinates written.void
setTab(int size)
Sets the tab size to use for indenting.static java.lang.String
toLineString(Coordinate[] coord)
Generates the WKT for a LINESTRING specified by aCoordinateSequence
.static java.lang.String
toLineString(Coordinate p0, Coordinate p1)
Generates the WKT for a LINESTRING specified by twoCoordinate
s.static java.lang.String
toLineString(CoordinateSequence seq)
Generates the WKT for a LINESTRING specified by aCoordinateSequence
.static java.lang.String
toPoint(Coordinate p0)
Generates the WKT for a POINT specified by aCoordinate
.java.lang.String
write(Geometry geometry)
Converts aGeometry
to its Well-known Text representation.void
write(Geometry geometry, java.io.Writer writer)
Converts aGeometry
to its Well-known Text representation.java.lang.String
writeFormatted(Geometry geometry)
Same aswrite
, but with newlines and spaces to make the well-known text more readable.void
writeFormatted(Geometry geometry, java.io.Writer writer)
Same aswrite
, but with newlines and spaces to make the well-known text more readable.
-
-
-
Constructor Detail
-
WKTWriter
public WKTWriter()
Creates a new WKTWriter with default settings
-
WKTWriter
public WKTWriter(int outputDimension)
Creates a writer that writesGeometry
s 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
- the coordinate dimension to output (2 to 4)
- 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
-
-
Method Detail
-
toPoint
public static java.lang.String toPoint(Coordinate p0)
Generates the WKT for a POINT specified by aCoordinate
.- Parameters:
p0
- the point coordinate- Returns:
- the WKT
-
toLineString
public static java.lang.String toLineString(CoordinateSequence seq)
Generates the WKT for a LINESTRING specified by aCoordinateSequence
.- Parameters:
seq
- the sequence to write- Returns:
- the WKT string
-
toLineString
public static java.lang.String toLineString(Coordinate[] coord)
Generates the WKT for a LINESTRING specified by aCoordinateSequence
.- Parameters:
coord
- the sequence to write- Returns:
- the WKT string
-
toLineString
public static java.lang.String toLineString(Coordinate p0, Coordinate p1)
Generates the WKT for a LINESTRING specified by twoCoordinate
s.- Parameters:
p0
- the first coordinatep1
- the second coordinate- Returns:
- the WKT
-
format
public static java.lang.String format(Coordinate p)
-
setFormatted
public void setFormatted(boolean isFormatted)
Sets whether the output will be formatted.- Parameters:
isFormatted
- true if the output is to be formatted
-
setMaxCoordinatesPerLine
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
- the number of coordinates per line to output.
-
setTab
public void setTab(int size)
Sets the tab size to use for indenting.- Parameters:
size
- the number of spaces to use as the tab string- Throws:
java.lang.IllegalArgumentException
- if the size is non-positive
-
setOutputOrdinates
public void setOutputOrdinates(java.util.EnumSet<Ordinate> outputOrdinates)
Sets theOrdinate
that are to be written. Possible members are: Values ofOrdinate.X
andOrdinate.Y
are always assumed and not particularly checked for.- Parameters:
outputOrdinates
- A set ofOrdinate
values
-
getOutputOrdinates
public java.util.EnumSet<Ordinate> getOutputOrdinates()
Gets a bit-pattern defining which ordinates should be- Returns:
- an ordinate bit-pattern
- See Also:
setOutputOrdinates(EnumSet)
-
setPrecisionModel
public void setPrecisionModel(PrecisionModel precisionModel)
Sets aPrecisionModel
that should be used on the ordinates written.If none/
null
is assigned, the precision model of theGeometry.getFactory()
is used.Note: The precision model is applied to all ordinate values, not just x and y.
- Parameters:
precisionModel
- the flag indicating ifCoordinate.z
/{} is actually a measure value.
-
write
public java.lang.String write(Geometry geometry)
Converts aGeometry
to its Well-known Text representation.- Parameters:
geometry
- aGeometry
to process- Returns:
- a <Geometry Tagged Text> string (see the OpenGIS Simple Features Specification)
-
write
public void write(Geometry geometry, java.io.Writer writer) throws java.io.IOException
Converts aGeometry
to its Well-known Text representation.- Parameters:
geometry
- aGeometry
to process- Throws:
java.io.IOException
-
writeFormatted
public java.lang.String writeFormatted(Geometry geometry)
Same aswrite
, but with newlines and spaces to make the well-known text more readable.- Parameters:
geometry
- aGeometry
to process- Returns:
- a <Geometry Tagged Text> string (see the OpenGIS Simple Features Specification), with newlines and spaces
-
writeFormatted
public void writeFormatted(Geometry geometry, java.io.Writer writer) throws java.io.IOException
Same aswrite
, but with newlines and spaces to make the well-known text more readable.- Parameters:
geometry
- aGeometry
to process- Throws:
java.io.IOException
-
-