Unverified Commit 86b7a703 authored by Martin Raifer's avatar Martin Raifer
Browse files

update to OSHDB PR 369 + minor code style fixes

https://github.com/GIScience/oshdb/pull/369
parent e9520f09
Pipeline #1707 passed with stage
in 0 seconds
......@@ -2,11 +2,10 @@ package org.heigit.ohsome.oshdb.examples.analyses;
import java.util.Map;
import java.util.SortedMap;
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.osm.OSMType;
import org.heigit.ohsome.oshdb.util.OSHDBBoundingBox;
import org.heigit.ohsome.oshdb.util.OSHDBTimestamp;
import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps.Interval;
import org.heigit.ohsome.oshdb.util.time.TimestampFormatter;
......@@ -14,26 +13,20 @@ public class DistinctContributors {
public static void main(String[] args) throws Exception {
// database
OSHDBH2 oshdb = new OSHDBH2(DistinctContributors.class.getResource("/test.oshdb.mv.db")
.getFile()
.replace(".mv.db", ""))
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()
.replace(".mv.db", "")
);
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(k->k.is(ContributionType.CREATION) || k.is(ContributionType.DELETION )|| k.is(ContributionType.GEOMETRY_CHANGE)||k.is(ContributionType.TAG_CHANGE)||k.is(ContributionType.valueOf("")))
.osmType(OSMType.WAY)
.osmTag("highway")
.filter("type:way and highway=*")
.map(k -> k.getContributorUserId())
.aggregateByTimestamp()
.countUniq();
......
package org.heigit.ohsome.oshdb.examples.analyses;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
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.OSMEntitySnapshotView;
import org.heigit.ohsome.oshdb.osm.OSMType;
import org.heigit.ohsome.oshdb.util.OSHDBBoundingBox;
import org.heigit.ohsome.oshdb.util.OSHDBTimestamp;
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;
public class RoadLength {
static List<String> other = Arrays.asList("unclassified", "road", "service", "track", "path",
static final List<String> other = List.of("unclassified", "road", "service", "track", "path",
"pedestrian", "footway", "cycleway", "steps", "platform", "bridleway");
static List<String> highway_motorway = Arrays.asList("motorway", "primary", "motorway_link",
"primary_link", "trunk", "trunk_link");
static List<String> secondary_tertiary = Arrays.asList("secondary", "secondary_link", "tertiary",
"tertiary_link");
static List<String> residential = Arrays.asList("residential", "living_street");
static final List<String> highway_motorway = List.of(
"motorway", "primary", "motorway_link", "primary_link", "trunk", "trunk_link");
static final List<String> secondary_tertiary = List.of(
"secondary", "secondary_link", "tertiary", "tertiary_link");
static final List<String> residential = List.of("residential", "living_street");
public static void main(String[] args) throws Exception {
// database
......@@ -38,8 +36,7 @@ public class RoadLength {
.keytables(oshdbKeytables)
.areaOfInterest(new OSHDBBoundingBox(71.45, -1.16, 74.7, 7.47)) // maldives
.timestamps("2007-01-01", "2017-12-01", Interval.MONTHLY)
.osmType(OSMType.WAY)
.osmTag("highway", highway_motorway)
.filter("type:way and highway in (" + String.join(",", highway_motorway) + ")")
.aggregateByTimestamp()
.sum(snapshot -> Geo.lengthOf(snapshot.getGeometry()) / 1000);
......
......@@ -5,26 +5,23 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
import org.heigit.ohsome.oshdb.OSHDBTimestamp;
import org.heigit.ohsome.oshdb.api.db.OSHDBDatabase;
import org.heigit.ohsome.oshdb.api.db.OSHDBH2;
import org.heigit.ohsome.oshdb.api.db.OSHDBJdbc;
import org.heigit.ohsome.oshdb.api.generic.function.SerializableBinaryOperator;
import org.heigit.ohsome.oshdb.api.generic.function.SerializableFunction;
import org.heigit.ohsome.oshdb.api.generic.function.SerializableSupplier;
import org.heigit.ohsome.oshdb.api.mapreducer.OSMContributionView;
import org.heigit.ohsome.oshdb.api.object.OSMContribution;
import org.heigit.ohsome.oshdb.osm.OSMType;
import org.heigit.ohsome.oshdb.util.OSHDBTimestamp;
import org.heigit.ohsome.oshdb.util.celliterator.ContributionType;
import org.heigit.ohsome.oshdb.util.function.SerializableBinaryOperator;
import org.heigit.ohsome.oshdb.util.function.SerializableFunction;
import org.heigit.ohsome.oshdb.util.function.SerializableSupplier;
import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps;
import org.jfree.ui.RefineryUtilities;
public class AdvandcedExample {
public static void main(String[] args)
throws SQLException,
ClassNotFoundException,
Exception {
public static void main(String[] args) throws Exception {
//Declare Database
OSHDBDatabase oshdb = new OSHDBH2(AdvandcedExample.class.getResource("/test.oshdb.mv.db")
......@@ -39,8 +36,7 @@ public class AdvandcedExample {
SortedMap<OSHDBTimestamp, Map<ContributionType, Integer>> reduce = OSMContributionView.on(oshdb)
.keytables(keytables)
.timestamps("2014-01-01", "2015-01-01", OSHDBTimestamps.Interval.MONTHLY)
.osmType(OSMType.WAY)
.osmTag("building")
.filter("geometry:polygon and building=*")
.map(new Mapper())
.aggregateByTimestamp()
.reduce(new IdentitySupplier(), new Combiner());
......@@ -106,8 +102,8 @@ public class AdvandcedExample {
result.putAll(mapResultA);
//sum up with all result from map-result B
mapResultB.forEach((ContributionType cType, Integer integ) -> {
result.merge(cType, integ, (Integer int1, Integer int2) -> int1 + int2);
mapResultB.forEach((ContributionType contribType, Integer integ) -> {
result.merge(contribType, integ, (Integer int1, Integer int2) -> int1 + int2);
});
return result;
......
......@@ -2,16 +2,16 @@ package org.heigit.ohsome.oshdb.tutorial;
import java.io.IOException;
import java.sql.SQLException;
import org.heigit.ohsome.oshdb.OSHDBBoundingBox;
import org.heigit.ohsome.oshdb.api.db.OSHDBDatabase;
import org.heigit.ohsome.oshdb.api.db.OSHDBH2;
import org.heigit.ohsome.oshdb.api.db.OSHDBJdbc;
import org.heigit.ohsome.oshdb.api.generic.function.SerializableFunction;
import org.heigit.ohsome.oshdb.api.generic.function.SerializablePredicate;
import org.heigit.ohsome.oshdb.api.mapreducer.MapReducer;
import org.heigit.ohsome.oshdb.api.mapreducer.OSMEntitySnapshotView;
import org.heigit.ohsome.oshdb.api.object.OSMEntitySnapshot;
import org.heigit.ohsome.oshdb.osm.OSMType;
import org.heigit.ohsome.oshdb.util.OSHDBBoundingBox;
import org.heigit.ohsome.oshdb.util.function.SerializableFunction;
import org.heigit.ohsome.oshdb.util.function.SerializablePredicate;
import org.heigit.ohsome.oshdb.util.geometry.Geo;
import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps.Interval;
......@@ -35,13 +35,13 @@ public class Tutorial {
// -- MANDATORY SETTINGS --
// declare and open a link to keytables
OSHDBJdbc tagsDB = new OSHDBH2(
OSHDBJdbc tagsDatabase = new OSHDBH2(
Tutorial.class.getResource("/test.oshdb.keytables.mv.db")
.getFile()
.replace(".mv.db", "")
);
// add keytables to the MapReducer
mapReducer = mapReducer.keytables(tagsDB);
mapReducer = mapReducer.keytables(tagsDatabase);
// Setting spatial extent
// create BoundingBox
......@@ -54,25 +54,22 @@ public class Tutorial {
mapReducer = mapReducer.timestamps("2014-01-01", "2015-01-01", Interval.MONTHLY);
// -- FILTER DATA --
// by type
mapReducer = mapReducer.osmType(OSMType.WAY);
// by tag
mapReducer = mapReducer.osmTag("building");
mapReducer = mapReducer.filter("type:way and building=*");
// -- Calculating intermediate results --
// mapping snapshots to area-values using a seperate class
MapReducer<Double> mapReducerII = mapReducer.map(new Mapper());
MapReducer<Double> mapReducer2 = mapReducer.map(new Mapper());
// -- Filtering intermediate results --
mapReducerII = mapReducerII.filter(new ResultFilter());
mapReducer2 = mapReducer2.filter(new ResultFilter());
// -- Reqeusting aggregated result --
// sum
Number result = mapReducerII.sum();
Number result = mapReducer2.sum();
// --Tear Down --
oshdb.close();
tagsDB.close();
tagsDatabase.close();
// -- RESULT --
System.out.println(result);
......
......@@ -4,7 +4,7 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedMap;
import org.heigit.ohsome.oshdb.util.OSHDBTimestamp;
import org.heigit.ohsome.oshdb.OSHDBTimestamp;
import org.heigit.ohsome.oshdb.util.celliterator.ContributionType;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
......@@ -43,8 +43,8 @@ public class TutorialChart extends ApplicationFrame {
.iterator();
while (it.hasNext()) {
Map.Entry<OSHDBTimestamp, Map<ContributionType, Integer>> ff = it.next();
Arrays.asList(ContributionType.values()).forEach((ContributionType cType) -> {
a.addValue(ff.getValue().get(cType), cType, ff
Arrays.asList(ContributionType.values()).forEach((ContributionType contribType) -> {
a.addValue(ff.getValue().get(contribType), contribType, ff
.getKey());
});
......
  • jenkinsci/branch: The Jenkins CI build failed - Details

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