@Override
 public void write(OsmRelation relation) {
   out.print("  <relation id=\"" + relation.getId() + "\"");
   if (printMetadata) {
     OsmMetadata metadata = relation.getMetadata();
     printMetadata(metadata);
   }
   if (relation.getNumberOfTags() == 0 && relation.getNumberOfMembers() == 0) {
     out.println("/>");
   } else {
     out.println(">");
     for (int i = 0; i < relation.getNumberOfMembers(); i++) {
       OsmRelationMember member = relation.getMember(i);
       EntityType type = member.getType();
       String t = type == EntityType.Node ? "node" : type == EntityType.Way ? "way" : "relation";
       String role = member.getRole();
       role = StringEscapeUtils.escapeXml(role);
       out.println(
           "    <member type=\""
               + t
               + "\" ref=\""
               + member.getId()
               + "\" role=\""
               + role
               + "\"/>");
     }
     printTags(relation);
     out.println("  </relation>");
   }
 }
Example #2
0
  private void process(OsmRelation relation) {
    boolean hasChildRelations = false;
    TLongList childRelationMembers = new TLongArrayList();
    for (OsmRelationMember member : OsmModelUtil.membersAsList(relation)) {
      if (member.getType() == EntityType.Relation) {
        hasChildRelations = true;
        idsIsChildRelation.add(member.getId());
        childRelationMembers.add(member.getId());
        if (storeSimpleRelations) {
          idsSimpleRelations.remove(member.getId());
        }
      }
    }
    long id = relation.getId();
    if (hasChildRelations) {
      idsHasChildRelations.add(id);
      if (!graph.getNodes().contains(id)) {
        graph.addNode(id);
      }

      TLongIterator iterator = childRelationMembers.iterator();
      while (iterator.hasNext()) {
        long member = iterator.next();
        if (!graph.getNodes().contains(member)) {
          graph.addNode(member);
        }
        graph.addEdge(id, member);
      }
    } else {
      if (storeSimpleRelations && !idsIsChildRelation.contains(id)) {
        idsSimpleRelations.add(id);
      }
      numNoChildren++;
    }
  }