*/
protected void processRelationsAfterParsing() throws IllegalDataException {
// First add all relations to make sure that when relation reference other relation, the referenced will be already in dataset
for (Long externalRelationId : relations.keySet()) {
Relation relation = (Relation) externalIdMap.get(
new SimplePrimitiveId(externalRelationId, OsmPrimitiveType.RELATION)
);
ds.addPrimitive(relation);
}
for (Long externalRelationId : relations.keySet()) {
Relation relation = (Relation) externalIdMap.get(
new SimplePrimitiveId(externalRelationId, OsmPrimitiveType.RELATION)
);
List<RelationMember> relationMembers = new ArrayList<>();
for (RelationMemberData rm : relations.get(externalRelationId)) {
OsmPrimitive primitive = null;
// lookup the member from the map of already created primitives
primitive = externalIdMap.get(new SimplePrimitiveId(rm.getMemberId(), rm.getMemberType()));
if (primitive == null) {
if (rm.getMemberId() <= 0)
// relation member refers to a primitive with a negative id which was not
// found in the data. This is always a data integrity problem and we abort
// with an exception
//
throw new IllegalDataException(
tr("Relation with external id ''{0}'' refers to a missing primitive with external id ''{1}''.",
externalRelationId,
rm.getMemberId()));
// member refers to OSM primitive which was not present in the parsed data
// -> create a new incomplete primitive and add it to the dataset
//
primitive = ds.getPrimitiveById(rm.getMemberId(), rm.getMemberType());
if (primitive == null) {
switch (rm.getMemberType()) {
case NODE:
primitive = new Node(rm.getMemberId()); break;
case WAY:
primitive = new Way(rm.getMemberId()); break;
case RELATION:
primitive = new Relation(rm.getMemberId()); break;
default: throw new AssertionError(); // can't happen
}
ds.addPrimitive(primitive);
externalIdMap.put(new SimplePrimitiveId(rm.getMemberId(), rm.getMemberType()), primitive);
}
}
if (primitive.isDeleted()) {
Main.info(tr("Deleted member {0} is used by relation {1}", primitive.getId(), relation.getId()));
} else {
relationMembers.add(new RelationMember(rm.getRole(), primitive));
}
}
relation.setMembers(relationMembers);
}
}