Search in sources :

Example 1 with OsmRelation

use of com.revolsys.record.io.format.openstreetmap.model.OsmRelation in project com.revolsys.open by revolsys.

the class OsmPbfRecordIterator method parseRelation.

private void parseRelation(final ProtocolBufferInputStream input) throws IOException {
    final OsmRelation relation = new OsmRelation();
    final List<String> keys = new ArrayList<>();
    final List<String> values = new ArrayList<>();
    final List<Long> memberIds = new ArrayList<>();
    final List<Integer> memberTypes = new ArrayList<>();
    final List<String> memberRoles = new ArrayList<>();
    final int inLength = input.startLengthDelimited();
    boolean running = true;
    while (running) {
        final int tag = input.readTag();
        switch(tag) {
            case 0:
                running = false;
                break;
            case 8:
                final long id = input.readInt64();
                relation.setId(id);
                break;
            case 16:
                readStringById(input, keys);
                break;
            case 18:
                readStringsByIds(input, keys);
                break;
            case 24:
                readStringById(input, values);
                break;
            case 26:
                readStringsByIds(input, values);
                break;
            case 34:
                parseInfo(input, relation);
                break;
            case 64:
                readStrings(input, memberRoles);
                break;
            case 66:
                readStringsByIds(input, memberRoles);
                break;
            case 72:
                input.readLong(memberIds);
                break;
            case 74:
                input.readLongs(memberIds);
                break;
            case 80:
                input.readEnum(memberTypes);
                break;
            case 82:
                input.readEnums(memberTypes);
                break;
            default:
                input.skipField(tag);
                break;
        }
    }
    input.endLengthDelimited(inLength);
    addTags(relation, keys, values);
    final List<Geometry> parts = new ArrayList<>();
    long memberId = 0;
    for (int i = 0; i < memberIds.size(); i++) {
        final long memberIdOffset = memberIds.get(i);
        memberId += memberIdOffset;
        Geometry geometry = null;
        final int memberType = memberTypes.get(i);
        switch(memberType) {
            case 0:
                geometry = this.nodePoints.get(memberId);
                break;
            case 1:
                geometry = this.wayGeometries.get(memberId);
                break;
            default:
                throw new RuntimeException("Unknown member type " + memberType);
        }
        if (geometry != null) {
            parts.add(geometry);
        }
    }
    if (memberIds.size() == parts.size()) {
        final Geometry geometry = OsmConstants.WGS84_2D.geometry(parts);
        if (memberTypes.get(0) == 1 && !Property.hasValue(memberRoles.get(0))) {
        }
        relation.setGeometryValue(geometry);
        this.currentRecords.add(relation);
        final long relationId = relation.getId();
        this.relationGeometries.put(relationId, geometry);
    } else {
        this.relations.add(relation);
        this.relationMemberIds.add(memberIds);
        this.relationMemberRoles.add(memberRoles);
        this.relationMemberTypes.add(memberTypes);
    }
}
Also used : OsmRelation(com.revolsys.record.io.format.openstreetmap.model.OsmRelation) ArrayList(java.util.ArrayList) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Geometry(com.revolsys.geometry.model.Geometry)

Aggregations

Geometry (com.revolsys.geometry.model.Geometry)1 LineString (com.revolsys.geometry.model.LineString)1 Point (com.revolsys.geometry.model.Point)1 OsmRelation (com.revolsys.record.io.format.openstreetmap.model.OsmRelation)1 ArrayList (java.util.ArrayList)1