Commit c9efc4c0 authored by Johannes Visintini's avatar Johannes Visintini
Browse files

Merge branch 'fix-sonarlint-issues' into 'oshdb-snapshot'

fix some sonarlint issues and typos

See merge request !21
parents a0765a60 4d80fdb2
Pipeline #2516 created
......@@ -19,7 +19,7 @@ You can check out this repository and run the example classes – to see immedia
## Tutorial
The [tutorial](https://gitlab.gistools.geog.uni-heidelberg.de/giscience/big-data/ohsome/oshdb-examples/tree/master/src/main/java/org/heigit/ohsome/oshdb/tutorial) is a quick and simple dive into the OSHDB-API-Code.
The [tutorial](/src/main/java/org/heigit/ohsome/oshdb/tutorial) is a quick and simple dive into the OSHDB-API Code.
## Analyses
......
......@@ -6,27 +6,34 @@ import org.heigit.ohsome.oshdb.OSHDBBoundingBox;
import org.heigit.ohsome.oshdb.OSHDBTimestamp;
import org.heigit.ohsome.oshdb.api.db.OSHDBH2;
import org.heigit.ohsome.oshdb.api.mapreducer.OSMContributionView;
import org.heigit.ohsome.oshdb.util.mappable.OSMContribution;
import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps.Interval;
import org.heigit.ohsome.oshdb.util.time.TimestampFormatter;
@SuppressWarnings("java:S106")
public class DistinctContributors {
public static void main(String[] args) throws Exception {
// database
OSHDBH2 oshdb = new OSHDBH2(
DistinctContributors.class.getResource("/test.oshdb.mv.db").getFile())
.multithreading(true);
//keytables
OSHDBH2 oshdbKeytables = new OSHDBH2(
DistinctContributors.class.getResource("/test.oshdb.keytables.mv.db").getFile());
// query
SortedMap<OSHDBTimestamp, Integer> result = OSMContributionView.on(oshdb)
.keytables(oshdbKeytables)
.areaOfInterest(new OSHDBBoundingBox(71.45, -1.16, 74.7, 7.47)) // maldives
.timestamps("2007-01-01", "2017-12-01", Interval.MONTHLY)
.filter("type:way and highway=*")
.map(k -> k.getContributorUserId())
.aggregateByTimestamp()
.countUniq();
SortedMap<OSHDBTimestamp, Integer> result;
try (
// database
OSHDBH2 oshdb = new OSHDBH2(
DistinctContributors.class.getResource("/test.oshdb.mv.db").getFile())
.multithreading(true);
// keytables
OSHDBH2 oshdbKeytables = new OSHDBH2(
DistinctContributors.class.getResource("/test.oshdb.keytables.mv.db").getFile())) {
// query
result = OSMContributionView.on(oshdb)
.keytables(oshdbKeytables)
.areaOfInterest(
OSHDBBoundingBox.bboxWgs84Coordinates(71.45, -1.16, 74.7, 7.47)) // maldives
.timestamps("2007-01-01", "2017-12-01", Interval.MONTHLY)
.filter("type:way and highway=*")
.map(OSMContribution::getContributorUserId)
.aggregateByTimestamp()
.countUniq();
}
// output
for (Map.Entry<OSHDBTimestamp, Integer> entry : result.entrySet()) {
System.out.format("%s\t%.2f%n",
......
......@@ -11,7 +11,9 @@ import org.heigit.ohsome.oshdb.util.geometry.Geo;
import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps.Interval;
import org.heigit.ohsome.oshdb.util.time.TimestampFormatter;
@SuppressWarnings("java:S106")
public class RoadLength {
static final List<String> other = List.of("unclassified", "road", "service", "track", "path",
"pedestrian", "footway", "cycleway", "steps", "platform", "bridleway");
static final List<String> highway_motorway = List.of(
......@@ -21,22 +23,27 @@ public class RoadLength {
static final List<String> residential = List.of("residential", "living_street");
public static void main(String[] args) throws Exception {
// database
OSHDBH2 oshdb = new OSHDBH2(RoadLength.class.getResource("/test.oshdb.mv.db")
.getFile()
.replace(".mv.db", ""))
.multithreading(true);
OSHDBH2 oshdbKeytables = new OSHDBH2(RoadLength.class.getResource("/test.oshdb.keytables.mv.db")
.getFile()
.replace(".mv.db", ""));
// query
SortedMap<OSHDBTimestamp, Number> result = OSMEntitySnapshotView.on(oshdb)
.keytables(oshdbKeytables)
.areaOfInterest(new OSHDBBoundingBox(71.45, -1.16, 74.7, 7.47)) // maldives
.timestamps("2007-01-01", "2017-12-01", Interval.MONTHLY)
.filter("type:way and highway in (" + String.join(",", highway_motorway) + ")")
.aggregateByTimestamp()
.sum(snapshot -> Geo.lengthOf(snapshot.getGeometry()) / 1000);
SortedMap<OSHDBTimestamp, Number> result;
try (
// database
OSHDBH2 oshdb = new OSHDBH2(RoadLength.class.getResource("/test.oshdb.mv.db")
.getFile()
.replace(".mv.db", ""))
.multithreading(true);
OSHDBH2 oshdbKeytables = new OSHDBH2(
RoadLength.class.getResource("/test.oshdb.keytables.mv.db")
.getFile()
.replace(".mv.db", ""))) {
// query
result = OSMEntitySnapshotView.on(oshdb)
.keytables(oshdbKeytables)
.areaOfInterest(
OSHDBBoundingBox.bboxWgs84Coordinates(71.45, -1.16, 74.7, 7.47)) // maldives
.timestamps("2007-01-01", "2017-12-01", Interval.MONTHLY)
.filter("type:way and highway in (" + String.join(",", highway_motorway) + ")")
.aggregateByTimestamp()
.sum(snapshot -> Geo.lengthOf(snapshot.getGeometry()) / 1000);
}
// output
for (Map.Entry<OSHDBTimestamp, Number> entry : result.entrySet()) {
System.out.format("%s\t%.2f%n",
......
package org.heigit.ohsome.oshdb.tutorial;
import java.util.Arrays;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import java.util.SortedMap;
import org.heigit.ohsome.oshdb.OSHDBTimestamp;
......@@ -17,23 +17,26 @@ import org.heigit.ohsome.oshdb.util.mappable.OSMContribution;
import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps;
import org.jfree.ui.RefineryUtilities;
public class AdvandcedExample {
public class AdvancedExample {
public static void main(String[] args) throws Exception {
//Declare Database
OSHDBDatabase oshdb = new OSHDBH2(AdvandcedExample.class.getResource("/test.oshdb.mv.db")
.getFile()
.replace(".mv.db", ""));
OSHDBJdbc keytables = new OSHDBH2(Tutorial.class.getResource("/test.oshdb.keytables.mv.db")
SortedMap<OSHDBTimestamp, Map<ContributionType, Integer>> reduce;
try (OSHDBDatabase oshdb = new OSHDBH2(AdvancedExample.class.getResource("/test.oshdb.mv.db")
.getFile()
.replace(".mv.db", ""));
//Define MapReducer
SortedMap<OSHDBTimestamp, Map<ContributionType, Integer>> reduce = OSMContributionView.on(oshdb)
.keytables(keytables)
.timestamps("2014-01-01", "2015-01-01", OSHDBTimestamps.Interval.MONTHLY)
.filter("geometry:polygon and building=*")
.map(new Mapper())
.aggregateByTimestamp()
.reduce(new IdentitySupplier(), new Combiner());
OSHDBJdbc keytables = new OSHDBH2(Tutorial.class.getResource("/test.oshdb.keytables.mv.db")
.getFile()
.replace(".mv.db", ""))) {
//Define MapReducer
reduce = OSMContributionView.on(oshdb)
.keytables(keytables)
.timestamps("2014-01-01", "2015-01-01", OSHDBTimestamps.Interval.MONTHLY)
.filter("geometry:polygon and building=*")
.map(new Mapper())
.aggregateByTimestamp()
.reduce(new IdentitySupplier(), new Combiner());
}
//Display Result
TutorialChart chart = new TutorialChart("BigDB Analyses",
"Contribution-Types per timestamp!", reduce);
......@@ -44,6 +47,7 @@ public class AdvandcedExample {
private static class Mapper implements
SerializableFunction<OSMContribution, Map<ContributionType, Integer>> {
@Override
public Map<ContributionType, Integer> apply(OSMContribution contribution) {
//get an empty result-map
......@@ -57,22 +61,21 @@ public class AdvandcedExample {
private static class IdentitySupplier implements
SerializableSupplier<Map<ContributionType, Integer>> {
@Override
public Map<ContributionType, Integer> get() {
//create an empty result-map
Map<ContributionType, Integer> result = new HashMap<>();
Map<ContributionType, Integer> result = new EnumMap<>(ContributionType.class);
//fill with 0 values
Arrays.asList(ContributionType.values())
.forEach(
(ContributionType type) ->
result.put(type, 0)
);
.forEach(type -> result.put(type, 0));
return result;
}
}
private static class Combiner implements
SerializableBinaryOperator<Map<ContributionType, Integer>> {
@Override
public Map<ContributionType, Integer> apply(
Map<ContributionType, Integer> mapResultA,
......
# Tutorial
The basic tutorial is a realisation of the [OSHDB-API-Tutorial](https://github.com/GIScience/oshdb/blob/master/documentation/oshdb-api-tutorial/README.md). An alternative coding style can be found there. The code here tries to transparently demonstrate the intermediate steps of the process and transfers processing code to seperate classes that can easyly be extended.
The basic tutorial is a realisation of the [OSHDB First Steps Tutorial](https://github.com/GIScience/oshdb/blob/master/documentation/first-steps/README.md). An alternative coding style can be found there. The code here tries to transparently demonstrate the intermediate steps of the process and transfers processing code to separate classes that can easily be extended.
The advandced tutorial shows a more complex analysis.
The [advanced tutorial](/src/main/java/org/heigit/ohsome/oshdb/tutorial/AdvancedExample.java) shows a more complex analysis.
......@@ -12,7 +12,9 @@ import org.heigit.ohsome.oshdb.util.geometry.Geo;
import org.heigit.ohsome.oshdb.util.mappable.OSMEntitySnapshot;
import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps.Interval;
@SuppressWarnings("java:S106")
public class Tutorial {
public static void main(String[] args) throws Exception {
// -- PREPARATION --
// Start writing the OSHDB query
......@@ -39,7 +41,8 @@ public class Tutorial {
// Setting spatial extent
// create BoundingBox
OSHDBBoundingBox boundingBox = new OSHDBBoundingBox(71.45, -1.16, 74.7, 7.47); //Maldives
OSHDBBoundingBox boundingBox = OSHDBBoundingBox
.bboxWgs84Coordinates(71.45, -1.16, 74.7, 7.47); //Maldives
// add hte boundingBox to the MapReducer
mapReducer = mapReducer.areaOfInterest(boundingBox);
......@@ -51,13 +54,13 @@ public class Tutorial {
mapReducer = mapReducer.filter("type:way and building=*");
// -- Calculating intermediate results --
// mapping snapshots to area-values using a seperate class
// mapping snapshots to area-values using a separate class
MapReducer<Double> mapReducer2 = mapReducer.map(new Mapper());
// -- Filtering intermediate results --
mapReducer2 = mapReducer2.filter(new ResultFilter());
// -- Reqeusting aggregated result --
// -- Requesting aggregated result --
// sum
Number result = mapReducer2.sum();
......@@ -70,6 +73,7 @@ public class Tutorial {
}
private static class Mapper implements SerializableFunction<OSMEntitySnapshot, Double> {
@Override
public Double apply(OSMEntitySnapshot snapshot) {
return Geo.areaOf(snapshot.getGeometry());
......@@ -77,6 +81,7 @@ public class Tutorial {
}
private static class ResultFilter implements SerializablePredicate<Double> {
@Override
public boolean test(Double area) {
return area < 1000.0;
......
......@@ -15,6 +15,7 @@ import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
public class TutorialChart extends ApplicationFrame {
private SortedMap<OSHDBTimestamp, Map<ContributionType, Integer>> dataset;
public TutorialChart(
......@@ -43,10 +44,9 @@ public class TutorialChart extends ApplicationFrame {
.iterator();
while (it.hasNext()) {
Map.Entry<OSHDBTimestamp, Map<ContributionType, Integer>> ff = it.next();
Arrays.asList(ContributionType.values()).forEach((ContributionType contribType) -> {
a.addValue(ff.getValue().get(contribType), contribType, ff
.getKey());
});
Arrays.asList(ContributionType.values()).forEach((ContributionType contribType) -> a
.addValue(ff.getValue().get(contribType), contribType, ff
.getKey()));
}
return a;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment