コード例 #1
0
ファイル: OsmosisReader.java プロジェクト: tordanik/OSM2World
 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);
   }
 }
コード例 #2
0
ファイル: OSMUtils.java プロジェクト: tomik4/mapsforge
 /**
  * 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();
 }
コード例 #3
0
ファイル: WayKeyFilter.java プロジェクト: junwuwei/osmosis
  /** {@inheritDoc} */
  public void process(WayContainer container) {
    Way way = container.getEntity();

    boolean matchesFilter = false;
    for (Tag tag : way.getTags()) {
      if (allowedKeys.contains(tag.getKey())) {
        matchesFilter = true;
        break;
      }
    }

    if (matchesFilter) {
      sink.process(container);
    }
  }
コード例 #4
0
ファイル: TagFilter.java プロジェクト: junwuwei/osmosis
 /**
  * Checks whether the Entity in a container has tags that match this filter.
  *
  * @param container The container holding the entity whose tags shall be examined.
  */
 private boolean matches(EntityContainer container) {
   boolean matched = false;
   for (Tag tag : container.getEntity().getTags()) {
     String key = tag.getKey();
     if (tagKeys.contains(key)) {
       matched = true;
       break;
     }
     Set<String> values = tagKeyValues.get(key);
     if ((values != null) && values.contains(tag.getValue())) {
       matched = true;
       break;
     }
   }
   return matched;
 }
コード例 #5
0
ファイル: OSMUtils.java プロジェクト: tomik4/mapsforge
 /**
  * Heuristic to determine from attributes if a way is likely to be an area. Precondition for this
  * call is that the first and last node of a way are the same, so that this method should only
  * return false if it is known that the feature should not be an area even if the geometry is a
  * polygon.
  *
  * <p>Determining what is an area is neigh impossible in OSM, this method inspects tag elements to
  * give a likely answer. See http://wiki.openstreetmap.org/wiki/The_Future_of_Areas and
  * http://wiki.openstreetmap.org/wiki/Way
  *
  * @param way the way (which is assumed to be closed and have enough nodes to be an area)
  * @return true if tags indicate this is an area, otherwise false.
  */
 public static boolean isArea(Way way) {
   boolean result = true;
   if (way.getTags() != null) {
     for (Tag tag : way.getTags()) {
       String key = tag.getKey().toLowerCase(Locale.ENGLISH);
       String value = tag.getValue().toLowerCase(Locale.ENGLISH);
       if ("area".equals(key)) {
         // obvious result
         if (("yes").equals(value) || ("y").equals(value) || ("true").equals(value)) {
           return true;
         }
         if (("no").equals(value) || ("n").equals(value) || ("false").equals(value)) {
           return false;
         }
       }
       if ("highway".equals(key) || "barrier".equals(key)) {
         // false unless something else overrides this.
         result = false;
       }
       if ("railway".equals(key)) {
         // there is more to the railway tag then just rails, this excludes the
         // most common railway lines from being detected as areas if they are closed.
         // Since this method is only called if the first and last node are the same
         // this should be safe
         if ("rail".equals(value)
             || "tram".equals(value)
             || "subway".equals(value)
             || "monorail".equals(value)
             || "narrow_gauge".equals(value)
             || "preserved".equals(value)
             || "light_rail".equals(value)
             || "construction".equals(value)) {
           result = false;
         }
       }
     }
   }
   return result;
 }
コード例 #6
0
ファイル: OSMUtils.java プロジェクト: tomik4/mapsforge
  /**
   * 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);
  }