Search in sources :

Example 6 with OsmTag

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

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

the class ImplUtil method cloneTags.

private static List<? extends OsmTag> cloneTags(OsmEntity entity) {
    List<Tag> tags = new ArrayList<>();
    for (int i = 0; i < entity.getNumberOfTags(); i++) {
        OsmTag tag = entity.getTag(i);
        tags.add(new Tag(tag.getKey(), tag.getValue()));
    }
    return tags;
}
Also used : 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)

Example 8 with OsmTag

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

the class OsmModelUtil method getTagsAsMap.

/**
 * Construct a Map containing all tags of this entity.
 *
 * @param entity
 *            an osm entity.
 * @return the entity's tags as a map.
 */
public static Map<String, String> getTagsAsMap(OsmEntity entity) {
    Map<String, String> map = new HashMap<>();
    for (int i = 0; i < entity.getNumberOfTags(); i++) {
        OsmTag tag = entity.getTag(i);
        map.put(tag.getKey(), tag.getValue());
    }
    return map;
}
Also used : HashMap(java.util.HashMap) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag)

Example 9 with OsmTag

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

the class OsmModelUtil method getTagsAsList.

public static List<? extends OsmTag> getTagsAsList(OsmEntity entity) {
    List<OsmTag> list = new ArrayList<>();
    for (int i = 0; i < entity.getNumberOfTags(); i++) {
        OsmTag tag = entity.getTag(i);
        list.add(tag);
    }
    return list;
}
Also used : OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) ArrayList(java.util.ArrayList)

Example 10 with OsmTag

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

the class PbfWriter method addTagsToStringTable.

private void addTagsToStringTable(Collection<? extends OsmEntity> entities) {
    for (OsmEntity entity : entities) {
        for (int k = 0; k < entity.getNumberOfTags(); k++) {
            OsmTag tag = entity.getTag(k);
            stringTable.incr(tag.getKey());
            stringTable.incr(tag.getValue());
        }
    }
}
Also used : OsmEntity(de.topobyte.osm4j.core.model.iface.OsmEntity) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag)

Aggregations

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