Search in sources :

Example 1 with Info

use of com.baremaps.osm.domain.Info in project baremaps by baremaps.

the class OsmXmlSpliterator method readNode.

private Node readNode() throws XMLStreamException {
    long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_ID));
    Info info = readInfo();
    double latitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LATITUDE));
    double longitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LONGITUDE));
    // read the content of the node
    Map<String, String> tags = new HashMap<>();
    reader.nextTag();
    while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
        switch(reader.getLocalName()) {
            case ELEMENT_NAME_TAG:
                readTag(tags);
                break;
            default:
                readUnknownElement();
                break;
        }
    }
    return new Node(id, info, tags, longitude, latitude);
}
Also used : HashMap(java.util.HashMap) Node(com.baremaps.osm.domain.Node) Info(com.baremaps.osm.domain.Info)

Example 2 with Info

use of com.baremaps.osm.domain.Info in project baremaps by baremaps.

the class DataBlockReader method readDenseNodes.

/**
 * Read the dense nodes with the provided consumer.
 *
 * @param consumer the consumer
 */
public void readDenseNodes(Consumer<Node> consumer) {
    for (PrimitiveGroup group : primitiveBlock.getPrimitivegroupList()) {
        DenseNodes denseNodes = group.getDense();
        long id = 0;
        long lat = 0;
        long lon = 0;
        long timestamp = 0;
        long changeset = 0;
        int sid = 0;
        int uid = 0;
        // Index into the keysvals array.
        int j = 0;
        for (int i = 0; i < denseNodes.getIdCount(); i++) {
            id = denseNodes.getId(i) + id;
            Osmformat.DenseInfo denseInfo = denseNodes.getDenseinfo();
            int version = denseInfo.getVersion(i);
            uid = denseInfo.getUid(i) + uid;
            sid = denseInfo.getUserSid(i) + sid;
            timestamp = denseInfo.getTimestamp(i) + timestamp;
            changeset = denseInfo.getChangeset(i) + changeset;
            lat = denseNodes.getLat(i) + lat;
            lon = denseNodes.getLon(i) + lon;
            // If empty, assume that nothing here has keys or vals.
            Map<String, String> tags = new HashMap<>();
            if (denseNodes.getKeysValsCount() > 0) {
                while (denseNodes.getKeysVals(j) != 0) {
                    int keyid = denseNodes.getKeysVals(j++);
                    int valid = denseNodes.getKeysVals(j++);
                    tags.put(getString(keyid), getString(valid));
                }
                // Skip over the '0' delimiter.
                j++;
            }
            Info info = new Info(version, getTimestamp(timestamp), changeset, uid);
            consumer.accept(new Node(id, info, tags, getLon(lon), getLat(lat)));
        }
    }
}
Also used : PrimitiveGroup(com.baremaps.osm.binary.Osmformat.PrimitiveGroup) HashMap(java.util.HashMap) Node(com.baremaps.osm.domain.Node) DenseNodes(com.baremaps.osm.binary.Osmformat.DenseNodes) Osmformat(com.baremaps.osm.binary.Osmformat) Info(com.baremaps.osm.domain.Info)

Example 3 with Info

use of com.baremaps.osm.domain.Info in project baremaps by baremaps.

the class DataBlockReader method readWays.

/**
 * Read the ways with the provided consumer.
 *
 * @param consumer the consumer
 */
public void readWays(Consumer<Way> consumer) {
    for (PrimitiveGroup group : primitiveBlock.getPrimitivegroupList()) {
        for (Osmformat.Way way : group.getWaysList()) {
            long id = way.getId();
            int version = way.getInfo().getVersion();
            LocalDateTime timestamp = getTimestamp(way.getInfo().getTimestamp());
            long changeset = way.getInfo().getChangeset();
            int uid = way.getInfo().getUid();
            Map<String, String> tags = getTags(way.getKeysList(), way.getValsList());
            long nid = 0;
            List<Long> nodes = new ArrayList<>();
            for (int index = 0; index < way.getRefsCount(); index++) {
                nid = nid + way.getRefs(index);
                nodes.add(nid);
            }
            Info info = new Info(version, timestamp, changeset, uid);
            consumer.accept(new Way(id, info, tags, nodes));
        }
    }
}
Also used : PrimitiveGroup(com.baremaps.osm.binary.Osmformat.PrimitiveGroup) LocalDateTime(java.time.LocalDateTime) ArrayList(java.util.ArrayList) Osmformat(com.baremaps.osm.binary.Osmformat) Info(com.baremaps.osm.domain.Info) Way(com.baremaps.osm.domain.Way)

