public class GMLWriter extends Object
Geometry
s as XML fragments in GML2 format.
Allows specifying the XML prefix, namespace and srsName
of the emitted GML.
Also allows adding custom root elements
to support GML extensions such as KML.
With appropriate settings for prefix (none) and custom root elements
this class can be used to write out geometry in KML format.
An example of the output that can be generated is:
<gml:LineString xmlns:gml='http://www.opengis.net/gml' srsName='foo'> <gml:coordinates> 6.03,8.17 7.697,6.959 8.333,5.0 7.697,3.041 6.03,1.83 3.97,1.83 2.303,3.041 1.667,5.0 2.303,6.959 3.97,8.17 </gml:coordinates> </gml:LineString>
This class does not rely on any external XML libraries.
Constructor and Description |
---|
GMLWriter()
Creates a writer which outputs GML with default settings.
|
GMLWriter(boolean emitNamespace)
Creates a writer which may emit the GML namespace prefix
declaration in the geometry root element.
|
Modifier and Type | Method and Description |
---|---|
void |
setCustomElements(String[] customElements)
Specifies a list of custom elements
which are written after the opening tag
of the root element.
|
void |
setMaxCoordinatesPerLine(int num)
Sets the number of coordinates printed per line.
|
void |
setNamespace(boolean emitNamespace)
Determines whether a GML namespace declaration will be written in the
opening tag of geometries.
|
void |
setPrefix(String prefix)
Specifies the namespace prefix to write on each GML tag.
|
void |
setSrsName(String srsName)
Sets the value of the srsName attribute
to be written into the root geometry tag.
|
void |
setStartingIndentIndex(int indent)
Sets the starting column index for pretty printing
|
String |
write(Geometry geom)
Writes a
Geometry in GML2 format to a String. |
void |
write(Geometry geom,
Writer writer)
|
public GMLWriter()
public GMLWriter(boolean emitNamespace)
emitNamespace
- true if the GML namespace prefix declaration should be written
in the geometry root elementpublic void setPrefix(String prefix)
The default is to write gml: as the namespace prefix.
prefix
- the namespace prefix to use (null or blank if none)public void setSrsName(String srsName)
The default is not to write the srsName attribute.
srsName
- the srsName attribute valuepublic void setNamespace(boolean emitNamespace)
emitNamespace
- true if the GML namespace prefix declaration
should be written in the root geometry elementpublic void setCustomElements(String[] customElements)
For instance, this is useful for adding KML-specific geometry parameters such as <extrude>
customElements
- a list of the custom element strings, or null if nonepublic void setStartingIndentIndex(int indent)
indent
- public void setMaxCoordinatesPerLine(int num)
num
- public String write(Geometry geom)
Geometry
in GML2 format to a String.geom
- public void write(Geometry geom, Writer writer) throws IOException
geom
- Geometry to encodewriter
- Stream to encode to.IOException
Copyright © 2020. All rights reserved.