Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

long to int coordinates, refactoring #395

Merged
merged 13 commits into from
Jul 16, 2021
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Changelog
* rename and move submodules of `oshdb-tool` ([#384])
* rename some classes, methods and enum constants; move some classes/interfaces ([#369], [#374])
* move the oshdb-api's ignite backend implementation into its own submodule `oshdb-api-ignite` ([#387])
* refactoring of internal coordinate representation form long to int, mainly `OSHDBBoundingBox`, `OSMNode`, `OSHEntity` ([#395])

> See the _upgrading from 0.6_ section below for instructions how to update your code according to these breaking changes.

Expand Down Expand Up @@ -78,6 +79,7 @@ Changelog
[#384]: https://github.com/GIScience/oshdb/pull/384
[#386]: https://github.com/GIScience/oshdb/issues/386
[#387]: https://github.com/GIScience/oshdb/pull/387
[#395]: https://github.com/GIScience/oshdb/pull/395


## 0.6.4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.heigit.ohsome.oshdb.api.mapreducer;

import static org.heigit.ohsome.oshdb.OSHDBBoundingBox.bboxLonLatCoordinates;

import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
Expand Down Expand Up @@ -163,7 +165,7 @@ public boolean isCancelable() {
TimestampFormatter.getInstance().date(new Date()),
OSHDBTimestamps.Interval.MONTHLY
);
protected OSHDBBoundingBox bboxFilter = new OSHDBBoundingBox(-180, -90, 180, 90);
protected OSHDBBoundingBox bboxFilter = bboxLonLatCoordinates(-180.0, -90.0, 180.0, 90.0);
private Geometry polyFilter = null;
protected EnumSet<OSMType> typeFilter = EnumSet.of(OSMType.NODE, OSMType.WAY, OSMType.RELATION);
private final List<SerializablePredicate<OSHEntity>> preFilters = new ArrayList<>();
Expand Down Expand Up @@ -218,7 +220,7 @@ public MapReducer<X> keytables(OSHDBJdbc keytables) {
Connection c = ((OSHDBJdbc) this.oshdb).getConnection();
boolean oshdbContainsKeytables = true;
try {
(new TagTranslator(c)).close();
new TagTranslator(c).close();
} catch (OSHDBKeytablesNotFoundException e) {
// this is the expected path -> the oshdb doesn't have the key tables
oshdbContainsKeytables = false;
Expand Down Expand Up @@ -565,7 +567,7 @@ public MapReducer<X> osmTag(String key, Collection<String> values) {
int keyId = oshdbKey.toInt();
if (!oshdbKey.isPresentInKeytables() || values.isEmpty()) {
LOG.warn(
(values.isEmpty() ? EMPTY_TAG_LIST : TAG_KEY_NOT_FOUND),
values.isEmpty() ? EMPTY_TAG_LIST : TAG_KEY_NOT_FOUND,
key
);
return osmTagEmptyResult();
Expand Down Expand Up @@ -1997,8 +1999,8 @@ protected OSMEntityFilter getFilter() {
protected Iterable<CellIdRange> getCellIdRanges() {
XYGridTree grid = new XYGridTree(OSHDB.MAXZOOM);
if (this.bboxFilter == null
|| this.bboxFilter.getMinLon() >= this.bboxFilter.getMaxLon()
|| this.bboxFilter.getMinLat() >= this.bboxFilter.getMaxLat()) {
|| this.bboxFilter.getMinLongitude() >= this.bboxFilter.getMaxLongitude()
|| this.bboxFilter.getMinLatitude() >= this.bboxFilter.getMaxLatitude()) {
// return an empty iterable if bbox is not set or empty
LOG.warn("area of interest not set or empty");
return Collections.emptyList();
Expand All @@ -2017,7 +2019,7 @@ protected <P extends Geometry & Polygonal> P getPolyFilter() {
private SerializableFunction<Object, X> getMapper() {
// todo: maybe we can somehow optimize this?? at least for special cases like
// this.mappers.size() == 1
return (SerializableFunction<Object, X>) (data -> {
return (SerializableFunction<Object, X>) data -> {
// working with raw Objects since we don't know the actual intermediate types ¯\_(ツ)_/¯
Object result = data;
for (MapFunction mapper : this.mappers) {
Expand All @@ -2032,14 +2034,14 @@ private SerializableFunction<Object, X> getMapper() {
// after applying all mapper functions, the result type is X
X mappedResult = (X) result;
return mappedResult;
});
};
}

// concatenates all applied `flatMap` and `map` functions
private SerializableFunction<Object, Iterable<X>> getFlatMapper() {
// todo: maybe we can somehow optimize this?? at least for special cases like
// this.mappers.size() == 1
return (SerializableFunction<Object, Iterable<X>>) (data -> {
return (SerializableFunction<Object, Iterable<X>>) data -> {
// working with raw objects since we don't know the actual intermediate types ¯\_(ツ)_/¯
List<Object> results = new LinkedList<>();
results.add(data);
Expand All @@ -2057,7 +2059,7 @@ private SerializableFunction<Object, Iterable<X>> getFlatMapper() {
// after applying all mapper functions, the result type is List<X>
Iterable<X> mappedResults = (Iterable<X>) results;
return mappedResults;
});
};
}

// gets list of timestamps to use for zerofilling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class TestCollect {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox =
new OSHDBBoundingBox(8.651133, 49.387611, 8.6561, 49.390513);
OSHDBBoundingBox.bboxLonLatCoordinates(8.651133, 49.387611, 8.6561, 49.390513);
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
OSHDBTimestamps.Interval.MONTHLY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ohsome.oshdb.api.tests;

import static org.heigit.ohsome.oshdb.OSHDBBoundingBox.bboxLonLatCoordinates;
import static org.junit.Assert.assertEquals;

import java.util.AbstractMap.SimpleImmutableEntry;
Expand All @@ -26,7 +27,7 @@
public class TestFlatMapAggregate {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox = new OSHDBBoundingBox(8, 49, 9, 50);
private final OSHDBBoundingBox bbox = bboxLonLatCoordinates(8.0, 49.0, 9.0, 50.0);
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
OSHDBTimestamps.Interval.MONTHLY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ohsome.oshdb.api.tests;

import static org.heigit.ohsome.oshdb.OSHDBBoundingBox.bboxLonLatCoordinates;
import static org.junit.Assert.assertEquals;

import java.util.AbstractMap.SimpleImmutableEntry;
Expand All @@ -24,7 +25,7 @@
public class TestFlatMapAggregateGroupedByEntity {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox = new OSHDBBoundingBox(8, 49, 9, 50);
private final OSHDBBoundingBox bbox = bboxLonLatCoordinates(8.0, 49.0, 9.0, 50.0);
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
OSHDBTimestamps.Interval.MONTHLY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ohsome.oshdb.api.tests;

import static org.heigit.ohsome.oshdb.OSHDBBoundingBox.bboxLonLatCoordinates;
import static org.junit.Assert.assertEquals;

import java.util.AbstractMap.SimpleImmutableEntry;
Expand All @@ -26,7 +27,7 @@
public class TestFlatMapReduce {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox = new OSHDBBoundingBox(8, 49, 9, 50);
private final OSHDBBoundingBox bbox = bboxLonLatCoordinates(8.0, 49.0, 9.0, 50.0);
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
OSHDBTimestamps.Interval.MONTHLY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ohsome.oshdb.api.tests;

import static org.heigit.ohsome.oshdb.OSHDBBoundingBox.bboxLonLatCoordinates;
import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
Expand All @@ -22,7 +23,7 @@
abstract class TestFlatMapReduceGroupedByEntity {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox = new OSHDBBoundingBox(8, 49, 9, 50);
private final OSHDBBoundingBox bbox = bboxLonLatCoordinates(8.0, 49.0, 9.0, 50.0);
private final OSHDBTimestamps timestamps6 = new OSHDBTimestamps("2010-01-01", "2015-01-01",
OSHDBTimestamps.Interval.YEARLY);
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TestForEach {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox =
new OSHDBBoundingBox(8.651133, 49.387611, 8.6561, 49.390513);
OSHDBBoundingBox.bboxLonLatCoordinates(8.651133, 49.387611, 8.6561, 49.390513);
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
OSHDBTimestamps.Interval.MONTHLY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class TestHelpersOSMContributionView {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox =
new OSHDBBoundingBox(8.651133, 49.387611, 8.6561, 49.390513);
OSHDBBoundingBox.bboxLonLatCoordinates(8.651133, 49.387611, 8.6561, 49.390513);
private final OSHDBTimestamps timestamps2 = new OSHDBTimestamps("2014-01-01", "2015-01-01");
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
OSHDBTimestamps.Interval.MONTHLY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestHelpersOSMEntitySnapshotView {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox =
new OSHDBBoundingBox(8.651133, 49.387611, 8.6561, 49.390513);
OSHDBBoundingBox.bboxLonLatCoordinates(8.651133, 49.387611, 8.6561, 49.390513);
private final OSHDBTimestamps timestamps1 = new OSHDBTimestamps("2014-01-01");
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
OSHDBTimestamps.Interval.MONTHLY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ohsome.oshdb.api.tests;

import static org.heigit.ohsome.oshdb.OSHDBBoundingBox.bboxLonLatCoordinates;
import static org.junit.Assert.assertEquals;

import java.util.Set;
Expand All @@ -21,7 +22,7 @@
public class TestLambdaFilter {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox = new OSHDBBoundingBox(8, 49, 9, 50);
private final OSHDBBoundingBox bbox = bboxLonLatCoordinates(8.0, 49.0, 9.0, 50.0);
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
OSHDBTimestamps.Interval.MONTHLY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ohsome.oshdb.api.tests;

import static org.heigit.ohsome.oshdb.OSHDBBoundingBox.bboxLonLatCoordinates;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -32,7 +33,7 @@
public class TestMapAggregateByGeometry {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox = new OSHDBBoundingBox(8, 49, 9, 50);
private final OSHDBBoundingBox bbox = bboxLonLatCoordinates(8.0, 49.0, 9.0, 50.0);
private final OSHDBTimestamps timestamps1 = new OSHDBTimestamps("2015-12-01");
private final OSHDBTimestamps timestamps2 = new OSHDBTimestamps("2010-01-01", "2015-12-01");

Expand Down Expand Up @@ -61,16 +62,16 @@ private MapReducer<OSMEntitySnapshot> createMapReducerOSMEntitySnapshot() throws
private Map<String, Polygon> getSubRegions() {
Map<String, Polygon> res = new TreeMap<>();
res.put("left", OSHDBGeometryBuilder.getGeometry(
new OSHDBBoundingBox(8, 49, 8.66128, 50)
bboxLonLatCoordinates(8, 49, 8.66128, 50)
));
res.put("right", OSHDBGeometryBuilder.getGeometry(
new OSHDBBoundingBox(8.66128 + 1E-8, 49, 9, 50)
bboxLonLatCoordinates(8.66128 + 1E-8, 49, 9, 50)
));
res.put("total", OSHDBGeometryBuilder.getGeometry(
bbox
));
res.put("null island", OSHDBGeometryBuilder.getGeometry(
new OSHDBBoundingBox(-1, -1, 1, 1)
bboxLonLatCoordinates(-1.0, -1.0, 1.0, 1.0)
));
return res;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ohsome.oshdb.api.tests;

import static org.heigit.ohsome.oshdb.OSHDBBoundingBox.bboxLonLatCoordinates;
import static org.junit.Assert.assertEquals;

import java.util.Collections;
Expand All @@ -25,7 +26,7 @@
public class TestMapAggregateByIndex {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox = new OSHDBBoundingBox(8, 49, 9, 50);
private final OSHDBBoundingBox bbox = bboxLonLatCoordinates(8.0, 49.0, 9.0, 50.0);
private final OSHDBTimestamps timestamps1 = new OSHDBTimestamps("2015-12-01");
private final OSHDBTimestamps timestamps2 = new OSHDBTimestamps("2010-01-01", "2015-12-01");
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class TestMapAggregateByTimestamp {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox =
new OSHDBBoundingBox(8.651133, 49.387611, 8.6561, 49.390513);
OSHDBBoundingBox.bboxLonLatCoordinates(8.651133, 49.387611, 8.6561, 49.390513);
private final OSHDBTimestamps timestamps1 = new OSHDBTimestamps("2014-01-01");
private final OSHDBTimestamps timestamps2 = new OSHDBTimestamps("2014-01-01", "2014-12-30");
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ohsome.oshdb.api.tests;

import static org.heigit.ohsome.oshdb.OSHDBBoundingBox.bboxLonLatCoordinates;
import static org.junit.Assert.assertEquals;

import java.util.List;
Expand All @@ -26,7 +27,7 @@ abstract class TestMapReduce {
final OSHDBDatabase oshdb;
OSHDBJdbc keytables = null;

private final OSHDBBoundingBox bbox = new OSHDBBoundingBox(8, 49, 9, 50);
private final OSHDBBoundingBox bbox = bboxLonLatCoordinates(8.0, 49.0, 9.0, 50.0);
private final OSHDBTimestamps timestamps6 = new OSHDBTimestamps("2010-01-01", "2015-01-01",
OSHDBTimestamps.Interval.YEARLY);
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TestOSHDBFilter {
private final FilterParser filterParser;

private final OSHDBBoundingBox bbox =
new OSHDBBoundingBox(8.651133, 49.387611, 8.6561, 49.390513);
OSHDBBoundingBox.bboxLonLatCoordinates(8.651133, 49.387611, 8.6561, 49.390513);

/**
* Creates a test runner using the H2 backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TestOSMDataFilters {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox =
new OSHDBBoundingBox(8.651133, 49.387611, 8.6561, 49.390513);
OSHDBBoundingBox.bboxLonLatCoordinates(8.651133, 49.387611, 8.6561, 49.390513);
private final OSHDBTimestamps timestamps1 = new OSHDBTimestamps("2014-01-01");

public TestOSMDataFilters() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class TestQuantiles {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox =
new OSHDBBoundingBox(8.651133, 49.387611, 8.6561, 49.390513);
OSHDBBoundingBox.bboxLonLatCoordinates(8.651133, 49.387611, 8.6561, 49.390513);
private final OSHDBTimestamps timestamps1 = new OSHDBTimestamps("2015-01-01");
private final OSHDBTimestamps timestamps2 = new OSHDBTimestamps("2014-01-01", "2015-01-01");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TestStream {
private final OSHDBDatabase oshdb;

private final OSHDBBoundingBox bbox =
new OSHDBBoundingBox(8.651133, 49.387611, 8.6561, 49.390513);
OSHDBBoundingBox.bboxLonLatCoordinates(8.651133, 49.387611, 8.6561, 49.390513);
private final OSHDBTimestamps timestamps72 = new OSHDBTimestamps("2010-01-01", "2015-12-01",
OSHDBTimestamps.Interval.MONTHLY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.heigit.ohsome.oshdb.tool.importer.extract.collector;

import static org.heigit.ohsome.oshdb.osm.OSMCoordinates.GEOM_PRECISION;

import crosby.binary.Osmformat.HeaderBBox;
import crosby.binary.Osmformat.HeaderBlock;
import java.io.PrintStream;
Expand All @@ -9,7 +11,6 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import org.heigit.ohsome.oshdb.OSHDB;
import org.heigit.ohsome.oshdb.osm.OSMType;
import org.heigit.ohsome.oshpbf.parser.osm.v06.Entity;
import org.heigit.ohsome.oshpbf.parser.osm.v06.Node;
Expand Down Expand Up @@ -139,9 +140,9 @@ public void print(PrintStream out) {
}

if (minLon != Integer.MAX_VALUE) {
out.printf("data.bbox=%.7f,%.7f,%.7f,%.7f%n", minLon * OSHDB.GEOM_PRECISION,
minLat * OSHDB.GEOM_PRECISION, maxLon * OSHDB.GEOM_PRECISION,
maxLat * OSHDB.GEOM_PRECISION);
out.printf("data.bbox=%.7f,%.7f,%.7f,%.7f%n", minLon * GEOM_PRECISION,
minLat * GEOM_PRECISION, maxLon * GEOM_PRECISION,
maxLat * GEOM_PRECISION);
}

out.printf("data.timerange=%s,%s%n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import it.unimi.dsi.fastutil.longs.Long2ObjectAVLTreeMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -48,7 +49,7 @@ public LoaderNode(Path workDirectory, Handler handler, int minEntitiesPerCell,
files = StreamSupport.stream(stream.spliterator(), false).collect(Collectors.toList())
.toArray(new Path[0]);
} catch (IOException e) {
throw new RuntimeException(e);
throw new UncheckedIOException(e);
}

reader = new TransfromNodeReaders(files);
Expand Down
Loading