use of de.topobyte.osm4j.pbf.seq.PbfWriter in project osm4j-pbf by topobyte.
the class CopyElementwise method main.
public static void main(String[] args) throws IOException, OsmInputException {
if (args.length != 2) {
System.out.println("usage: " + CopyElementwise.class.getSimpleName() + " <input> <output>");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
OutputStream output = new FileOutputStream(args[1]);
final PbfWriter writer = new PbfWriter(output, true);
PbfParser parser = new PbfParser(new OsmHandler() {
@Override
public void handle(OsmBounds bounds) throws IOException {
writer.write(bounds);
}
@Override
public void handle(OsmNode node) throws IOException {
writer.write(node);
}
@Override
public void handle(OsmWay way) throws IOException {
writer.write(way);
}
@Override
public void handle(OsmRelation relation) throws IOException {
writer.write(relation);
}
@Override
public void complete() throws IOException {
writer.complete();
}
}, true);
parser.parse(input);
output.close();
}
use of de.topobyte.osm4j.pbf.seq.PbfWriter in project osm4j-pbf by topobyte.
the class Util method copyAndRead.
public static void copyAndRead(String resource, boolean readMetadata, boolean writeMetadata) throws IOException {
InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
OsmIterator iterator = new PbfIterator(input, readMetadata);
File file = File.createTempFile("osm4j-test", "pbf");
OutputStream output = new FileOutputStream(file);
OsmOutputStream osmOutput = new PbfWriter(output, writeMetadata);
for (EntityContainer container : iterator) {
switch(container.getType()) {
default:
case Node:
osmOutput.write((OsmNode) container.getEntity());
break;
case Way:
osmOutput.write((OsmWay) container.getEntity());
break;
case Relation:
osmOutput.write((OsmRelation) container.getEntity());
break;
}
}
osmOutput.complete();
output.close();
Util.iterate(file, true);
Util.iterate(file, false);
file.delete();
}
Aggregations