Package org.locationtech.jts.io
Class WKTWriter
java.lang.Object
org.locationtech.jts.io.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.
- Version:
- 1.7
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate DecimalFormatprivate static final intprivate Stringprivate booleanprivate intprivate intprivate boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidappendCoordinate(Coordinate coordinate, Writer writer) Converts aCoordinateto<Point>format, then appends it to the writer.private voidappendCoordinate(CoordinateSequence seq, int i, Writer writer) Appends the i'th coordinate from the sequence to the writerprivate voidappendGeometryCollectionTaggedText(GeometryCollection geometryCollection, int level, Writer writer) Converts aGeometryCollectionto <GeometryCollection Tagged Text> format, then appends it to the writer.private voidappendGeometryCollectionText(GeometryCollection geometryCollection, int level, Writer writer) Converts aGeometryCollectionto <GeometryCollectionText> format, then appends it to the writer.private voidappendGeometryTaggedText(Geometry geometry, int level, Writer writer) Converts aGeometryto <Geometry Tagged Text> format, then appends it to the writer.private voidappendLinearRingTaggedText(LinearRing linearRing, int level, Writer writer) Converts aLinearRingto <LinearRing Tagged Text> format, then appends it to the writer.private voidappendLineStringTaggedText(LineString lineString, int level, Writer writer) Converts aLineStringto <LineString Tagged Text> format, then appends it to the writer.private voidappendLineStringText(LineString lineString, int level, boolean doIndent, Writer writer) Converts aLineStringto <LineString Text> format, then appends it to the writer.private voidappendMultiLineStringTaggedText(MultiLineString multiLineString, int level, Writer writer) Converts aMultiLineStringto <MultiLineString Tagged Text> format, then appends it to the writer.private voidappendMultiLineStringText(MultiLineString multiLineString, int level, boolean indentFirst, Writer writer) Converts aMultiLineStringto <MultiLineString Text> format, then appends it to the writer.private voidappendMultiPointTaggedText(MultiPoint multipoint, int level, Writer writer) Converts aMultiPointto <MultiPoint Tagged Text> format, then appends it to the writer.private voidappendMultiPointText(MultiPoint multiPoint, int level, Writer writer) Converts aMultiPointto <MultiPoint Text> format, then appends it to the writer.private voidappendMultiPolygonTaggedText(MultiPolygon multiPolygon, int level, Writer writer) Converts aMultiPolygonto <MultiPolygon Tagged Text> format, then appends it to the writer.private voidappendMultiPolygonText(MultiPolygon multiPolygon, int level, Writer writer) Converts aMultiPolygonto <MultiPolygon Text> format, then appends it to the writer.private voidappendPointTaggedText(Coordinate coordinate, int level, Writer writer, PrecisionModel precisionModel) Converts aCoordinateto <Point Tagged Text> format, then appends it to the writer.private voidappendPointText(Coordinate coordinate, int level, Writer writer, PrecisionModel precisionModel) Converts aCoordinateto <Point Text> format, then appends it to the writer.private voidappendPolygonTaggedText(Polygon polygon, int level, Writer writer) Converts aPolygonto <Polygon Tagged Text> format, then appends it to the writer.private voidappendPolygonText(Polygon polygon, int level, boolean indentFirst, Writer writer) Converts aPolygonto <Polygon Text> format, then appends it to the writer.private voidappendSequenceText(CoordinateSequence seq, int level, boolean doIndent, Writer writer) Converts aLineStringto <LineString Text> format, then appends it to the writer.private static DecimalFormatcreateFormatter(PrecisionModel precisionModel) Creates theDecimalFormatused to writedoubles with a sufficient number of decimal places.private voidprivate voidindentCoords(int coordIndex, int level, Writer writer) voidsetFormatted(boolean isFormatted) Sets whether the output will be formatted.voidsetMaxCoordinatesPerLine(int coordsPerLine) Sets the maximum number of coordinates per line written in formatted output.voidsetTab(int size) Sets the tab size to use for indenting.static StringstringOfChar(char ch, int count) Returns aStringof repeated characters.static StringtoLineString(Coordinate[] coord) Generates the WKT for a LINESTRING specified by aCoordinateSequence.static StringtoLineString(Coordinate p0, Coordinate p1) Generates the WKT for a LINESTRING specified by twoCoordinates.static StringGenerates the WKT for a LINESTRING specified by aCoordinateSequence.static StringtoPoint(Coordinate p0) Generates the WKT for a POINT specified by aCoordinate.Converts aGeometryto its Well-known Text representation.voidConverts aGeometryto its Well-known Text representation.writeFormatted(Geometry geometry) Same aswrite, but with newlines and spaces to make the well-known text more readable.private voidwriteFormatted(Geometry geometry, boolean useFormatting, Writer writer) Converts aGeometryto its Well-known Text representation.voidwriteFormatted(Geometry geometry, Writer writer) Same aswrite, but with newlines and spaces to make the well-known text more readable.private StringwriteNumber(double d) Converts adoubleto aString, not in scientific notation.
-
Field Details
-
INDENT
private static final int INDENT- See Also:
-
outputDimension
private int outputDimension -
formatter
-
isFormatted
private boolean isFormatted -
useFormatting
private boolean useFormatting -
level
private int level -
coordsPerLine
private int coordsPerLine -
indentTabStr
-
-
Constructor Details
-
WKTWriter
public WKTWriter()Creates a new WKTWriter with default settings -
WKTWriter
public WKTWriter(int outputDimension) Creates a writer that writesGeometrys with the given output dimension (2 or 3). If the specified output dimension is 3, the Z value of coordinates will be written if it is present (i.e. if it is notDouble.NaN).- Parameters:
outputDimension- the coordinate dimension to output (2 or 3)
-
-
Method Details
-
toPoint
Generates the WKT for a POINT specified by aCoordinate.- Parameters:
p0- the point coordinate- Returns:
- the WKT
-
toLineString
Generates the WKT for a LINESTRING specified by aCoordinateSequence.- Parameters:
seq- the sequence to write- Returns:
- the WKT string
-
toLineString
Generates the WKT for a LINESTRING specified by aCoordinateSequence.- Parameters:
coord- the sequence to write- Returns:
- the WKT string
-
toLineString
Generates the WKT for a LINESTRING specified by twoCoordinates.- Parameters:
p0- the first coordinatep1- the second coordinate- Returns:
- the WKT
-
createFormatter
Creates theDecimalFormatused to writedoubles with a sufficient number of decimal places.- Parameters:
precisionModel- thePrecisionModelused to determine the number of decimal places to write.- Returns:
- a
DecimalFormatthat writedoubles without scientific notation.
-
stringOfChar
Returns aStringof repeated characters.- Parameters:
ch- the character to repeatcount- the number of times to repeat the character- Returns:
- a
Stringof characters
-
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:
IllegalArgumentException- if the size is non-positive
-
write
Converts aGeometryto its Well-known Text representation.- Parameters:
geometry- aGeometryto process- Returns:
- a <Geometry Tagged Text> string (see the OpenGIS Simple Features Specification)
-
write
Converts aGeometryto its Well-known Text representation.- Parameters:
geometry- aGeometryto process- Throws:
IOException
-
writeFormatted
Same aswrite, but with newlines and spaces to make the well-known text more readable.- Parameters:
geometry- aGeometryto process- Returns:
- a <Geometry Tagged Text> string (see the OpenGIS Simple Features Specification), with newlines and spaces
-
writeFormatted
Same aswrite, but with newlines and spaces to make the well-known text more readable.- Parameters:
geometry- aGeometryto process- Throws:
IOException
-
writeFormatted
private void writeFormatted(Geometry geometry, boolean useFormatting, Writer writer) throws IOException Converts aGeometryto its Well-known Text representation.- Parameters:
geometry- aGeometryto process- Throws:
IOException
-
appendGeometryTaggedText
private void appendGeometryTaggedText(Geometry geometry, int level, Writer writer) throws IOException Converts aGeometryto <Geometry Tagged Text> format, then appends it to the writer.- Parameters:
geometry- theGeometryto processwriter- the output writer to append to- Throws:
IOException
-
appendPointTaggedText
private void appendPointTaggedText(Coordinate coordinate, int level, Writer writer, PrecisionModel precisionModel) throws IOException Converts aCoordinateto <Point Tagged Text> format, then appends it to the writer.- Parameters:
coordinate- theCoordinateto processwriter- the output writer to append toprecisionModel- thePrecisionModelto use to convert from a precise coordinate to an external coordinate- Throws:
IOException
-
appendLineStringTaggedText
private void appendLineStringTaggedText(LineString lineString, int level, Writer writer) throws IOException Converts aLineStringto <LineString Tagged Text> format, then appends it to the writer.- Parameters:
lineString- theLineStringto processwriter- the output writer to append to- Throws:
IOException
-
appendLinearRingTaggedText
private void appendLinearRingTaggedText(LinearRing linearRing, int level, Writer writer) throws IOException Converts aLinearRingto <LinearRing Tagged Text> format, then appends it to the writer.- Parameters:
linearRing- theLinearRingto processwriter- the output writer to append to- Throws:
IOException
-
appendPolygonTaggedText
Converts aPolygonto <Polygon Tagged Text> format, then appends it to the writer.- Parameters:
polygon- thePolygonto processwriter- the output writer to append to- Throws:
IOException
-
appendMultiPointTaggedText
private void appendMultiPointTaggedText(MultiPoint multipoint, int level, Writer writer) throws IOException Converts aMultiPointto <MultiPoint Tagged Text> format, then appends it to the writer.- Parameters:
multipoint- theMultiPointto processwriter- the output writer to append to- Throws:
IOException
-
appendMultiLineStringTaggedText
private void appendMultiLineStringTaggedText(MultiLineString multiLineString, int level, Writer writer) throws IOException Converts aMultiLineStringto <MultiLineString Tagged Text> format, then appends it to the writer.- Parameters:
multiLineString- theMultiLineStringto processwriter- the output writer to append to- Throws:
IOException
-
appendMultiPolygonTaggedText
private void appendMultiPolygonTaggedText(MultiPolygon multiPolygon, int level, Writer writer) throws IOException Converts aMultiPolygonto <MultiPolygon Tagged Text> format, then appends it to the writer.- Parameters:
multiPolygon- theMultiPolygonto processwriter- the output writer to append to- Throws:
IOException
-
appendGeometryCollectionTaggedText
private void appendGeometryCollectionTaggedText(GeometryCollection geometryCollection, int level, Writer writer) throws IOException Converts aGeometryCollectionto <GeometryCollection Tagged Text> format, then appends it to the writer.- Parameters:
geometryCollection- theGeometryCollectionto processwriter- the output writer to append to- Throws:
IOException
-
appendPointText
private void appendPointText(Coordinate coordinate, int level, Writer writer, PrecisionModel precisionModel) throws IOException Converts aCoordinateto <Point Text> format, then appends it to the writer.- Parameters:
coordinate- theCoordinateto processwriter- the output writer to append toprecisionModel- thePrecisionModelto use to convert from a precise coordinate to an external coordinate- Throws:
IOException
-
appendCoordinate
Appends the i'th coordinate from the sequence to the writer- Parameters:
seq- theCoordinateSequenceto processi- the index of the coordinate to writewriter- the output writer to append to- Throws:
IOException
-
appendCoordinate
Converts aCoordinateto<Point>format, then appends it to the writer.- Parameters:
coordinate- theCoordinateto processwriter- the output writer to append to- Throws:
IOException
-
writeNumber
Converts adoubleto aString, not in scientific notation.- Parameters:
d- thedoubleto convert- Returns:
- the
doubleas aString, not in scientific notation
-
appendSequenceText
private void appendSequenceText(CoordinateSequence seq, int level, boolean doIndent, Writer writer) throws IOException Converts aLineStringto <LineString Text> format, then appends it to the writer.- Parameters:
writer- the output writer to append tolineString- theLineStringto process- Throws:
IOException
-
appendLineStringText
private void appendLineStringText(LineString lineString, int level, boolean doIndent, Writer writer) throws IOException Converts aLineStringto <LineString Text> format, then appends it to the writer.- Parameters:
lineString- theLineStringto processwriter- the output writer to append to- Throws:
IOException
-
appendPolygonText
private void appendPolygonText(Polygon polygon, int level, boolean indentFirst, Writer writer) throws IOException Converts aPolygonto <Polygon Text> format, then appends it to the writer.- Parameters:
polygon- thePolygonto processwriter- the output writer to append to- Throws:
IOException
-
appendMultiPointText
private void appendMultiPointText(MultiPoint multiPoint, int level, Writer writer) throws IOException Converts aMultiPointto <MultiPoint Text> format, then appends it to the writer.- Parameters:
multiPoint- theMultiPointto processwriter- the output writer to append to- Throws:
IOException
-
appendMultiLineStringText
private void appendMultiLineStringText(MultiLineString multiLineString, int level, boolean indentFirst, Writer writer) throws IOException Converts aMultiLineStringto <MultiLineString Text> format, then appends it to the writer.- Parameters:
multiLineString- theMultiLineStringto processwriter- the output writer to append to- Throws:
IOException
-
appendMultiPolygonText
private void appendMultiPolygonText(MultiPolygon multiPolygon, int level, Writer writer) throws IOException Converts aMultiPolygonto <MultiPolygon Text> format, then appends it to the writer.- Parameters:
multiPolygon- theMultiPolygonto processwriter- the output writer to append to- Throws:
IOException
-
appendGeometryCollectionText
private void appendGeometryCollectionText(GeometryCollection geometryCollection, int level, Writer writer) throws IOException Converts aGeometryCollectionto <GeometryCollectionText> format, then appends it to the writer.- Parameters:
geometryCollection- theGeometryCollectionto processwriter- the output writer to append to- Throws:
IOException
-
indentCoords
- Throws:
IOException
-
indent
- Throws:
IOException
-