use of de.topobyte.osm4j.core.model.iface.OsmBounds 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.core.model.iface.OsmBounds in project osm4j-core by topobyte.
the class IdDataSetReader method read.
public static InMemorySetIdDataSet read(OsmReader reader) throws OsmInputException {
final InMemorySetIdDataSet dataSet = new InMemorySetIdDataSet();
final TLongSet nodeIds = dataSet.getNodeIds();
final TLongSet wayIds = dataSet.getWayIds();
final TLongSet relationIds = dataSet.getRelationIds();
reader.setHandler(new OsmHandler() {
@Override
public void handle(OsmBounds bounds) throws IOException {
dataSet.setBounds(bounds);
}
@Override
public void handle(OsmNode node) throws IOException {
nodeIds.add(node.getId());
}
@Override
public void handle(OsmWay way) throws IOException {
wayIds.add(way.getId());
}
@Override
public void handle(OsmRelation relation) throws IOException {
relationIds.add(relation.getId());
}
@Override
public void complete() throws IOException {
// nothing to do here
}
});
reader.read();
return dataSet;
}
use of de.topobyte.osm4j.core.model.iface.OsmBounds in project osm4j-core by topobyte.
the class ListDataSetLoader method read.
public static InMemoryListDataSet read(OsmReader reader, final boolean keepNodeTags, final boolean keepWayTags, final boolean keepRelationTags) throws OsmInputException {
final InMemoryListDataSet dataSet = new InMemoryListDataSet();
final List<OsmNode> nodes = dataSet.getNodes();
final List<OsmWay> ways = dataSet.getWays();
final List<OsmRelation> relations = dataSet.getRelations();
reader.setHandler(new OsmHandler() {
@Override
public void handle(OsmBounds bounds) throws IOException {
dataSet.setBounds(bounds);
}
@Override
public void handle(OsmNode node) throws IOException {
if (!keepNodeTags) {
node = new Node(node.getId(), node.getLongitude(), node.getLatitude());
}
nodes.add(node);
}
@Override
public void handle(OsmWay way) throws IOException {
if (!keepWayTags) {
TLongArrayList ids = new TLongArrayList();
for (int i = 0; i < way.getNumberOfNodes(); i++) {
ids.add(way.getNodeId(i));
}
way = new Way(way.getId(), ids);
}
ways.add(way);
}
@Override
public void handle(OsmRelation relation) throws IOException {
if (!keepRelationTags) {
List<OsmRelationMember> members = new ArrayList<>();
for (int i = 0; i < relation.getNumberOfMembers(); i++) {
members.add(relation.getMember(i));
}
relation = new Relation(relation.getId(), members);
}
relations.add(relation);
}
@Override
public void complete() throws IOException {
// nothing to do here
}
});
reader.read();
return dataSet;
}
use of de.topobyte.osm4j.core.model.iface.OsmBounds in project osm4j-core by topobyte.
the class MapDataSetLoader method read.
public static InMemoryMapDataSet read(OsmReader reader, final boolean keepNodeTags, final boolean keepWayTags, final boolean keepRelationTags) throws OsmInputException {
final InMemoryMapDataSet dataSet = new InMemoryMapDataSet();
final TLongObjectMap<OsmNode> nodes = dataSet.getNodes();
final TLongObjectMap<OsmWay> ways = dataSet.getWays();
final TLongObjectMap<OsmRelation> relations = dataSet.getRelations();
reader.setHandler(new OsmHandler() {
@Override
public void handle(OsmBounds bounds) throws IOException {
dataSet.setBounds(bounds);
}
@Override
public void handle(OsmNode node) throws IOException {
if (!keepNodeTags) {
node = new Node(node.getId(), node.getLongitude(), node.getLatitude());
}
nodes.put(node.getId(), node);
}
@Override
public void handle(OsmWay way) throws IOException {
if (!keepWayTags) {
TLongArrayList ids = new TLongArrayList();
for (int i = 0; i < way.getNumberOfNodes(); i++) {
ids.add(way.getNodeId(i));
}
way = new Way(way.getId(), ids);
}
ways.put(way.getId(), way);
}
@Override
public void handle(OsmRelation relation) throws IOException {
if (!keepRelationTags) {
List<OsmRelationMember> members = new ArrayList<>();
for (int i = 0; i < relation.getNumberOfMembers(); i++) {
members.add(relation.getMember(i));
}
relation = new Relation(relation.getId(), members);
}
relations.put(relation.getId(), relation);
}
@Override
public void complete() throws IOException {
// nothing to do here
}
});
reader.read();
return dataSet;
}
use of de.topobyte.osm4j.core.model.iface.OsmBounds in project osm4j-core by topobyte.
the class IdDataSetReader method read.
public static InMemorySetIdDataSet read(OsmIdReader reader) throws OsmInputException {
final InMemorySetIdDataSet dataSet = new InMemorySetIdDataSet();
final TLongSet nodeIds = dataSet.getNodeIds();
final TLongSet wayIds = dataSet.getWayIds();
final TLongSet relationIds = dataSet.getRelationIds();
reader.setIdHandler(new OsmIdHandler() {
@Override
public void handle(OsmBounds bounds) throws IOException {
dataSet.setBounds(bounds);
}
@Override
public void handleNode(long id) throws IOException {
nodeIds.add(id);
}
@Override
public void handleWay(long id) throws IOException {
wayIds.add(id);
}
@Override
public void handleRelation(long id) throws IOException {
relationIds.add(id);
}
@Override
public void complete() throws IOException {
// nothing to do here
}
});
reader.read();
return dataSet;
}
Aggregations