Ejemplo n.º 1
0
 private TagGroup tagGroupForEntity(Entity entity) {
   if (entity.getTags().isEmpty()) {
     return EMPTY_TAG_GROUP;
   } else {
     Map<String, String> tagMap = new HashMap<String, String>(entity.getTags().size());
     for (Tag tag : entity.getTags()) {
       tagMap.put(tag.getKey(), tag.getValue());
     }
     return new MapBasedTagGroup(tagMap);
   }
 }
Ejemplo n.º 2
0
 public void process(EntityContainer entityContainer) {
   Entity entity = entityContainer.getEntity();
   if (entity instanceof Node) {
     nodesById.put(entity.getId(), ((Node) entity));
   } else if (entity instanceof Way) {
     waysById.put(entity.getId(), ((Way) entity));
   } else if (entity instanceof Relation) {
     relationsById.put(entity.getId(), ((Relation) entity));
   } else if (entity instanceof Bound) {
     bounds.add((Bound) entity);
   }
 }
Ejemplo n.º 3
0
 /**
  * Extracts known way tags and returns their ids.
  *
  * @param entity the way
  * @return the ids of the identified tags
  */
 public static short[] extractKnownWayTags(Entity entity) {
   TShortArrayList currentTags = new TShortArrayList();
   OSMTagMapping mapping = OSMTagMapping.getInstance();
   if (entity.getTags() != null) {
     for (Tag tag : entity.getTags()) {
       OSMTag wayTag = mapping.getWayTag(tag.getKey(), tag.getValue());
       if (wayTag != null) {
         currentTags.add(wayTag.getId());
       }
     }
   }
   return currentTags.toArray();
 }
Ejemplo n.º 4
0
  private void processFacilities(
      ActivityFacilitiesFactory aff, Map<Long, ? extends EntityContainer> nodeMap) {

    for (Long n : nodeMap.keySet()) {

      Entity entity = nodeMap.get(n).getEntity();
      Map<String, String> tags = new TagCollectionImpl(entity.getTags()).buildMap();

      for (String s : this.keys) {

        String tourism = tags.get(s);
        String matsimType = null;
        if (tourism != null) {
          matsimType = getActivityType(tourism);
        }
        if (matsimType != null) {

          String name = tags.get("name");

          if (name != null) {

            name.replace("ä", "ae");
            name.replace("ö", "oe");
            name.replace("ü", "ue");
          }
          Coord coord =
              OsmCoordUtils.getCoord(entity, this.ct, this.nodeMap, this.wayMap, this.relationMap);
          Id<ActivityFacility> id = Id.create(entity.getId(), ActivityFacility.class);
          ActivityFacility af;
          if (!this.facilities.getFacilities().containsKey(id)) {
            af = aff.createActivityFacility(id, coord);
            //					((ActivityFacilityImpl)af).setDesc(name);
            this.facilities.addActivityFacility(af);
          } else {
            af = (ActivityFacilityImpl) this.facilities.getFacilities().get(id);
          }

          ActivityOption ao = aff.createActivityOption(matsimType);
          af.addActivityOption(ao);
        }
      }
    }
  }
Ejemplo n.º 5
0
  /**
   * Extracts special fields and returns their values as an array of strings.
   *
   * @param entity the entity
   * @param preferredLanguage the preferred language
   * @return a string array, [0] = name, [1] = ref, [2} = housenumber, [3] layer, [4] elevation, [5]
   *     relationType
   */
  public static SpecialTagExtractionResult extractSpecialFields(
      Entity entity, String preferredLanguage) {
    boolean foundPreferredLanguageName = false;
    String name = null;
    String ref = null;
    String housenumber = null;
    byte layer = 5;
    short elevation = 0;
    String relationType = null;

    if (entity.getTags() != null) {
      for (Tag tag : entity.getTags()) {
        String key = tag.getKey().toLowerCase(Locale.ENGLISH);
        if ("name".equals(key) && !foundPreferredLanguageName) {
          name = tag.getValue();
        } else if ("piste:name".equals(key) && name == null) {
          name = tag.getValue();
        } else if ("addr:housenumber".equals(key)) {
          housenumber = tag.getValue();
        } else if ("ref".equals(key)) {
          ref = tag.getValue();
        } else if ("layer".equals(key)) {
          String l = tag.getValue();
          try {
            byte testLayer = Byte.parseByte(l);
            if (testLayer >= -5 && testLayer <= 5) {
              testLayer += 5;
            }
            layer = testLayer;
          } catch (NumberFormatException e) {
            LOGGER.finest(
                "could not parse layer information to byte type: "
                    + tag.getValue()
                    + "\t entity-id: "
                    + entity.getId()
                    + "\tentity-type: "
                    + entity.getType().name());
          }
        } else if ("ele".equals(key)) {
          String strElevation = tag.getValue();
          strElevation = strElevation.replaceAll("m", "");
          strElevation = strElevation.replaceAll(",", ".");
          try {
            double testElevation = Double.parseDouble(strElevation);
            if (testElevation < MAX_ELEVATION) {
              elevation = (short) testElevation;
            }
          } catch (NumberFormatException e) {
            LOGGER.finest(
                "could not parse elevation information to double type: "
                    + tag.getValue()
                    + "\t entity-id: "
                    + entity.getId()
                    + "\tentity-type: "
                    + entity.getType().name());
          }
        } else if ("type".equals(key)) {
          relationType = tag.getValue();
        } else if (preferredLanguage != null && !foundPreferredLanguageName) {
          Matcher matcher = NAME_LANGUAGE_PATTERN.matcher(key);
          if (matcher.matches()) {
            String language = matcher.group(3);
            if (language.equalsIgnoreCase(preferredLanguage)) {
              name = tag.getValue();
              foundPreferredLanguageName = true;
            }
          }
        }
      }
    }

    return new SpecialTagExtractionResult(name, ref, housenumber, layer, elevation, relationType);
  }