Ejemplo n.º 1
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();
      }
Ejemplo n.º 2
0
 @Override
 protected void parseWays(List<Osmformat.Way> osmWays) {
   if (exception == null) {
     try {
       for (Osmformat.Way w : osmWays) {
         final Info info = w.getInfo();
         if (!info.hasVersion()) discourageUpload = true;
         final Way way = new Way(w.getId(), info.hasVersion() ? info.getVersion() : 1);
         setMetadata(way, info);
         Map<String, String> keys = new HashMap<>();
         for (int i = 0; i < w.getKeysCount(); i++) {
           keys.put(getStringById(w.getKeys(i)), getStringById(w.getVals(i)));
         }
         way.setKeys(keys);
         long previousId = 0; // Node ids are delta coded
         Collection<Long> nodeIds = new ArrayList<>();
         for (Long id : w.getRefsList()) {
           nodeIds.add(previousId += id);
         }
         ways.put(way.getUniqueId(), nodeIds);
         externalIdMap.put(way.getPrimitiveId(), way);
       }
     } catch (IllegalDataException e) {
       exception = e;
     }
   }
 }
Ejemplo n.º 3
0
  private void sendWaysToTranslator(List<Way> ways) {

    for (Osmformat.Way i : ways) {
      List<Tag> listeTags = new ArrayList<Tag>();
      for (int j = 0; j < i.getKeysCount(); j++) {
        Tag tag = new Tag();
        tag.setKey(getStringById(i.getKeys(j)));
        tag.setValue(getStringById(i.getVals(j)));
        listeTags.add(tag);
      }

      long lastId = 0;
      List<Nd> listeLocalisationsRef = new ArrayList<Nd>();
      for (long j : i.getRefsList()) {
        Nd nd = new Nd();
        nd.setRef(j + lastId);
        listeLocalisationsRef.add(nd);
        lastId = j + lastId;
      }

      com.osm2xp.model.osm.Way way = new com.osm2xp.model.osm.Way();
      way.getTag().addAll(listeTags);
      way.setId(i.getId());
      way.getNd().addAll(listeLocalisationsRef);

      // if roof color information is available, add it to the current way
      if (this.roofsColorMap != null && this.roofsColorMap.get(way.getId()) != null) {
        String hexColor =
            Integer.toHexString(this.roofsColorMap.get(way.getId()).getRGB() & 0x00ffffff);
        Tag roofColorTag = new Tag("building:roof:color", hexColor);
        way.getTag().add(roofColorTag);
      }

      try {
        List<Long> ids = new ArrayList<Long>();
        for (Nd nd : way.getNd()) {
          ids.add(nd.getRef());
        }
        List<com.osm2xp.model.osm.Node> nodes = processor.getNodes(ids);

        if (nodes != null) {
          OsmPolygon polygon = new OsmPolygon(way.getId(), way.getTag(), nodes);
          translator.processPolygon(polygon);
        }

      } catch (Osm2xpBusinessException e) {
        Osm2xpLogger.error("Error processing way.", e);
      } catch (DataSinkException e) {
        Osm2xpLogger.error("Error processing way.", e);
      }
    }
  }
Ejemplo n.º 4
0
  private void checkWaysForUsefullNodes(List<Way> ways) {
    for (Osmformat.Way i : ways) {
      List<Tag> listeTags = new ArrayList<Tag>();
      for (int j = 0; j < i.getKeysCount(); j++) {
        Tag tag = new Tag();
        tag.setKey(getStringById(i.getKeys(j)));
        tag.setValue(getStringById(i.getVals(j)));
        listeTags.add(tag);
      }

      long lastId = 0;
      List<Nd> listeLocalisationsRef = new ArrayList<Nd>();
      for (long j : i.getRefsList()) {
        Nd nd = new Nd();
        nd.setRef(j + lastId);
        listeLocalisationsRef.add(nd);
        lastId = j + lastId;
      }

      com.osm2xp.model.osm.Way way = new com.osm2xp.model.osm.Way();
      way.getTag().addAll(listeTags);
      way.setId(i.getId());
      way.getNd().addAll(listeLocalisationsRef);

      try {
        List<Long> ids = new ArrayList<Long>();
        for (Nd nd : way.getNd()) {
          ids.add(nd.getRef());
        }
        if (translator.mustStoreWay(way)) {
          for (Nd nd : way.getNd()) {
            com.osm2xp.model.osm.Node node = new com.osm2xp.model.osm.Node();
            node.setId(nd.getRef());
            node.setLat(0);
            node.setLon(0);
            processor.storeNode(node);
          }
        }

      } catch (DataSinkException e) {
        Osm2xpLogger.error("Error processing way.", e);
      }
    }
  }