Skip to content

Commit

Permalink
modifying handling of OSM metadata
Browse files Browse the repository at this point in the history
gets now checked in ExecutionUtils to further reduce code
  • Loading branch information
FabiKo117 committed Nov 27, 2018
1 parent ac50004 commit c9ab41b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,37 +146,15 @@ public static void executeElements(RequestParameters requestParams, ElementsGeom
ExecutionUtils exeUtils = new ExecutionUtils();
GeoJSONWriter gjw = new GeoJSONWriter();
RemoteTagTranslator mapTagTranslator = DbConnData.mapTagTranslator;
if (includeOSMMetadata) {
preResult = mapRed.map(view -> {
Map<String, Object> properties = new TreeMap<>();
if (isSnapshot) {
properties.put("version", ((OSMEntitySnapshot) view).getEntity().getVersion());
properties.put("osmType", ((OSMEntitySnapshot) view).getEntity().getType());
properties.put("lastEdit",
((OSMEntitySnapshot) view).getEntity().getTimestamp().toString());
properties.put("changesetId", ((OSMEntitySnapshot) view).getEntity().getChangeset());
return exeUtils.createOSMDataFeature(keys, values, mapTagTranslator.get(), keysInt,
valuesInt, view, isSnapshot, properties, gjw, includeTags, elemGeom);
} else {
if (((OSMContribution) view).getContributionTypes().contains(ContributionType.DELETION)) {
return null;
} else {
properties.put("version", ((OSMContribution) view).getEntityAfter().getVersion());
properties.put("osmType", ((OSMContribution) view).getEntityAfter().getType());
properties.put("changesetId", ((OSMContribution) view).getEntityAfter().getChangeset());
return exeUtils.createOSMDataFeature(keys, values, mapTagTranslator.get(), keysInt,
valuesInt, view, isSnapshot, properties, gjw, includeTags, elemGeom);
}
}
});
} else {
preResult = mapRed.map(view -> {
Map<String, Object> properties = new TreeMap<>();
return exeUtils.createOSMDataFeature(keys, values, mapTagTranslator.get(), keysInt,
valuesInt, view, isSnapshot, properties, gjw, includeTags, elemGeom);
});
}

preResult = mapRed.map(view -> {
Map<String, Object> properties = new TreeMap<>();
if (!isSnapshot
&& ((OSMContribution) view).getContributionTypes().contains(ContributionType.DELETION)) {
return null;
}
return exeUtils.createOSMDataFeature(keys, values, mapTagTranslator.get(), keysInt, valuesInt,
view, isSnapshot, properties, gjw, includeTags, includeOSMMetadata, elemGeom);
});
Stream<Feature> streamResult = preResult.stream().filter(feature -> {
if (feature == null)
return false;
Expand Down Expand Up @@ -288,34 +266,27 @@ public static void executeElementsFullHistory(RequestParameters contributionRequ
// if not "creation": take "before" as starting "row" (geom, tags), validFrom = t_start
if (!contributions.get(0).getContributionTypes().contains(ContributionType.CREATION)) {
properties.put("validFrom", startTimestamp);
properties.put("version", contributions.get(0).getEntityBefore().getVersion());
properties.put("osmType", contributions.get(0).getEntityBefore().getType());
properties.put("changesetId", contributions.get(0).getEntityBefore().getChangeset());
} else {
// if creation
properties.put("validFrom", contributions.get(0).getTimestamp().toString());
properties.put("version", contributions.get(0).getEntityAfter().getVersion());
properties.put("osmType", contributions.get(0).getEntityAfter().getType());
properties.put("changesetId", contributions.get(0).getEntityAfter().getChangeset());
if (contributions.size() == 1) {
// use latest timestamp from input parameter for validTo
properties.put("validTo", endTimestamp);
output.add(exeUtils.createOSMDataFeature(keys, values, mapTagTranslator.get(), keysInt,
valuesInt, contributions.get(0), false, properties, gjw, includeTags, elemGeom));
valuesInt, contributions.get(0), false, properties, gjw, includeTags,
includeOSMMetadata, elemGeom));
properties = new TreeMap<>();
return output;
} else {
// use timestamp of contribution 2 for validTo
properties.put("validTo", contributions.get(1).getTimestamp().toString());
output.add(exeUtils.createOSMDataFeature(keys, values, mapTagTranslator.get(), keysInt,
valuesInt, contributions.get(0), false, properties, gjw, includeTags, elemGeom));
valuesInt, contributions.get(0), false, properties, gjw, includeTags,
includeOSMMetadata, elemGeom));
properties = new TreeMap<>();
}
if (!contributions.get(1).getContributionTypes().contains(ContributionType.DELETION)) {
properties.put("validFrom", contributions.get(1).getTimestamp().toString());
properties.put("version", contributions.get(1).getEntityAfter().getVersion());
properties.put("osmType", contributions.get(1).getEntityAfter().getType());
properties.put("changesetId", contributions.get(1).getEntityAfter().getChangeset());
}
// to skip the 2nd contribution in the following loop
startIndex = 2;
Expand All @@ -325,17 +296,15 @@ public static void executeElementsFullHistory(RequestParameters contributionRequ
// set valid_to of previous row, add to output list (output.add(…))
properties.put("validTo", contributions.get(i).getTimestamp().toString());
output.add(exeUtils.createOSMDataFeature(keys, values, mapTagTranslator.get(), keysInt,
valuesInt, contributions.get(i), false, properties, gjw, includeTags, elemGeom));
valuesInt, contributions.get(i), false, properties, gjw, includeTags,
includeOSMMetadata, elemGeom));
properties = new TreeMap<>();
// if deletion: skip output of next row
if (contributions.get(i).getContributionTypes().contains(ContributionType.DELETION)) {
i++;
} else {
// else: take "after" as next row
properties.put("validFrom", contributions.get(i).getTimestamp().toString());
properties.put("version", contributions.get(i).getEntityAfter().getVersion());
properties.put("osmType", contributions.get(i).getEntityAfter().getType());
properties.put("changesetId", contributions.get(i).getEntityAfter().getChangeset());
}
}
// after loop:
Expand All @@ -345,7 +314,7 @@ public static void executeElementsFullHistory(RequestParameters contributionRequ
properties.put("validTo", endTimestamp);
output.add(exeUtils.createOSMDataFeature(keys, values, mapTagTranslator.get(), keysInt,
valuesInt, contributions.get(contributions.size() - 1), false, properties, gjw,
includeTags, elemGeom));
includeTags, includeOSMMetadata, elemGeom));
properties = new TreeMap<>();
}
return output;
Expand All @@ -366,12 +335,8 @@ public static void executeElementsFullHistory(RequestParameters contributionRequ
Map<String, Object> properties = new TreeMap<>();
properties.put("validFrom", startTimestamp);
properties.put("validTo", endTimestamp);
properties.put("version", snapshot.getEntity().getVersion());
properties.put("osmType", snapshot.getEntity().getType());
properties.put("lastEdit", snapshot.getEntity().getTimestamp().toString());
properties.put("changesetId", snapshot.getEntity().getChangeset());
return exeUtils.createOSMDataFeature(keys, values, mapTagTranslator.get(), keysInt, valuesInt,
snapshot, true, properties, gjw, includeTags, elemGeom);
snapshot, true, properties, gjw, includeTags, includeOSMMetadata, elemGeom);
}); // valid_from = t_start, valid_to = t_end

