Package org.locationtech.jts.io.kml
Class KMLWriter
java.lang.Object
org.locationtech.jts.io.kml.KMLWriter
Writes a formatted string containing the KML representation of a JTS
Geometry
.
The output is KML fragments which
can be substituted wherever the KML Geometry abstract element can be used.
Output elements are indented to provide a nicely-formatted representation. An output line prefix and maximum number of coordinates per line can be specified.
The Z ordinate value output can be forced to be a specific value.
The extrude
and altitudeMode
modes can be set.
If set, the corresponding sub-elements will be output.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic String
The KML standard valueabsolute
for use insetAltitudeMode(String)
.static String
The KML standard valueclampToGround
for use insetAltitudeMode(String)
.static String
The KML standard valuerelativeToGround
for use insetAltitudeMode(String)
.private String
private static final String
private boolean
private final int
private String
private int
private DecimalFormat
private boolean
private static final String
private double
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static DecimalFormat
createFormatter
(int precision) Creates theDecimalFormat
used to writedouble
s with a sufficient number of decimal places.private String
geometryTag
(String geometryName, String attributes) void
setAltitudeMode
(String altitudeMode) Sets the value output in thealtitudeMode
element.void
setExtrude
(boolean extrude) Sets the flag to be output in theextrude
element.void
setLinePrefix
(String linePrefix) Sets a tag string which is prefixed to every emitted text line.void
setMaximumCoordinatesPerLine
(int maxCoordinatesPerLine) Sets the maximum number of coordinates to output per line.void
setPrecision
(int precision) Sets the maximum number of decimal places to output in ordinate values.void
setTesselate
(boolean tesselate) Sets the flag to be output in thetesselate
element.void
setZ
(double zVal) Sets the Z value to be output for all coordinates.private void
startLine
(String text, int level, StringBuffer buf) private void
write
(double num, StringBuffer buf) private void
write
(Coordinate[] coords, int level, StringBuffer buf) Takes a list of coordinates and converts it to KML.
2d and 3d aware.private void
write
(Coordinate p, StringBuffer buf) Writes aGeometry
in KML format as a string.void
void
write
(Geometry geometry, StringBuffer buf) Appends the KML representation of aGeometry
to aStringBuffer
.static String
writeGeometry
(Geometry geometry, double z) Writes a Geometry as KML to a string, using a specified Z value.static String
writeGeometry
(Geometry geometry, double z, int precision, boolean extrude, String altitudeMode) Writes a Geometry as KML to a string, using a specified Z value, precision, extrude flag, and altitude mode code.private void
writeGeometry
(Geometry g, int level, StringBuffer buf) private void
writeGeometryCollection
(GeometryCollection gc, String attributes, int level, StringBuffer buf) private void
writeLinearRing
(LinearRing lr, String attributes, boolean writeModifiers, int level, StringBuffer buf) private void
writeLineString
(LineString ls, String attributes, int level, StringBuffer buf) private void
writeModifiers
(int level, StringBuffer buf) private void
writePoint
(Point p, String attributes, int level, StringBuffer buf) private void
writePolygon
(Polygon p, String attributes, int level, StringBuffer buf)
-
Field Details
-
ALTITUDE_MODE_CLAMPTOGROUND
The KML standard valueclampToGround
for use insetAltitudeMode(String)
. -
ALTITUDE_MODE_RELATIVETOGROUND
The KML standard valuerelativeToGround
for use insetAltitudeMode(String)
. -
ALTITUDE_MODE_ABSOLUTE
The KML standard valueabsolute
for use insetAltitudeMode(String)
. -
INDENT_SIZE
private final int INDENT_SIZE- See Also:
-
COORDINATE_SEPARATOR
- See Also:
-
TUPLE_SEPARATOR
- See Also:
-
linePrefix
-
maxCoordinatesPerLine
private int maxCoordinatesPerLine -
zVal
private double zVal -
extrude
private boolean extrude -
tesselate
private boolean tesselate -
altitudeMode
-
numberFormatter
-
-
Constructor Details
-
KMLWriter
public KMLWriter()Creates a new writer.
-
-
Method Details
-
writeGeometry
Writes a Geometry as KML to a string, using a specified Z value.- Parameters:
geometry
- the geometry to writez
- the Z value to use- Returns:
- a string containing the KML geometry representation
-
writeGeometry
public static String writeGeometry(Geometry geometry, double z, int precision, boolean extrude, String altitudeMode) Writes a Geometry as KML to a string, using a specified Z value, precision, extrude flag, and altitude mode code.- Parameters:
geometry
- the geometry to writez
- the Z value to useprecision
- the maximum number of decimal places to writeextrude
- the extrude flag to writealtitudeMode
- the altitude model code to write- Returns:
- a string containing the KML geometry representation
-
setLinePrefix
Sets a tag string which is prefixed to every emitted text line. This can be used to indent the geometry text in a containing document.- Parameters:
linePrefix
- the tag string
-
setMaximumCoordinatesPerLine
public void setMaximumCoordinatesPerLine(int maxCoordinatesPerLine) Sets the maximum number of coordinates to output per line.- Parameters:
maxCoordinatesPerLine
- the maximum number of coordinates to output
-
setZ
public void setZ(double zVal) Sets the Z value to be output for all coordinates. This overrides any Z value present in the Geometry coordinates.- Parameters:
zVal
- the Z value to output
-
setExtrude
public void setExtrude(boolean extrude) Sets the flag to be output in theextrude
element.- Parameters:
extrude
- the extrude flag to output
-
setTesselate
public void setTesselate(boolean tesselate) Sets the flag to be output in thetesselate
element.- Parameters:
tesselate
- the tesselate flag to output
-
setAltitudeMode
Sets the value output in thealtitudeMode
element.- Parameters:
altitudeMode
- string representing the altitude mode
-
setPrecision
public void setPrecision(int precision) Sets the maximum number of decimal places to output in ordinate values. Useful for limiting output size.- Parameters:
precision
- the number of decimal places to output
-
write
Writes aGeometry
in KML format as a string.- Parameters:
geom
- the geometry to write- Returns:
- a string containing the KML geometry representation
-
write
- Parameters:
geometry
- the geometry to writewriter
- the Writer to write to- Throws:
IOException
- if an I/O error occurred
-
write
Appends the KML representation of aGeometry
to aStringBuffer
.- Parameters:
geometry
- the geometry to writebuf
- the buffer to write into
-
writeGeometry
-
startLine
-
geometryTag
-
writeModifiers
-
writePoint
-
writeLineString
-
writeLinearRing
private void writeLinearRing(LinearRing lr, String attributes, boolean writeModifiers, int level, StringBuffer buf) -
writePolygon
-
writeGeometryCollection
private void writeGeometryCollection(GeometryCollection gc, String attributes, int level, StringBuffer buf) -
write
Takes a list of coordinates and converts it to KML.
2d and 3d aware. Terminates the coordinate output with a newline.- Parameters:
cs
- array of coordinates
-
write
-
write
-
createFormatter
Creates theDecimalFormat
used to writedouble
s with a sufficient number of decimal places.- Parameters:
precisionModel
- thePrecisionModel
used to determine the number of decimal places to write.- Returns:
- a
DecimalFormat
that writedouble
s without scientific notation.
-