Search in sources :

Example 1 with EntityContainer

use of de.topobyte.osm4j.core.model.iface.EntityContainer in project osm4j-pbf by topobyte.

the class TestCountIterator method main.

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.out.println("usage: " + TestCountIterator.class.getSimpleName() + " <filename>");
        System.exit(1);
    }
    File file = new File(args[0]);
    FileInputStream input = new FileInputStream(file);
    Iterator<EntityContainer> iterator = new PbfIterator(input, false);
    long nc = 0, wc = 0, rc = 0;
    while (iterator.hasNext()) {
        EntityContainer entityContainer = iterator.next();
        switch(entityContainer.getType()) {
            case Node:
                nc++;
                break;
            case Way:
                wc++;
                break;
            case Relation:
                rc++;
                break;
        }
    }
    System.out.println("nodes: " + nc);
    System.out.println("ways: " + wc);
    System.out.println("relations: " + rc);
}
Also used : EntityContainer(de.topobyte.osm4j.core.model.iface.EntityContainer) File(java.io.File) PbfIterator(de.topobyte.osm4j.pbf.seq.PbfIterator) FileInputStream(java.io.FileInputStream)

Example 2 with EntityContainer

use of de.topobyte.osm4j.core.model.iface.EntityContainer in project osm4j-core by topobyte.

the class IdDataSetReader method read.

public static InMemorySetIdDataSet read(OsmIterator iterator) throws IOException {
    InMemorySetIdDataSet dataSet = new InMemorySetIdDataSet();
    TLongSet nodeIds = dataSet.getNodeIds();
    TLongSet wayIds = dataSet.getWayIds();
    TLongSet relationIds = dataSet.getRelationIds();
    if (iterator.hasBounds()) {
        dataSet.setBounds(iterator.getBounds());
    }
    while (iterator.hasNext()) {
        EntityContainer container = iterator.next();
        switch(container.getType()) {
            case Node:
                nodeIds.add(container.getEntity().getId());
                break;
            case Way:
                wayIds.add(container.getEntity().getId());
                break;
            case Relation:
                relationIds.add(container.getEntity().getId());
                break;
        }
    }
    return dataSet;
}
Also used : TLongSet(com.slimjars.dist.gnu.trove.set.TLongSet) EntityContainer(de.topobyte.osm4j.core.model.iface.EntityContainer)

Example 3 with EntityContainer

use of de.topobyte.osm4j.core.model.iface.EntityContainer in project osm4j-core by topobyte.

the class ListDataSetLoader method read.

public static InMemoryListDataSet read(OsmIterator iterator, boolean keepNodeTags, boolean keepWayTags, boolean keepRelationTags) throws IOException {
    InMemoryListDataSet dataSet = new InMemoryListDataSet();
    List<OsmNode> nodes = dataSet.getNodes();
    List<OsmWay> ways = dataSet.getWays();
    List<OsmRelation> relations = dataSet.getRelations();
    if (iterator.hasBounds()) {
        dataSet.setBounds(iterator.getBounds());
    }
    while (iterator.hasNext()) {
        EntityContainer container = iterator.next();
        switch(container.getType()) {
            case Node:
                OsmNode node = (OsmNode) container.getEntity();
                if (!keepNodeTags) {
                    node = new Node(node.getId(), node.getLongitude(), node.getLatitude());
                }
                nodes.add(node);
                break;
            case Way:
                OsmWay way = (OsmWay) container.getEntity();
                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);
                break;
            case Relation:
                OsmRelation relation = (OsmRelation) container.getEntity();
                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);
                break;
        }
    }
    return dataSet;
}
Also used : TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) Node(de.topobyte.osm4j.core.model.impl.Node) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) EntityContainer(de.topobyte.osm4j.core.model.iface.EntityContainer) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Way(de.topobyte.osm4j.core.model.impl.Way) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Relation(de.topobyte.osm4j.core.model.impl.Relation) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Example 4 with EntityContainer

use of de.topobyte.osm4j.core.model.iface.EntityContainer in project osm4j-core by topobyte.

the class MapDataSetLoader method read.

public static InMemoryMapDataSet read(OsmIterator iterator, boolean keepNodeTags, boolean keepWayTags, boolean keepRelationTags) throws IOException {
    InMemoryMapDataSet dataSet = new InMemoryMapDataSet();
    TLongObjectMap<OsmNode> nodes = dataSet.getNodes();
    TLongObjectMap<OsmWay> ways = dataSet.getWays();
    TLongObjectMap<OsmRelation> relations = dataSet.getRelations();
    if (iterator.hasBounds()) {
        dataSet.setBounds(iterator.getBounds());
    }
    while (iterator.hasNext()) {
        EntityContainer container = iterator.next();
        switch(container.getType()) {
            case Node:
                OsmNode node = (OsmNode) container.getEntity();
                if (!keepNodeTags) {
                    node = new Node(node.getId(), node.getLongitude(), node.getLatitude());
                }
                nodes.put(node.getId(), node);
                break;
            case Way:
                OsmWay way = (OsmWay) container.getEntity();
                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);
                break;
            case Relation:
                OsmRelation relation = (OsmRelation) container.getEntity();
                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);
                break;
        }
    }
    return dataSet;
}
Also used : TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) Node(de.topobyte.osm4j.core.model.impl.Node) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) EntityContainer(de.topobyte.osm4j.core.model.iface.EntityContainer) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Way(de.topobyte.osm4j.core.model.impl.Way) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Relation(de.topobyte.osm4j.core.model.impl.Relation) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Example 5 with EntityContainer

use of de.topobyte.osm4j.core.model.iface.EntityContainer in project osm4j-core by topobyte.

the class EntityIterator method advance.

private void advance() {
    while (iterator.hasNext()) {
        EntityContainer container = iterator.next();
        if (container.getType() != type) {
            continue;
        }
        valid = true;
        hasNext = true;
        next = (T) container.getEntity();
        return;
    }
    valid = true;
    hasNext = false;
    next = null;
}
Also used : EntityContainer(de.topobyte.osm4j.core.model.iface.EntityContainer)

Aggregations

EntityContainer (de.topobyte.osm4j.core.model.iface.EntityContainer)6 TLongArrayList (com.slimjars.dist.gnu.trove.list.array.TLongArrayList)2 OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)2 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)2 OsmRelationMember (de.topobyte.osm4j.core.model.iface.OsmRelationMember)2 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)2 Node (de.topobyte.osm4j.core.model.impl.Node)2 Relation (de.topobyte.osm4j.core.model.impl.Relation)2 Way (de.topobyte.osm4j.core.model.impl.Way)2 PbfIterator (de.topobyte.osm4j.pbf.seq.PbfIterator)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 TLongSet (com.slimjars.dist.gnu.trove.set.TLongSet)1 OsmIterator (de.topobyte.osm4j.core.access.OsmIterator)1 OsmOutputStream (de.topobyte.osm4j.core.access.OsmOutputStream)1 PbfWriter (de.topobyte.osm4j.pbf.seq.PbfWriter)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1