Stream<Feature> contributionStream = contributionPreResult.stream().filter(feature -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,21 @@ public Geometry getGeometry(BoundaryType boundary, GeometryBuilder geomBuilder)
public org.wololo.geojson.Feature createOSMDataFeature(String[] keys, String[] values,
TagTranslator tt, int[] keysInt, int[] valuesInt, OSHDBMapReducible mapReducible,
boolean isSnapshot, Map<String, Object> properties, GeoJSONWriter gjw, boolean includeTags,
ElementsGeometry elemGeom) {
boolean includeOSMMetadata, ElementsGeometry elemGeom) {
if (isSnapshot) {
properties.put("snapshotTimestamp",
((OSMEntitySnapshot) mapReducible).getTimestamp().toString());
properties.put("osmId",
((OSMEntitySnapshot) mapReducible).getEntity().getType().toString().toLowerCase() + "/"
+ ((OSMEntitySnapshot) mapReducible).getEntity().getId());
if (includeOSMMetadata) {
properties.put("version", ((OSMEntitySnapshot) mapReducible).getEntity().getVersion());
properties.put("osmType", ((OSMEntitySnapshot) mapReducible).getEntity().getType());
properties.put("lastEdit",
((OSMEntitySnapshot) mapReducible).getEntity().getTimestamp().toString());
properties.put("changesetId",
((OSMEntitySnapshot) mapReducible).getEntity().getChangeset());
}
if (includeTags) {
for (OSHDBTag oshdbTag : ((OSMEntitySnapshot) mapReducible).getEntity().getTags()) {
OSMTag tag = tt.getOSMTagOf(oshdbTag.getKey(), oshdbTag.getValue());
Expand Down Expand Up @@ -247,6 +255,12 @@ public org.wololo.geojson.Feature createOSMDataFeature(String[] keys, String[] v
properties.put("osmId",
((OSMContribution) mapReducible).getEntityAfter().getType().toString().toLowerCase() + "/"
+ ((OSMContribution) mapReducible).getEntityAfter().getId());
if (includeOSMMetadata) {
properties.put("version", ((OSMContribution) mapReducible).getEntityAfter().getVersion());
properties.put("osmType", ((OSMContribution) mapReducible).getEntityAfter().getType());
properties.put("changesetId",
((OSMContribution) mapReducible).getEntityAfter().getChangeset());
}
if (includeTags) {
for (OSHDBTag oshdbTag : ((OSMContribution) mapReducible).getEntityAfter().getTags()) {
OSMTag tag = tt.getOSMTagOf(oshdbTag.getKey(), oshdbTag.getValue());
Expand Down

0 comments on commit c9ab41b

Please sign in to comment.