Package org.openstreetmap.josm.io
Class OsmWriter
- java.lang.Object
-
- org.openstreetmap.josm.io.XmlWriter
-
- org.openstreetmap.josm.io.OsmWriter
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,PrimitiveVisitor
public class OsmWriter extends XmlWriter implements PrimitiveVisitor
Save the dataset into a stream as osm intern xml format. This is not using any xml library for storing.- Since:
- 59
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.Comparator<AbstractPrimitive>
byIdComparator
Sorts-1
→-infinity
, then+1
→+infinity
protected static java.util.Comparator<java.util.Map.Entry<java.lang.String,java.lang.String>>
byKeyComparator
private Changeset
changeset
static java.lang.String
DEFAULT_API_VERSION
Default OSM API versionprivate boolean
isOsmChange
private boolean
osmConform
private java.lang.String
version
private boolean
withBody
private boolean
withVisible
-
Constructor Summary
Constructors Modifier Constructor Description protected
OsmWriter(java.io.PrintWriter out, boolean osmConform, java.lang.String version)
Constructs a newOsmWriter
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addCommon(IPrimitive osm, java.lang.String tagname)
Add the common part as the form of the tag as well as the XML attributes id, action, user, and visible.protected void
addTags(Tagged osm, java.lang.String tagname, boolean tagOpen)
void
footer()
Writes OSM footer.void
header()
Writes OSM header with normal download and upload policies.void
header(DownloadPolicy download, UploadPolicy upload)
Writes OSM header with given download upload policies.private void
header(DownloadPolicy download, UploadPolicy upload, boolean locked)
void
setChangeset(Changeset cs)
void
setIsOsmChange(boolean isOsmChange)
void
setVersion(java.lang.String v)
void
setWithBody(boolean wb)
Sets whether body must be written.void
setWithVisible(boolean wv)
Sets whether 'visible' attribute must be written.protected boolean
shouldWrite(OsmPrimitive osm)
protected <T extends OsmPrimitive>
java.util.Collection<T>sortById(java.util.Collection<T> primitives)
void
visit(Changeset cs)
Visiting call for changesets.void
visit(INode n)
Visiting call for nodes.void
visit(IRelation<?> e)
Visiting call for relations.void
visit(IWay<?> w)
Visiting call for ways.void
write(DataSet data)
Writes the full OSM file for the given data set (header, data sources, osm data, footer).void
writeContent(DataSet ds)
Writes the contents of the given dataset (nodes, then ways, then relations)void
writeDataSources(DataSet ds)
Writes data sources with their respective bounds.(package private) void
writeLatLon(LatLon ll)
void
writeNodes(java.util.Collection<Node> nodes)
Writes the given nodes sorted by idvoid
writeRelations(java.util.Collection<Relation> relations)
Writes the given relations sorted by idvoid
writeWays(java.util.Collection<Way> ways)
Writes the given ways sorted by id
-
-
-
Field Detail
-
DEFAULT_API_VERSION
public static final java.lang.String DEFAULT_API_VERSION
Default OSM API version- See Also:
- Constant Field Values
-
osmConform
private final boolean osmConform
-
withBody
private boolean withBody
-
withVisible
private boolean withVisible
-
isOsmChange
private boolean isOsmChange
-
version
private java.lang.String version
-
byIdComparator
protected static final java.util.Comparator<AbstractPrimitive> byIdComparator
Sorts-1
→-infinity
, then+1
→+infinity
-
byKeyComparator
protected static final java.util.Comparator<java.util.Map.Entry<java.lang.String,java.lang.String>> byKeyComparator
-
-
Constructor Detail
-
OsmWriter
protected OsmWriter(java.io.PrintWriter out, boolean osmConform, java.lang.String version)
Constructs a newOsmWriter
. Do not call this directly. UseOsmWriterFactory
instead.- Parameters:
out
- print writerosmConform
- iftrue
, prevents modification attributes to be written to the common partversion
- OSM API version (0.6)
-
-
Method Detail
-
setWithBody
public void setWithBody(boolean wb)
Sets whether body must be written.- Parameters:
wb
- iftrue
body will be written.
-
setWithVisible
public void setWithVisible(boolean wv)
Sets whether 'visible' attribute must be written.- Parameters:
wv
- iftrue
'visible' attribute will be written.- Since:
- 12019
-
setIsOsmChange
public void setIsOsmChange(boolean isOsmChange)
-
setChangeset
public void setChangeset(Changeset cs)
-
setVersion
public void setVersion(java.lang.String v)
-
header
public void header()
Writes OSM header with normal download and upload policies.
-
header
public void header(DownloadPolicy download, UploadPolicy upload)
Writes OSM header with given download upload policies.- Parameters:
download
- download policyupload
- upload policy- Since:
- 13485
-
header
private void header(DownloadPolicy download, UploadPolicy upload, boolean locked)
-
footer
public void footer()
Writes OSM footer.
-
sortById
protected <T extends OsmPrimitive> java.util.Collection<T> sortById(java.util.Collection<T> primitives)
-
write
public void write(DataSet data)
Writes the full OSM file for the given data set (header, data sources, osm data, footer).- Parameters:
data
- OSM data set- Since:
- 12800
-
writeContent
public void writeContent(DataSet ds)
Writes the contents of the given dataset (nodes, then ways, then relations)- Parameters:
ds
- The dataset to write
-
writeNodes
public void writeNodes(java.util.Collection<Node> nodes)
Writes the given nodes sorted by id- Parameters:
nodes
- The nodes to write- Since:
- 5737
-
writeWays
public void writeWays(java.util.Collection<Way> ways)
Writes the given ways sorted by id- Parameters:
ways
- The ways to write- Since:
- 5737
-
writeRelations
public void writeRelations(java.util.Collection<Relation> relations)
Writes the given relations sorted by id- Parameters:
relations
- The relations to write- Since:
- 5737
-
shouldWrite
protected boolean shouldWrite(OsmPrimitive osm)
-
writeDataSources
public void writeDataSources(DataSet ds)
Writes data sources with their respective bounds.- Parameters:
ds
- data set
-
writeLatLon
void writeLatLon(LatLon ll)
-
visit
public void visit(INode n)
Description copied from interface:PrimitiveVisitor
Visiting call for nodes.- Specified by:
visit
in interfacePrimitiveVisitor
- Parameters:
n
- The node to inspect.
-
visit
public void visit(IWay<?> w)
Description copied from interface:PrimitiveVisitor
Visiting call for ways.- Specified by:
visit
in interfacePrimitiveVisitor
- Parameters:
w
- The way to inspect.
-
visit
public void visit(IRelation<?> e)
Description copied from interface:PrimitiveVisitor
Visiting call for relations.- Specified by:
visit
in interfacePrimitiveVisitor
- Parameters:
e
- The relation to inspect.
-
addCommon
protected void addCommon(IPrimitive osm, java.lang.String tagname)
Add the common part as the form of the tag as well as the XML attributes id, action, user, and visible.- Parameters:
osm
- osm primitivetagname
- XML tag matching osm primitive (node, way, relation)
-
-