Search in sources :

Example 1 with Node

use of de.topobyte.osm4j.core.model.impl.Node in project osm4j-pbf by topobyte.

the class PrimParser method convert.

public OsmNode convert(Osmformat.Node n) {
    long id = n.getId();
    double lat = parseLat(n.getLat());
    double lon = parseLon(n.getLon());
    List<OsmTag> tags = new ArrayList<>();
    for (int j = 0; j < n.getKeysCount(); j++) {
        tags.add(new Tag(strings[n.getKeys(j)], strings[n.getVals(j)]));
    }
    OsmMetadata metadata = null;
    if (fetchMetadata && n.hasInfo()) {
        Osmformat.Info info = n.getInfo();
        metadata = convertMetadata(info);
    }
    return new Node(id, lon, lat, tags, metadata);
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag) Node(de.topobyte.osm4j.core.model.impl.Node) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) Tag(de.topobyte.osm4j.core.model.impl.Tag) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat)

Example 2 with Node

use of de.topobyte.osm4j.core.model.impl.Node in project osm4j-pbf by topobyte.

the class PrimParser method convert.

public List<OsmNode> convert(Osmformat.DenseNodes nodes) {
    List<OsmNode> results = new ArrayList<>(nodes.getIdCount());
    Osmformat.DenseInfo denseInfo = null;
    boolean hasVisible = false;
    if (fetchMetadata && nodes.hasDenseinfo()) {
        denseInfo = nodes.getDenseinfo();
        hasVisible = denseInfo.getVisibleCount() != 0;
    }
    long id = 0, lat = 0, lon = 0;
    int version = 0, uid = 0, userSid = 0;
    long timestamp = 0, changeset = 0;
    // Index into the keysvals array.
    int j = 0;
    for (int i = 0; i < nodes.getIdCount(); i++) {
        id += nodes.getId(i);
        lat += nodes.getLat(i);
        lon += nodes.getLon(i);
        double latf = parseLat(lat), lonf = parseLon(lon);
        List<OsmTag> tags = new ArrayList<>();
        OsmMetadata metadata = null;
        if (fetchMetadata && nodes.hasDenseinfo()) {
            version = denseInfo.getVersion(i);
            timestamp += denseInfo.getTimestamp(i);
            uid += denseInfo.getUid(i);
            userSid += denseInfo.getUserSid(i);
            changeset += denseInfo.getChangeset(i);
            boolean visible = true;
            if (hasVisible) {
                visible = denseInfo.getVisible(i);
            }
            metadata = new Metadata(version, timestamp * dateGranularity, uid, strings[userSid], changeset, visible);
        }
        // If empty, assume that nothing here has keys or vals.
        if (nodes.getKeysValsCount() > 0) {
            while (nodes.getKeysVals(j) != 0) {
                int keyid = nodes.getKeysVals(j++);
                int valid = nodes.getKeysVals(j++);
                tags.add(new Tag(strings[keyid], strings[valid]));
            }
            // Skip over the '0' delimiter.
            j++;
        }
        results.add(new Node(id, lonf, latf, tags, metadata));
    }
    return results;
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag) Node(de.topobyte.osm4j.core.model.impl.Node) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) Metadata(de.topobyte.osm4j.core.model.impl.Metadata) OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat) Tag(de.topobyte.osm4j.core.model.impl.Tag) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag)

Example 3 with Node

use of de.topobyte.osm4j.core.model.impl.Node 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;
}
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 4 with Node

use of de.topobyte.osm4j.core.model.impl.Node 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 5 with Node

use of de.topobyte.osm4j.core.model.impl.Node 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)

Aggregations

OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)8 Node (de.topobyte.osm4j.core.model.impl.Node)8 TLongArrayList (com.slimjars.dist.gnu.trove.list.array.TLongArrayList)7 ArrayList (java.util.ArrayList)7 OsmMetadata (de.topobyte.osm4j.core.model.iface.OsmMetadata)4 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)4 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)4 Relation (de.topobyte.osm4j.core.model.impl.Relation)4 Way (de.topobyte.osm4j.core.model.impl.Way)4 OsmTag (de.topobyte.osm4j.core.model.iface.OsmTag)3 Tag (de.topobyte.osm4j.core.model.impl.Tag)3 Osmformat (de.topobyte.osm4j.pbf.protobuf.Osmformat)3 OsmHandler (de.topobyte.osm4j.core.access.OsmHandler)2 EntityContainer (de.topobyte.osm4j.core.model.iface.EntityContainer)2 OsmBounds (de.topobyte.osm4j.core.model.iface.OsmBounds)2 OsmRelationMember (de.topobyte.osm4j.core.model.iface.OsmRelationMember)2 Metadata (de.topobyte.osm4j.core.model.impl.Metadata)2 IOException (java.io.IOException)2 List (java.util.List)2