Example 4 with Info

use of com.baremaps.osm.domain.Info in project baremaps by baremaps.

the class DataBlockReader method readRelations.

/**
 * Read the relations with the provided consumer.
 *
 * @param consumer the consumer
 */
public void readRelations(Consumer<Relation> consumer) {
    for (PrimitiveGroup group : primitiveBlock.getPrimitivegroupList()) {
        for (Osmformat.Relation relation : group.getRelationsList()) {
            long id = relation.getId();
            int version = relation.getInfo().getVersion();
            LocalDateTime timestamp = getTimestamp(relation.getInfo().getTimestamp());
            long changeset = relation.getInfo().getChangeset();
            int uid = relation.getInfo().getUid();
            Map<String, String> tags = getTags(relation.getKeysList(), relation.getValsList());
            long mid = 0;
            List<Member> members = new ArrayList<>();
            for (int j = 0; j < relation.getMemidsCount(); j++) {
                mid = mid + relation.getMemids(j);
                String role = getString(relation.getRolesSid(j));
                MemberType type = type(relation.getTypes(j));
                members.add(new Member(mid, type, role));
            }
            Info info = new Info(version, timestamp, changeset, uid);
            consumer.accept(new Relation(id, info, tags, members));
        }
    }
}
Also used : PrimitiveGroup(com.baremaps.osm.binary.Osmformat.PrimitiveGroup) LocalDateTime(java.time.LocalDateTime) ArrayList(java.util.ArrayList) Osmformat(com.baremaps.osm.binary.Osmformat) Info(com.baremaps.osm.domain.Info) Relation(com.baremaps.osm.domain.Relation) MemberType(com.baremaps.osm.domain.Member.MemberType) Member(com.baremaps.osm.domain.Member)

Example 5 with Info

use of com.baremaps.osm.domain.Info in project baremaps by baremaps.

the class OsmChangeSpliterator method readRelation.

private Relation readRelation() throws XMLStreamException {
    long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_ID));
    Info info = readInfo();
    // read the content of the node
    Map<String, String> tags = new HashMap<>();
    List<Member> members = new ArrayList<>();
    reader.nextTag();
    while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
        switch(reader.getLocalName()) {
            case ELEMENT_NAME_TAG:
                readTag(tags);
                break;
            case ELEMENT_NAME_MEMBER:
                readRelationMember(members);
                break;
            default:
                readUnknownElement();
                break;
        }
    }
    return new Relation(id, info, tags, members);
}
Also used : Relation(com.baremaps.osm.domain.Relation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Info(com.baremaps.osm.domain.Info) Member(com.baremaps.osm.domain.Member)

Aggregations

Info (com.baremaps.osm.domain.Info)15 LocalDateTime (java.time.LocalDateTime)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Node (com.baremaps.osm.domain.Node)5 Osmformat (com.baremaps.osm.binary.Osmformat)4 PrimitiveGroup (com.baremaps.osm.binary.Osmformat.PrimitiveGroup)4 Member (com.baremaps.osm.domain.Member)4 Relation (com.baremaps.osm.domain.Relation)4 Way (com.baremaps.osm.domain.Way)4 Geometry (org.locationtech.jts.geom.Geometry)3 DenseNodes (com.baremaps.osm.binary.Osmformat.DenseNodes)1 MemberType (com.baremaps.osm.domain.Member.MemberType)1 Array (java.sql.Array)1