Search in sources :

Example 6 with OsmWay

use of de.topobyte.osm4j.core.model.iface.OsmWay 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 7 with OsmWay

use of de.topobyte.osm4j.core.model.iface.OsmWay 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 8 with OsmWay

use of de.topobyte.osm4j.core.model.iface.OsmWay 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;
}
Also used : OsmBounds(de.topobyte.osm4j.core.model.iface.OsmBounds) 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) OsmHandler(de.topobyte.osm4j.core.access.OsmHandler) IOException(java.io.IOException) 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) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) List(java.util.List)

Example 9 with OsmWay

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

the class EntityFinderLogMissing method findWays.

@Override
public List<OsmWay> findWays(TLongCollection ids) throws EntityNotFoundException {
    List<OsmWay> ways = new ArrayList<>();
    TLongIterator idIterator = ids.iterator();
    while (idIterator.hasNext()) {
        long id = idIterator.next();
        try {
            ways.add(entityProvider.getWay(id));
        } catch (EntityNotFoundException e) {
            logWayNotFound(id);
        }
    }
    return ways;
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) ArrayList(java.util.ArrayList) TLongIterator(com.slimjars.dist.gnu.trove.iterator.TLongIterator)

Example 10 with OsmWay

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

the class RelationUtil method buildWayTailMap.

/**
 * For all ways given, build a multivalmap from node-ids to ways. Head and
 * tail of each way are put as key and the way as value.
 */
public static CountingMultiValMap<Long, OsmWay> buildWayTailMap(MultiSet<OsmWay> ways) {
    CountingMultiValMap<Long, OsmWay> waysNodes = new CountingMultiValMap<>();
    for (OsmWay way : ways) {
        // add all of them to waysNodes. implement iterator correctly...
        int nnodes = way.getNumberOfNodes();
        if (nnodes < 2) {
            throw new IllegalArgumentException("Only ways with 2 or more nodes are allowed");
        }
        long node1 = way.getNodeId(0);
        long nodeN = way.getNodeId(nnodes - 1);
        waysNodes.add(node1, way);
        waysNodes.add(nodeN, way);
    }
    return waysNodes;
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) CountingMultiValMap(de.topobyte.adt.multicollections.CountingMultiValMap)

Aggregations

OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)24 OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)10 ArrayList (java.util.ArrayList)10 TLongArrayList (com.slimjars.dist.gnu.trove.list.array.TLongArrayList)9 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)7 Way (de.topobyte.osm4j.core.model.impl.Way)7 OsmHandler (de.topobyte.osm4j.core.access.OsmHandler)4 OsmBounds (de.topobyte.osm4j.core.model.iface.OsmBounds)4 Node (de.topobyte.osm4j.core.model.impl.Node)4 Relation (de.topobyte.osm4j.core.model.impl.Relation)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 TLongIterator (com.slimjars.dist.gnu.trove.iterator.TLongIterator)3 EntityFinder (de.topobyte.osm4j.core.resolve.EntityFinder)3 EntityNotFoundException (de.topobyte.osm4j.core.resolve.EntityNotFoundException)3 EntityNotFoundStrategy (de.topobyte.osm4j.core.resolve.EntityNotFoundStrategy)3 TLongList (com.slimjars.dist.gnu.trove.list.TLongList)2 EntityContainer (de.topobyte.osm4j.core.model.iface.EntityContainer)2 OsmMetadata (de.topobyte.osm4j.core.model.iface.OsmMetadata)2 OsmRelationMember (de.topobyte.osm4j.core.model.iface.OsmRelationMember)2