public class KMLWriter
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ALTITUDE_MODE_ABSOLUTE
The KML standard value
absolute for use in setAltitudeMode(String) . |
static java.lang.String |
ALTITUDE_MODE_CLAMPTOGROUND
The KML standard value
clampToGround for use in setAltitudeMode(String) . |
static java.lang.String |
ALTITUDE_MODE_RELATIVETOGROUND
The KML standard value
relativeToGround for use in setAltitudeMode(String) . |
private java.lang.String |
altitudeMode |
private static java.lang.String |
COORDINATE_SEPARATOR |
private boolean |
extrude |
private int |
INDENT_SIZE |
private java.lang.String |
linePrefix |
private int |
maxCoordinatesPerLine |
private java.text.DecimalFormat |
numberFormatter |
private boolean |
tesselate |
private static java.lang.String |
TUPLE_SEPARATOR |
private double |
zVal |
Constructor and Description |
---|
KMLWriter()
Creates a new writer.
|
Modifier and Type | Method and Description |
---|---|
private static java.text.DecimalFormat |
createFormatter(int precision)
Creates the
DecimalFormat used to write double s
with a sufficient number of decimal places. |
private java.lang.String |
geometryTag(java.lang.String geometryName,
java.lang.String attributes) |
void |
setAltitudeMode(java.lang.String altitudeMode)
Sets the value output in the
altitudeMode element. |
void |
setExtrude(boolean extrude)
Sets the flag to be output in the
extrude element. |
void |
setLinePrefix(java.lang.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 the
tesselate element. |
void |
setZ(double zVal)
Sets the Z value to be output for all coordinates.
|
private void |
startLine(java.lang.String text,
int level,
java.lang.StringBuffer buf) |
private void |
write(Coordinate[] coords,
int level,
java.lang.StringBuffer buf)
Takes a list of coordinates and converts it to KML.
2d and 3d aware. |
private void |
write(Coordinate p,
java.lang.StringBuffer buf) |
private void |
write(double num,
java.lang.StringBuffer buf) |
java.lang.String |
write(Geometry geom)
Writes a
Geometry in KML format as a string. |
void |
write(Geometry geometry,
java.lang.StringBuffer buf)
Appends the KML representation of a
Geometry to a StringBuffer . |
void |
write(Geometry geometry,
java.io.Writer writer)
Writes the KML representation of a
Geometry to a Writer . |
static java.lang.String |
writeGeometry(Geometry geometry,
double z)
Writes a Geometry as KML to a string, using
a specified Z value.
|
static java.lang.String |
writeGeometry(Geometry geometry,
double z,
int precision,
boolean extrude,
java.lang.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,
java.lang.StringBuffer buf) |
private void |
writeGeometryCollection(GeometryCollection gc,
java.lang.String attributes,
int level,
java.lang.StringBuffer buf) |
private void |
writeLinearRing(LinearRing lr,
java.lang.String attributes,
boolean writeModifiers,
int level,
java.lang.StringBuffer buf) |
private void |
writeLineString(LineString ls,
java.lang.String attributes,
int level,
java.lang.StringBuffer buf) |
private void |
writeModifiers(int level,
java.lang.StringBuffer buf) |
private void |
writePoint(Point p,
java.lang.String attributes,
int level,
java.lang.StringBuffer buf) |
private void |
writePolygon(Polygon p,
java.lang.String attributes,
int level,
java.lang.StringBuffer buf) |
public static java.lang.String ALTITUDE_MODE_CLAMPTOGROUND
clampToGround
for use in setAltitudeMode(String)
.public static java.lang.String ALTITUDE_MODE_RELATIVETOGROUND
relativeToGround
for use in setAltitudeMode(String)
.public static java.lang.String ALTITUDE_MODE_ABSOLUTE
absolute
for use in setAltitudeMode(String)
.private final int INDENT_SIZE
private static final java.lang.String COORDINATE_SEPARATOR
private static final java.lang.String TUPLE_SEPARATOR
private java.lang.String linePrefix
private int maxCoordinatesPerLine
private double zVal
private boolean extrude
private boolean tesselate
private java.lang.String altitudeMode
private java.text.DecimalFormat numberFormatter
public static java.lang.String writeGeometry(Geometry geometry, double z)
geometry
- the geometry to writez
- the Z value to usepublic static java.lang.String writeGeometry(Geometry geometry, double z, int precision, boolean extrude, java.lang.String altitudeMode)
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 writepublic void setLinePrefix(java.lang.String linePrefix)
linePrefix
- the tag stringpublic void setMaximumCoordinatesPerLine(int maxCoordinatesPerLine)
maxCoordinatesPerLine
- the maximum number of coordinates to outputpublic void setZ(double zVal)
zVal
- the Z value to outputpublic void setExtrude(boolean extrude)
extrude
element.extrude
- the extrude flag to outputpublic void setTesselate(boolean tesselate)
tesselate
element.tesselate
- the tesselate flag to outputpublic void setAltitudeMode(java.lang.String altitudeMode)
altitudeMode
element.altitudeMode
- string representing the altitude modepublic void setPrecision(int precision)
precision
- the number of decimal places to outputpublic java.lang.String write(Geometry geom)
Geometry
in KML format as a string.geom
- the geometry to writepublic void write(Geometry geometry, java.io.Writer writer) throws java.io.IOException
Geometry
to a Writer
.geometry
- the geometry to writewriter
- the Writer to write tojava.io.IOException
- if an I/O error occurredpublic void write(Geometry geometry, java.lang.StringBuffer buf)
Geometry
to a StringBuffer
.geometry
- the geometry to writebuf
- the buffer to write intoprivate void writeGeometry(Geometry g, int level, java.lang.StringBuffer buf)
private void startLine(java.lang.String text, int level, java.lang.StringBuffer buf)
private java.lang.String geometryTag(java.lang.String geometryName, java.lang.String attributes)
private void writeModifiers(int level, java.lang.StringBuffer buf)
private void writePoint(Point p, java.lang.String attributes, int level, java.lang.StringBuffer buf)
private void writeLineString(LineString ls, java.lang.String attributes, int level, java.lang.StringBuffer buf)
private void writeLinearRing(LinearRing lr, java.lang.String attributes, boolean writeModifiers, int level, java.lang.StringBuffer buf)
private void writePolygon(Polygon p, java.lang.String attributes, int level, java.lang.StringBuffer buf)
private void writeGeometryCollection(GeometryCollection gc, java.lang.String attributes, int level, java.lang.StringBuffer buf)
private void write(Coordinate[] coords, int level, java.lang.StringBuffer buf)
cs
- array of coordinatesprivate void write(Coordinate p, java.lang.StringBuffer buf)
private void write(double num, java.lang.StringBuffer buf)
private static java.text.DecimalFormat createFormatter(int precision)
DecimalFormat
used to write double
s
with a sufficient number of decimal places.precisionModel
- the PrecisionModel
used to determine the number of
decimal places to write.DecimalFormat
that write double
s
without scientific notation.