@Override public Optional<String> getTag(final String key) { return Optional.ofNullable(getTags().get(key)); }
/** * Utility function to test if an entity's tags match some given tag keys. * * @param matches * The given tag keys to match * @return True if at least one tag of the entity matches one of the given keys */ public boolean containsKey(final Iterable<String> matches) { final Map<String, String> tags = this.getTags(); for (final String candidate : matches) { if (tags.containsKey(candidate)) { return true; } } return false; }
@Override public Map<String, String> getTags() { return getSource().getTags(); }
/** * Utility function to test if an entity's tags start with some given tag keys. * * @param matches * The given tag keys to match * @return True if at least one tag of the entity starts with one of the given keys */ public boolean containsKeyStartsWith(final Iterable<String> matches) { final Map<String, String> tags = this.getTags(); for (final String candidate : matches) { for (final String key : tags.keySet()) { if (key.startsWith(candidate)) { return true; } } } return false; }
protected String tagString() { final StringBuilder builder = new StringBuilder(); final Map<String, String> tags = getTags(); int index = 0; builder.append("[Tags: "); for (final String key : tags.keySet()) { final String value = tags.get(key); builder.append("["); builder.append(key); builder.append(" => "); builder.append(value); builder.append("]"); if (index < tags.size() - 1) { builder.append(", "); } index++; } builder.append("]"); return builder.toString(); }
/** * @return The building's top height */ public Optional<Distance> topHeight() { Map<String, String> tags = getSource().getTags(); String heightTag = tags.get("height"); try { if (heightTag != null) { return Optional.of(HEIGHT_CONVERTER.convert(heightTag)); } tags = this.outlineSource.getTags(); heightTag = tags.get("height"); if (heightTag != null) { return Optional.of(HEIGHT_CONVERTER.convert(heightTag)); } } catch (final Exception e) { logger.warn("Invalid height {} for building id {}", heightTag, getSource().getIdentifier()); } return Optional.empty(); }
/** * @return The building part's top height */ public Optional<Distance> topHeight() { final Map<String, String> tags = getSource().getTags(); final String heightTag = tags.get("height"); try { if (heightTag != null) { return Optional.of(HEIGHT_CONVERTER.convert(heightTag)); } } catch (final Exception e) { logger.warn("Invalid height {} for building part id {}", heightTag, getSource().getIdentifier()); } return Optional.empty(); }
/** * A method that creates properties for a GeoJSON Feature from the tags. * * @return A GeoJSON properties object that is to be put in a Feature. */ public JsonObject geoJsonProperties() { final JsonObject properties = new JsonObject(); getTags().forEach(properties::addProperty); properties.addProperty(GeoJsonUtils.IDENTIFIER, getIdentifier()); properties.addProperty(GeoJsonUtils.OSM_IDENTIFIER, getOsmIdentifier()); properties.addProperty(GeoJsonUtils.ITEM_TYPE, String.valueOf(getType())); final Optional<String> shardName = getAtlas().metaData().getShardName(); shardName.ifPresent(shard -> properties.addProperty("shard", shard)); final Set<Relation> relations = relations(); if (relations.size() > 0) { final JsonArray relationsArray = new JsonArray(); properties.add("relations", relationsArray); for (final Relation relation : relations) { final JsonObject relationObject = relation.geoJsonProperties(); relationsArray.add(relationObject); } } return properties; }
protected String formatAtlasObject(final String type, final Atlas atlas, final AtlasEntity entity) { final String shardName = atlas.metaData().getShardName().orElse("UNKNOWN"); return String.format("[%10s] [%d] [%d] --> [%s:%s] Tags: [%s]\n", type, entity.getOsmIdentifier(), entity.getIdentifier(), shardName, atlas.getName(), entity.getTags()); }
properties.addProperty("class", source.getClass().getName()); properties.addProperty("identifier", source.getIdentifier()); add(properties, "tags", source.getTags(), tagPrinter); add(properties, "relations", source.relations(), identifierMapper);
private static void processDiffEntity(final Diff diff, final AtlasEntity entity, final List<LocationIterableProperties> items, final String diffStage) { // Depending on if it is a before or after for a given diff type, an entity may be null. if (entity != null) { final Map<String, String> tags = entity.getTags(); tags.put("diff", diffStage); tags.put("diff:type", diff.getDiffType().name()); tags.put("diff:reason", diff.getDiffReason().name()); if (diff.getItemType() == ItemType.RELATION) { items.addAll(processRelationForGeoJson((Relation) entity, tags)); } else { items.add(new LocationIterableProperties(((AtlasItem) entity).getRawGeometry(), tags)); } } }
protected void validateTagsPresent() { for (final AtlasEntity entity : this.atlas.entities()) { final Map<String, String> tags = entity.getTags(); if (tags == null) { throw new CoreException("Entity {} {} is missing tags.", entity.getType(), entity.getIdentifier()); } } } }
/** * Creates an informative {@link String} for an {@link AtlasEntity} and the {@link Atlas} that * contains it. * * @param entity * {@link AtlasEntity} to create the string for * @return formatted string */ private String formatAtlasObject(final AtlasEntity entity) { final String shardName = entity.getAtlas().metaData().getShardName().orElse("UNKNOWN"); return String.format("[%s] [%d] [%d] --> [%s:%s] Tags: [%s]\n", entity.getType(), entity.getOsmIdentifier(), entity.getIdentifier(), shardName, entity.getAtlas().getName(), entity.getTags()); } }
if (beforeEntity.getTags().equals(afterEntity.getTags())) .withTags(afterEntity.getTags()); if (saveAllGeometries) case EDGE: CompleteEdge edge = CompleteEdge.shallowFrom((Edge) afterEntity) .withTags(afterEntity.getTags()); if (saveAllGeometries) case LINE: CompleteLine line = CompleteLine.shallowFrom((Line) afterEntity) .withTags(afterEntity.getTags()); if (saveAllGeometries) case NODE: CompleteNode node = CompleteNode.shallowFrom((Node) afterEntity) .withTags(afterEntity.getTags()); if (saveAllGeometries) case POINT: CompletePoint point = CompletePoint.shallowFrom((Point) afterEntity) .withTags(afterEntity.getTags()); if (saveAllGeometries) case RELATION: final CompleteRelation relation = CompleteRelation .shallowFrom((Relation) afterEntity).withTags(afterEntity.getTags()); bloatedEntity = relation;
public static void saveAsGeojson(final Iterable<ComplexBoundary> complexBoundaries, final WritableResource output) { try (JsonWriter writer = new JsonWriter(output)) { final Iterable<LocationIterableProperties> geojsonObjects = Iterables .stream(complexBoundaries).flatMap(boundary -> { final Map<String, String> tags = boundary.getSource().getTags(); return Iterables .stream(boundary.getOutline().asLocationIterableProperties()) .map(locationIterableProperties -> { locationIterableProperties.getProperties().putAll(tags); return locationIterableProperties; }); }); writer.write(new GeoJsonBuilder().create(geojsonObjects).jsonObject()); } }
@Test public void testMergeTags() { final FeatureChange featureChange1 = new FeatureChange(ChangeType.ADD, new CompleteArea(123L, null, Maps.hashMap("key1", "value1"), null)); final FeatureChange featureChange2 = new FeatureChange(ChangeType.ADD, new CompleteArea(123L, null, Maps.hashMap("key2", "value2"), null)); Assert.assertEquals(Maps.hashMap("key1", "value1", "key2", "value2"), featureChange1.merge(featureChange2).getReference().getTags()); }