Search in sources :

Example 1 with OsmMetadata

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

the class PrimParser method convert.

public OsmWay convert(Osmformat.Way w) {
    long id = w.getId();
    TLongArrayList nodes = new TLongArrayList();
    long lastId = 0;
    for (long j : w.getRefsList()) {
        nodes.add(j + lastId);
        lastId = j + lastId;
    }
    List<OsmTag> tags = new ArrayList<>();
    for (int j = 0; j < w.getKeysCount(); j++) {
        tags.add(new Tag(strings[w.getKeys(j)], strings[w.getVals(j)]));
    }
    OsmMetadata metadata = null;
    if (fetchMetadata && w.hasInfo()) {
        Osmformat.Info info = w.getInfo();
        metadata = convertMetadata(info);
    }
    return new Way(id, nodes, tags, metadata);
}
Also used : TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag) 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) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Way(de.topobyte.osm4j.core.model.impl.Way)

Example 2 with OsmMetadata

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

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

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

the class ImplUtil method clone.

public static Node clone(OsmNode node) {
    List<? extends OsmTag> tags = cloneTags(node);
    OsmMetadata metadata = cloneMetadata(node);
    return new Node(node.getId(), node.getLongitude(), node.getLatitude(), tags, metadata);
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) Node(de.topobyte.osm4j.core.model.impl.Node) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode)

Example 5 with OsmMetadata

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

the class ImplUtil method clone.

public static Way clone(OsmWay way) {
    List<? extends OsmTag> tags = cloneTags(way);
    OsmMetadata metadata = cloneMetadata(way);
    TLongList nodes = new TLongArrayList(way.getNumberOfNodes());
    for (int i = 0; i < way.getNumberOfNodes(); i++) {
        nodes.add(way.getNodeId(i));
    }
    return new Way(way.getId(), nodes, tags, metadata);
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) TLongList(com.slimjars.dist.gnu.trove.list.TLongList) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Way(de.topobyte.osm4j.core.model.impl.Way)

Aggregations

OsmMetadata (de.topobyte.osm4j.core.model.iface.OsmMetadata)12 TLongArrayList (com.slimjars.dist.gnu.trove.list.array.TLongArrayList)7 ArrayList (java.util.ArrayList)6 OsmTag (de.topobyte.osm4j.core.model.iface.OsmTag)5 Tag (de.topobyte.osm4j.core.model.impl.Tag)5 Osmformat (de.topobyte.osm4j.pbf.protobuf.Osmformat)5 OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)4 Metadata (de.topobyte.osm4j.core.model.impl.Metadata)4 Node (de.topobyte.osm4j.core.model.impl.Node)4 OsmEntity (de.topobyte.osm4j.core.model.iface.OsmEntity)2 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)2 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)2 Relation (de.topobyte.osm4j.core.model.impl.Relation)2 RelationMember (de.topobyte.osm4j.core.model.impl.RelationMember)2 Way (de.topobyte.osm4j.core.model.impl.Way)2 ByteString (com.google.protobuf.ByteString)1 TLongList (com.slimjars.dist.gnu.trove.list.TLongList)1 EntityType (de.topobyte.osm4j.core.model.iface.EntityType)1 OsmRelationMember (de.topobyte.osm4j.core.model.iface.OsmRelationMember)1