Verified Commit f8620439 authored by Johannes Visintini's avatar Johannes Visintini
Browse files

add missing try-with to database and keytables connections

parent a0765a60
......@@ -11,22 +11,25 @@ import org.heigit.ohsome.oshdb.util.time.TimestampFormatter;
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(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();
}
// output
for (Map.Entry<OSHDBTimestamp, Integer> entry : result.entrySet()) {
System.out.format("%s\t%.2f%n",
......
......@@ -21,22 +21,26 @@ 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(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);
}
// output
for (Map.Entry<OSHDBTimestamp, Number> entry : result.entrySet()) {
System.out.format("%s\t%.2f%n",
......
......@@ -20,20 +20,22 @@ import org.jfree.ui.RefineryUtilities;
public class AdvandcedExample {
public static void main(String[] args) throws Exception {
//Declare Database
OSHDBDatabase oshdb = new OSHDBH2(AdvandcedExample.class.getResource("/test.oshdb.mv.db")
SortedMap<OSHDBTimestamp, Map<ContributionType, Integer>> reduce;
try (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")
.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);
......
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