Example #1
0
 /**
  * Serialize all nodes in the non-dense format.
  *
  * @param parentbuilder Add to this PrimitiveBlock.
  */
 public Osmformat.PrimitiveGroup serializeNonDense() {
   if (contents.size() == 0) {
     return null;
   }
   // System.out.format("%d Nodes   ",nodes.size());
   StringTable stable = serializer.getStringTable();
   Osmformat.PrimitiveGroup.Builder builder = Osmformat.PrimitiveGroup.newBuilder();
   for (Node i : contents) {
     long id = i.getId();
     int lat = mapDegrees(i.getLat());
     int lon = mapDegrees(i.getLon());
     Osmformat.Node.Builder bi = Osmformat.Node.newBuilder();
     bi.setId(id);
     bi.setLon(lon);
     bi.setLat(lat);
     Iterator<Element.Tag> tags = i.tagsIterator();
     while (tags.hasNext()) {
       Element.Tag t = tags.next();
       bi.addKeys(stable.getIndex(t.getKey()));
       bi.addVals(stable.getIndex(t.getValue()));
     }
     if (!omit_metadata) {
       bi.setInfo(serializeMetadata(i));
     }
     builder.addNodes(bi);
   }
   return builder.build();
 }
Example #2
0
      public Osmformat.PrimitiveGroup serialize() {
        if (contents.size() == 0) {
          return null;
        }

        // System.out.format("%d Ways  ",contents.size());
        StringTable stable = serializer.getStringTable();
        Osmformat.PrimitiveGroup.Builder builder = Osmformat.PrimitiveGroup.newBuilder();
        for (Way i : contents) {
          Osmformat.Way.Builder bi = Osmformat.Way.newBuilder();
          bi.setId(i.getId());
          long lastid = 0;
          for (long j : i.getRefs()) {
            long id = j;
            bi.addRefs(id - lastid);
            lastid = id;
          }
          Iterator<Element.Tag> tags = i.tagsIterator();
          while (tags.hasNext()) {
            Element.Tag t = tags.next();
            bi.addKeys(stable.getIndex(t.getKey()));
            bi.addVals(stable.getIndex(t.getValue()));
          }
          if (!omit_metadata) {
            bi.setInfo(serializeMetadata(i));
          }
          builder.addWays(bi);
        }
        return builder.build();
      }
Example #3
0
      /** Serialize all nodes in the 'dense' format. */
      public Osmformat.PrimitiveGroup serializeDense() {
        if (contents.size() == 0) {
          return null;
        }
        // System.out.format("%d Dense   ",nodes.size());
        Osmformat.PrimitiveGroup.Builder builder = Osmformat.PrimitiveGroup.newBuilder();
        StringTable stable = serializer.getStringTable();

        long lastlat = 0, lastlon = 0, lastid = 0;
        Osmformat.DenseNodes.Builder bi = Osmformat.DenseNodes.newBuilder();
        boolean doesBlockHaveTags = false;
        // Does anything in this block have tags?
        for (Node i : contents) {
          doesBlockHaveTags = doesBlockHaveTags || (i.tagsIterator().hasNext());
        }
        if (!omit_metadata) {
          Osmformat.DenseInfo.Builder bdi = Osmformat.DenseInfo.newBuilder();
          serializeMetadataDense(bdi, contents);
          bi.setDenseinfo(bdi);
        }

        for (Node i : contents) {
          long id = i.getId();
          int lat = mapDegrees(i.getLat());
          int lon = mapDegrees(i.getLon());
          bi.addId(id - lastid);
          lastid = id;
          bi.addLon(lon - lastlon);
          lastlon = lon;
          bi.addLat(lat - lastlat);
          lastlat = lat;

          // Then we must include tag information.
          if (doesBlockHaveTags) {
            Iterator<Element.Tag> tags = i.tagsIterator();
            while (tags.hasNext()) {
              Element.Tag t = tags.next();
              bi.addKeysVals(stable.getIndex(t.getKey()));
              bi.addKeysVals(stable.getIndex(t.getValue()));
            }
            bi.addKeysVals(0); // Add delimiter.
          }
        }
        builder.setDense(bi);
        return builder.build();
      }
Example #4
0
      public Osmformat.PrimitiveGroup serialize() {
        if (contents.size() == 0) {
          return null;
        }

        // System.out.format("%d Relations  ",contents.size());
        StringTable stable = serializer.getStringTable();
        Osmformat.PrimitiveGroup.Builder builder = Osmformat.PrimitiveGroup.newBuilder();
        for (Relation i : contents) {
          Osmformat.Relation.Builder bi = Osmformat.Relation.newBuilder();
          bi.setId(i.getId());
          Member[] arr = new Member[i.getMembers().size()];
          i.getMembers().toArray(arr);
          long lastid = 0;
          for (Member j : i.getMembers()) {
            long id = j.getRef();
            bi.addMemids(id - lastid);
            lastid = id;
            if (j.getType().equals("node")) {
              bi.addTypes(MemberType.NODE);
            } else if (j.getType().equals("way")) {
              bi.addTypes(MemberType.WAY);
            } else if (j.getType().equals("relation")) {
              bi.addTypes(MemberType.RELATION);
            } else {
              assert (false); // Software bug: Unknown entity.
            }
            bi.addRolesSid(stable.getIndex(j.getRole()));
          }

          Iterator<Element.Tag> tags = i.tagsIterator();
          while (tags.hasNext()) {
            Element.Tag t = tags.next();
            bi.addKeys(stable.getIndex(t.getKey()));
            bi.addVals(stable.getIndex(t.getValue()));
          }
          if (!omit_metadata) {
            bi.setInfo(serializeMetadata(i));
          }
          builder.addRelations(bi);
        }
        return builder.build();
      }