5 | * The purpose of these interfaces (copying the functionality of JAVA's generic lambda functions)
6 | * is to make them serializable.
7 | *
8 | */
9 | package org.heigit.ohsome.oshdb.util.function;
10 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPointInPolygon.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.geometry.fip;
2 |
3 | import java.util.function.Predicate;
4 | import org.locationtech.jts.geom.Geometry;
5 | import org.locationtech.jts.geom.Point;
6 | import org.locationtech.jts.geom.Polygonal;
7 |
8 | /**
9 | * Fast point in (multi)polygon test inspired by
10 | * {
14 | public FastPointInPolygon(P geom) {
15 | super(geom);
16 | }
17 |
18 | /**
19 | * Tests if the given bounding box is fully inside of the polygon.
20 | */
21 | @Override
22 | public boolean test(Point point) {
23 | return crossingNumber(point, true) % 2 == 1;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/mappable/OSHDBMapReducible.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.mappable;
2 |
3 | /**
4 | * Marks a class as possible data type of an OSHDB-MapReducer.
5 | */
6 | public interface OSHDBMapReducible {}
7 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/mappable/OSMEntitySnapshot.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.mappable;
2 |
3 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
4 | import org.heigit.ohsome.oshdb.osh.OSHEntity;
5 | import org.heigit.ohsome.oshdb.osm.OSMEntity;
6 | import org.locationtech.jts.geom.Geometry;
7 |
8 | /**
9 | * Information about a single OSM object at a specific point in time ("snapshot").
10 | */
11 | public interface OSMEntitySnapshot extends OSHDBMapReducible, Comparable {
12 | /**
13 | * The timestamp for which the snapshot of this data entity has been obtained.
14 | *
15 | * @return snapshot timestamp as an OSHDBTimestamp object
16 | */
17 | OSHDBTimestamp getTimestamp();
18 |
19 | /**
20 | * The timestamp when the entity of the snapshot was last modified before the snapshot timestamp.
21 | *
22 | * @return last modification timestamp as an OSHDBTimestamp object
23 | */
24 | OSHDBTimestamp getLastContributionTimestamp();
25 |
26 | /**
27 | * The geometry of this entity at the snapshot's timestamp clipped to the requested area of
28 | * interest.
29 | *
30 | * @return the geometry as a JTS Geometry
31 | */
32 | Geometry getGeometry();
33 |
34 | /**
35 | * The geometry of this entity at the snapshot's timestamp. This is the full (unclipped) geometry
36 | * of the osm entity.
37 | *
38 | * @return the unclipped geometry of the osm entity snapshot as a JTS Geometry
39 | */
40 | Geometry getGeometryUnclipped();
41 |
42 | /**
43 | * The entity for which the snapshot has been obtained.
44 | *
45 | * This is the (not deleted) version of a OSHEntity that was valid at the provided snapshot
46 | * timestamp.
47 | *
48 | * @return the OSMEntity object of this snapshot
49 | */
50 | OSMEntity getEntity();
51 |
52 | /**
53 | * The (parent) osh entity of the osm entity for which the snapshot has been obtained.
54 | *
55 | * @return the OSHEntity object corresponding to this snapshot
56 | */
57 | OSHEntity getOSHEntity();
58 | }
59 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/mappable/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Interfaces for "mappable" objects in the oshdb API.
3 | */
4 | package org.heigit.ohsome.oshdb.util.mappable;
5 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/taginterpreter/InvertedHashSet.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.taginterpreter;
2 |
3 | import java.util.HashSet;
4 | import java.util.Set;
5 |
6 | /**
7 | * Negated Set: contains(x) returns true only if x has not been add()ed to the inverted set
8 | * previously. Useful to supply where a method expects a whitelist "set", but one has a blacklist of
9 | * values instead. (or vv)
10 | */
11 | public class InvertedHashSet extends HashSet implements Set {
12 | private static final long serialVersionUID = 1L;
13 |
14 | @Override
15 | public boolean isEmpty() {
16 | return false;
17 | }
18 |
19 | @Override
20 | public boolean contains(Object o) {
21 | return !super.contains(o);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/taginterpreter/TagInterpreter.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.taginterpreter;
2 |
3 | import java.io.Serializable;
4 | import org.heigit.ohsome.oshdb.osm.OSMEntity;
5 | import org.heigit.ohsome.oshdb.osm.OSMMember;
6 | import org.heigit.ohsome.oshdb.osm.OSMRelation;
7 |
8 | /**
9 | * Used to provided information needed to create actual geometries from OSM data.
10 | *
11 | *
12 | * Some information about OSM entities is only soft-coded into their tags, for example if a closed
13 | * way should represent a polygon (e.g. a building) or just a (linestring) loop (e.g. a roundabout).
14 | * Similarly, some information needed to build geometries from multipolygon relations is encoded
15 | * into the relation members' roles.
16 | *
17 | */
18 | public interface TagInterpreter extends Serializable {
19 |
20 | boolean isArea(OSMEntity entity);
21 |
22 | boolean isLine(OSMEntity entity);
23 |
24 | boolean hasInterestingTagKey(OSMEntity osm);
25 |
26 | boolean isMultipolygonOuterMember(OSMMember osmMember);
27 |
28 | boolean isMultipolygonInnerMember(OSMMember osmMember);
29 |
30 | boolean isOldStyleMultipolygon(OSMRelation osmRelation);
31 | }
32 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/tagtranslator/ClosableSqlArray.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.tagtranslator;
2 |
3 | import java.sql.Array;
4 | import java.sql.Connection;
5 | import java.sql.SQLException;
6 | import java.util.Collection;
7 |
8 | public class ClosableSqlArray implements AutoCloseable {
9 |
10 | public static ClosableSqlArray createArray(Connection conn, String typeName, Collection elements) throws SQLException {
11 | var array = conn.createArrayOf(typeName, elements.toArray());
12 | return new ClosableSqlArray(array);
13 | }
14 |
15 | private Array array;
16 |
17 | public ClosableSqlArray(Array array) {
18 | this.array = array;
19 | }
20 |
21 | public Array get() {
22 | return array;
23 | }
24 |
25 | @Override
26 | public void close() throws Exception {
27 | array.free();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/tagtranslator/OSMRole.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.tagtranslator;
2 |
3 | /**
4 | * Represents an OSM role (which can be an arbitrary string).
5 | */
6 | public class OSMRole {
7 | private String role;
8 |
9 | public OSMRole(String role) {
10 | this.role = role;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return this.role;
16 | }
17 |
18 | @Override
19 | public boolean equals(Object o) {
20 | return o instanceof OSMRole && ((OSMRole) o).role.equals(this.role);
21 | }
22 |
23 | @Override
24 | public int hashCode() {
25 | return this.role.hashCode();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/tagtranslator/OSMTag.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.tagtranslator;
2 |
3 | /**
4 | * Represents an OSM tag (which consists of two arbitrary strings forming a key-value pair).
5 | */
6 | public class OSMTag implements OSMTagInterface {
7 | private String key;
8 | private String value;
9 |
10 | public OSMTag(String key, String value) {
11 | this.key = key;
12 | this.value = value;
13 | }
14 |
15 | public String getKey() {
16 | return this.key;
17 | }
18 |
19 | public String getValue() {
20 | return this.value;
21 | }
22 |
23 | @Override
24 | public boolean equals(Object o) {
25 | return o instanceof OSMTag
26 | && ((OSMTag) o).key.equals(this.key) && ((OSMTag) o).value.equals(this.value);
27 | }
28 |
29 | @Override
30 | public int hashCode() {
31 | return this.key.hashCode() + this.value.hashCode();
32 | }
33 |
34 | @Override
35 | public String toString() {
36 | return this.key + "=" + this.value;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/tagtranslator/OSMTagInterface.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.tagtranslator;
2 |
3 | /**
4 | * An OSM tag ({@link OSMTag}) or an OSM tag key ({@link OSMTagKey}).
5 | *
6 | * This interface allows to write methods that accept both OSMTag and OSMTagKey
7 | * objects as parameters without overloading, and it allows to write methods that
8 | * return either an OSMTag or an OSMTagKey object.
9 | */
10 | public interface OSMTagInterface {}
11 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/tagtranslator/OSMTagKey.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.tagtranslator;
2 |
3 | /**
4 | * Represents an OSM tag key (which can be an arbitrary string).
5 | */
6 | public class OSMTagKey implements OSMTagInterface {
7 | private String key;
8 |
9 | public OSMTagKey(String key) {
10 | this.key = key;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return this.key;
16 | }
17 |
18 | @Override
19 | public boolean equals(Object o) {
20 | return o instanceof OSMTagKey && ((OSMTagKey) o).key.equals(this.key);
21 | }
22 |
23 | @Override
24 | public int hashCode() {
25 | return this.key.hashCode();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/time/OSHDBTimestampException.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.time;
2 |
3 | /**
4 | * An exception representing a problem of handling timestamps in the OSHDB.
5 | */
6 | public class OSHDBTimestampException extends RuntimeException {
7 |
8 | public OSHDBTimestampException(String message) {
9 | super(message);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/time/OSHDBTimestampIllegalArgumentException.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.time;
2 |
3 | /**
4 | * An exception marking a problem with (for the OSHDB) illegal timestamps.
5 | */
6 | public class OSHDBTimestampIllegalArgumentException extends OSHDBTimestampException {
7 |
8 | public OSHDBTimestampIllegalArgumentException(String message) {
9 | super(message);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/time/OSHDBTimestampInterval.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.time;
2 |
3 | import java.io.Serializable;
4 | import java.util.Objects;
5 | import java.util.SortedSet;
6 | import javax.annotation.Nonnull;
7 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
8 |
9 | /**
10 | * A from-to time interval.
11 | */
12 | public class OSHDBTimestampInterval implements Serializable, Comparable {
13 | private final OSHDBTimestamp fromTimestamp;
14 | private final OSHDBTimestamp toTimestamp;
15 |
16 | public OSHDBTimestampInterval() {
17 | this(new OSHDBTimestamp(Long.MIN_VALUE), new OSHDBTimestamp(Long.MAX_VALUE));
18 | }
19 |
20 | public OSHDBTimestampInterval(OSHDBTimestamp fromTimestamp, OSHDBTimestamp toTimestamp) {
21 | this.fromTimestamp = fromTimestamp;
22 | this.toTimestamp = toTimestamp;
23 | }
24 |
25 | public OSHDBTimestampInterval(SortedSet oshdbTimestamps) {
26 | this(oshdbTimestamps.first(), oshdbTimestamps.last());
27 | }
28 |
29 | public boolean intersects(OSHDBTimestampInterval other) {
30 | return other.toTimestamp.getEpochSecond() >= this.fromTimestamp.getEpochSecond()
31 | && other.fromTimestamp.getEpochSecond() <= this.toTimestamp.getEpochSecond();
32 | }
33 |
34 | public boolean includes(OSHDBTimestamp timestamp) {
35 | return timestamp.getEpochSecond() >= this.fromTimestamp.getEpochSecond()
36 | && timestamp.getEpochSecond() < this.toTimestamp.getEpochSecond();
37 | }
38 |
39 | @SuppressWarnings("MissingJavadocMethod")
40 | public int compareAgainstTimestamp(@Nonnull OSHDBTimestamp timestamp) {
41 | if (this.includes(timestamp)) {
42 | return 0;
43 | }
44 | return timestamp.getEpochSecond() < this.fromTimestamp.getEpochSecond() ? -1 : 1;
45 | }
46 |
47 | @Override
48 | public int compareTo(@Nonnull OSHDBTimestampInterval o) {
49 | int c = this.fromTimestamp.compareTo(o.fromTimestamp);
50 | if (c == 0) {
51 | c = this.toTimestamp.compareTo(o.toTimestamp);
52 | }
53 | return c;
54 | }
55 |
56 | @Override
57 | public boolean equals(Object o) {
58 | return o instanceof OSHDBTimestampInterval
59 | && this.fromTimestamp.equals(((OSHDBTimestampInterval) o).fromTimestamp)
60 | && this.toTimestamp.equals(((OSHDBTimestampInterval) o).toTimestamp);
61 | }
62 |
63 | @Override
64 | public int hashCode() {
65 | return Objects.hash(fromTimestamp, toTimestamp);
66 | }
67 | }
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/time/OSHDBTimestampList.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.time;
2 |
3 | import java.io.Serializable;
4 | import java.util.SortedSet;
5 | import java.util.TreeSet;
6 | import java.util.stream.Collectors;
7 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
8 |
9 | /**
10 | * Provider of a sorted list of (unix) timestamps.
11 | */
12 | public interface OSHDBTimestampList extends Serializable {
13 | /**
14 | * Provides a sorted set of OSHDBTimestamps.
15 | *
16 | * @return a sorted set of oshdb timestamps
17 | */
18 | SortedSet get();
19 |
20 | /**
21 | * Convenience method that converts the timestamp list into raw unix timestamps (long values).
22 | *
23 | * @return this list of timestamps as raw unix timestamps (measured in seconds)
24 | */
25 | default SortedSet getRawUnixTimestamps() {
26 | return this.get().stream()
27 | .map(OSHDBTimestamp::getEpochSecond)
28 | .collect(Collectors.toCollection(TreeSet::new));
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/time/OSHDBTimestampParseException.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.time;
2 |
3 | /**
4 | * An exception marking a parsing problem.
5 | */
6 | public class OSHDBTimestampParseException extends OSHDBTimestampException {
7 |
8 | public OSHDBTimestampParseException(String message) {
9 | super(message);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/oshdb-util/src/main/resources/json/uninterestingTags.json:
--------------------------------------------------------------------------------
1 | [
2 | "source",
3 | "source_ref",
4 | "source:ref",
5 | "history",
6 | "attribution",
7 | "created_by",
8 | "tiger:county",
9 | "tiger:tlid",
10 | "tiger:upload_uuid"
11 | ]
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/geometry/OSHDBGeometryTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.geometry;
2 |
3 | import static org.heigit.ohsome.oshdb.util.geometry.helpers.TimestampParser.toOSHDBTimestamp;
4 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
5 |
6 | import com.google.common.collect.ListMultimap;
7 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
8 | import org.heigit.ohsome.oshdb.osm.OSMEntity;
9 | import org.heigit.ohsome.oshdb.osm.OSMNode;
10 | import org.heigit.ohsome.oshdb.osm.OSMRelation;
11 | import org.heigit.ohsome.oshdb.osm.OSMWay;
12 | import org.heigit.ohsome.oshdb.util.geometry.helpers.OSMXmlReaderTagInterpreter;
13 | import org.heigit.ohsome.oshdb.util.taginterpreter.TagInterpreter;
14 | import org.heigit.ohsome.oshdb.util.xmlreader.OSMXmlReader;
15 | import org.locationtech.jts.geom.Geometry;
16 |
17 | public abstract class OSHDBGeometryTest {
18 | protected final OSMXmlReader testData = new OSMXmlReader();
19 | protected final ListMultimap nodes;
20 | protected final ListMultimap ways;
21 | protected final ListMultimap relations;
22 | protected final TagInterpreter areaDecider;
23 |
24 | protected OSHDBGeometryTest(String... testdata) {
25 | for (var data : testdata) {
26 | testData.add(data);
27 | }
28 | nodes = testData.nodes();
29 | ways = testData.ways();
30 | relations = testData.relations();
31 | areaDecider = new OSMXmlReaderTagInterpreter(testData);
32 | }
33 |
34 | protected OSMNode nodes(long id, int index) {
35 | return nodes.get(id).get(index);
36 | }
37 |
38 | protected OSMWay ways(long id, int index) {
39 | return ways.get(id).get(index);
40 | }
41 |
42 | protected OSMRelation relations(long id, int index) {
43 | return relations.get(id).get(index);
44 | }
45 |
46 | protected Geometry buildGeometry(OSMEntity entity) {
47 | OSHDBTimestamp timestamp = new OSHDBTimestamp(entity);
48 | return buildGeometry(entity, timestamp);
49 | }
50 |
51 | protected Geometry buildGeometry(OSMEntity entity, String timestamp) {
52 | return buildGeometry(entity, toOSHDBTimestamp(timestamp));
53 | }
54 |
55 | protected Geometry buildGeometry(OSMEntity entity, OSHDBTimestamp timestamp) {
56 | return assertDoesNotThrow(() ->
57 | OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider));
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/geometry/helpers/FakeTagInterpreter.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.geometry.helpers;
2 |
3 | import org.heigit.ohsome.oshdb.osm.OSMEntity;
4 | import org.heigit.ohsome.oshdb.osm.OSMMember;
5 | import org.heigit.ohsome.oshdb.osm.OSMRelation;
6 | import org.heigit.ohsome.oshdb.util.taginterpreter.TagInterpreter;
7 |
8 | /**
9 | * A dummy implementation of the {@link TagInterpreter} interface.
10 | */
11 | public abstract class FakeTagInterpreter implements TagInterpreter {
12 | @Override
13 | public boolean isArea(OSMEntity entity) {
14 | return false;
15 | }
16 |
17 | @Override
18 | public boolean isLine(OSMEntity entity) {
19 | return !isArea(entity);
20 | }
21 |
22 | @Override
23 | public boolean hasInterestingTagKey(OSMEntity osm) {
24 | return false;
25 | }
26 |
27 | @Override
28 | public boolean isMultipolygonOuterMember(OSMMember osmMember) {
29 | return false;
30 | }
31 |
32 | @Override
33 | public boolean isMultipolygonInnerMember(OSMMember osmMember) {
34 | return false;
35 | }
36 |
37 | @Override
38 | public boolean isOldStyleMultipolygon(OSMRelation osmRelation) {
39 | return false;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/geometry/helpers/FakeTagInterpreterAreaAlways.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.geometry.helpers;
2 |
3 | import org.heigit.ohsome.oshdb.osm.OSMEntity;
4 | import org.heigit.ohsome.oshdb.osm.OSMMember;
5 | import org.heigit.ohsome.oshdb.osm.OSMWay;
6 | import org.heigit.ohsome.oshdb.util.taginterpreter.TagInterpreter;
7 |
8 | /**
9 | * A dummy implementation of the {@link TagInterpreter} interface which interprets all closed ways
10 | * as polygons.
11 | */
12 | public class FakeTagInterpreterAreaAlways extends FakeTagInterpreter {
13 | @Override
14 | public boolean isArea(OSMEntity e) {
15 | if (e instanceof OSMWay) {
16 | OSMMember[] nds = ((OSMWay) e).getMembers();
17 | return (nds.length >= 4 && nds[0].getId() == nds[nds.length - 1].getId());
18 | }
19 | return true;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/geometry/helpers/FakeTagInterpreterAreaMultipolygonAllOuters.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.geometry.helpers;
2 |
3 | import org.heigit.ohsome.oshdb.osm.OSMMember;
4 | import org.heigit.ohsome.oshdb.util.taginterpreter.TagInterpreter;
5 |
6 | /**
7 | * A dummy implementation of the {@link TagInterpreter} interface which interprets all
8 | * multipolygon members as outer ways.
9 | */
10 | public class FakeTagInterpreterAreaMultipolygonAllOuters extends FakeTagInterpreterAreaAlways {
11 | @Override
12 | public boolean isMultipolygonOuterMember(OSMMember osmMember) {
13 | return true;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/geometry/helpers/FakeTagInterpreterAreaNever.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.geometry.helpers;
2 |
3 | import org.heigit.ohsome.oshdb.osm.OSMEntity;
4 | import org.heigit.ohsome.oshdb.util.taginterpreter.TagInterpreter;
5 |
6 | /**
7 | * A dummy implementation of the {@link TagInterpreter} interface which interprets all OSM ways
8 | * as lines.
9 | */
10 | public class FakeTagInterpreterAreaNever extends FakeTagInterpreter {
11 | @Override
12 | public boolean isArea(OSMEntity e) {
13 | return false;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/geometry/helpers/OSMXmlReaderTagInterpreter.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.geometry.helpers;
2 |
3 | import org.heigit.ohsome.oshdb.osm.OSMEntity;
4 | import org.heigit.ohsome.oshdb.osm.OSMMember;
5 | import org.heigit.ohsome.oshdb.osm.OSMRelation;
6 | import org.heigit.ohsome.oshdb.osm.OSMType;
7 | import org.heigit.ohsome.oshdb.osm.OSMWay;
8 | import org.heigit.ohsome.oshdb.util.xmlreader.OSMXmlReader;
9 |
10 | /**
11 | * An implementation of the tag interpreter for use with {@link OSMXmlReader}.
12 | */
13 | public class OSMXmlReaderTagInterpreter extends FakeTagInterpreter {
14 | private final int area;
15 | private final int areaYes;
16 | private final int type;
17 | private final int typeMultipolygon;
18 | private final int emptyRole;
19 | private final int outer;
20 | private final int inner;
21 |
22 | /**
23 | * Constructor reading all required values from a given {@link OSMXmlReader}.
24 | */
25 | public OSMXmlReaderTagInterpreter(OSMXmlReader osmXmlReader) {
26 | area = osmXmlReader.keys().getOrDefault("area", -1);
27 | areaYes = area == -1 ? -1 : osmXmlReader.keyValues().get(area).getOrDefault("yes", -1);
28 | type = osmXmlReader.keys().getOrDefault("type", -1);
29 | typeMultipolygon = type == -1 ? -1 : osmXmlReader.keyValues().get(type)
30 | .getOrDefault("multipolygon", -1);
31 | emptyRole = osmXmlReader.roles().getOrDefault("", -1);
32 | outer = osmXmlReader.roles().getOrDefault("outer", -1);
33 | inner = osmXmlReader.roles().getOrDefault("inner", -1);
34 | }
35 |
36 | @Override
37 | public boolean isArea(OSMEntity e) {
38 | if (e instanceof OSMWay) {
39 | OSMMember[] nds = ((OSMWay) e).getMembers();
40 | return nds.length >= 4 && nds[0].getId() == nds[nds.length - 1].getId()
41 | && e.getTags().hasTag(area, areaYes);
42 | }
43 | if (e instanceof OSMRelation) {
44 | return e.getTags().hasTag(type, typeMultipolygon);
45 | }
46 | return true;
47 | }
48 |
49 | @Override
50 | public boolean isMultipolygonOuterMember(OSMMember osmMember) {
51 | return osmMember.getType() == OSMType.WAY
52 | && (osmMember.getRole().getId() == outer || osmMember.getRole().getId() == emptyRole);
53 | }
54 |
55 | @Override
56 | public boolean isMultipolygonInnerMember(OSMMember osmMember) {
57 | return osmMember.getType() == OSMType.WAY && osmMember.getRole().getId() == inner;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/geometry/helpers/TimestampParser.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.geometry.helpers;
2 |
3 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
4 | import org.heigit.ohsome.oshdb.util.time.IsoDateTimeParser;
5 |
6 | /**
7 | * Helper methods in addition to the {@link IsoDateTimeParser} class.
8 | */
9 | public class TimestampParser {
10 | /**
11 | * Returns an {@link OSHDBTimestamp} converted with
12 | * {@link IsoDateTimeParser#parseIsoDateTime(String)} using a given {@link String timeString}.
13 | */
14 | public static OSHDBTimestamp toOSHDBTimestamp(String timeString) {
15 | return new OSHDBTimestamp(IsoDateTimeParser.parseIsoDateTime(timeString).toEpochSecond());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/geometry/incomplete/OSHDBGeometryBuilderTestWayIncompleteDataTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.geometry.incomplete;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertTrue;
5 |
6 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
7 | import org.heigit.ohsome.oshdb.util.geometry.OSHDBGeometryBuilder;
8 | import org.heigit.ohsome.oshdb.util.geometry.OSHDBGeometryTest;
9 | import org.heigit.ohsome.oshdb.util.geometry.helpers.TimestampParser;
10 | import org.junit.jupiter.api.Test;
11 | import org.locationtech.jts.geom.Geometry;
12 | import org.locationtech.jts.geom.LineString;
13 |
14 | /**
15 | * Tests the {@link OSHDBGeometryBuilder} class on incomplete ways.
16 | */
17 | class OSHDBGeometryBuilderTestWayIncompleteDataTest extends OSHDBGeometryTest {
18 | private final OSHDBTimestamp timestamp =
19 | TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z");
20 |
21 | OSHDBGeometryBuilderTestWayIncompleteDataTest() {
22 | super("./src/test/resources/incomplete-osm/way.osm");
23 | }
24 |
25 | @Test
26 | void testOneOfNodesNotExistent() {
27 | // Way with four node references, one node missing
28 | Geometry result = buildGeometry(ways(100L, 0), timestamp);
29 | assertTrue(result instanceof LineString);
30 | assertTrue(result.isValid());
31 | assertTrue(result.getCoordinates().length >= 3);
32 | }
33 |
34 | @Test
35 | void testWayAreaYes() {
36 | // Way with four nodes, area = yes
37 | Geometry result = buildGeometry(ways(101L, 0), timestamp);
38 | assertTrue(result instanceof LineString);
39 | assertTrue(result.isValid());
40 | assertTrue(result.getCoordinates().length >= 3);
41 | }
42 |
43 | @Test
44 | void testAllNodesNotExistent() {
45 | // Way with two nodes, both missing
46 | Geometry result = buildGeometry(ways(102L, 0), timestamp);
47 | assertEquals(0, result.getCoordinates().length);
48 | assertTrue(result.isValid());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/geometry/relations/OSHDBGeometryBuilderMultipolygonInvalidInnersTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.geometry.relations;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertTrue;
4 |
5 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
6 | import org.heigit.ohsome.oshdb.util.geometry.OSHDBGeometryBuilder;
7 | import org.heigit.ohsome.oshdb.util.geometry.OSHDBGeometryTest;
8 | import org.heigit.ohsome.oshdb.util.geometry.helpers.TimestampParser;
9 | import org.junit.jupiter.api.Test;
10 | import org.locationtech.jts.geom.Geometry;
11 | import org.locationtech.jts.geom.Polygon;
12 |
13 | /**
14 | * Tests the {@link OSHDBGeometryBuilder} class for the special case of multipolygons with
15 | * invalid inner rings.
16 | */
17 | class OSHDBGeometryBuilderMultipolygonInvalidInnersTest extends OSHDBGeometryTest {
18 | private final OSHDBTimestamp timestamp =
19 | TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z");
20 |
21 | OSHDBGeometryBuilderMultipolygonInvalidInnersTest() {
22 | super("./src/test/resources/relations/invalid-inner-rings.osm");
23 | }
24 |
25 | @Test
26 | void testDuplicateInnerRings() {
27 | // data has invalid (duplicate) inner rings
28 | Geometry result = buildGeometry(relations(1L, 0), timestamp);
29 | assertTrue(result instanceof Polygon);
30 | }
31 |
32 | @Test
33 | void testTouchingIncompleteInnerRings() {
34 | // data has invalid (duplicate) inner rings
35 | Geometry result = buildGeometry(relations(2L, 0), timestamp);
36 | assertTrue(result instanceof Polygon);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/geometry/relations/OSHDBGeometryBuilderMultipolygonInvalidOutersTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.geometry.relations;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertTrue;
4 |
5 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
6 | import org.heigit.ohsome.oshdb.util.geometry.OSHDBGeometryBuilder;
7 | import org.heigit.ohsome.oshdb.util.geometry.OSHDBGeometryTest;
8 | import org.heigit.ohsome.oshdb.util.geometry.helpers.TimestampParser;
9 | import org.junit.jupiter.api.Test;
10 | import org.locationtech.jts.geom.Geometry;
11 | import org.locationtech.jts.geom.MultiPolygon;
12 |
13 | /**
14 | * Tests the {@link OSHDBGeometryBuilder} class for the special case of multipolygons with
15 | * invalid outer rings.
16 | */
17 | class OSHDBGeometryBuilderMultipolygonInvalidOutersTest extends OSHDBGeometryTest {
18 | private final OSHDBTimestamp timestamp =
19 | TimestampParser.toOSHDBTimestamp("2014-01-01T00:00:00Z");
20 |
21 | OSHDBGeometryBuilderMultipolygonInvalidOutersTest() {
22 | super("./src/test/resources/relations/invalid-outer-ring.osm");
23 | }
24 |
25 | @Test
26 | void test() {
27 | // data has invalid (self-intersecting) outer ring
28 | Geometry result = buildGeometry(relations(1L, 0), timestamp);
29 | assertTrue(result instanceof MultiPolygon);
30 | }
31 | }
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/tagtranslator/CachedTagTranslatorTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.tagtranslator;
2 |
3 | /**
4 | * Tests the {@link CachedTagTranslator} class.
5 | */
6 | class CachedTagTranslatorTest extends AbstractTagTranslatorTest {
7 |
8 | @Override
9 | TagTranslator getTranslator() {
10 | return new CachedTagTranslator(new JdbcTagTranslator(source), 1000, 1000);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/tagtranslator/JdbcTagTranslatorTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.tagtranslator;
2 |
3 | /**
4 | * Tests the {@link JdbcTagTranslator} class.
5 | */
6 | class JdbcTagTranslatorTest extends AbstractTagTranslatorTest {
7 |
8 | @Override
9 | TagTranslator getTranslator() {
10 | return new JdbcTagTranslator(source);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/time/OSHDBTimestampIntervalTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.time;
2 |
3 | import static java.lang.Integer.signum;
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
5 |
6 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
7 | import org.junit.jupiter.api.Test;
8 |
9 | /**
10 | * Test Suite for {@code OSHDBTimestampInterval}.
11 | */
12 | class OSHDBTimestampIntervalTest {
13 |
14 | /**
15 | * Test for the contract of {@code Comparable.compareTo}.
16 | */
17 | @Test
18 | void testCompareTo() {
19 | var x = new OSHDBTimestampInterval(new OSHDBTimestamp(0), new OSHDBTimestamp(1));
20 | var y = new OSHDBTimestampInterval(new OSHDBTimestamp(0), new OSHDBTimestamp(2));
21 |
22 | assertEquals(-1, signum(x.compareTo(y)));
23 | assertEquals(1, signum(y.compareTo(x)));
24 |
25 | // The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y.
26 | // This implies that x.compareTo(y) must throw an exception iff y.compareTo(x)
27 | // throws an exception.
28 | assertEquals(true, signum(x.compareTo(y)) == signum(y.compareTo(x)) * -1);
29 |
30 | // The implementor must also ensure that the relation is transitive:
31 | // (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.
32 | var z = new OSHDBTimestampInterval(new OSHDBTimestamp(1), new OSHDBTimestamp(2));
33 | assertEquals(-1, signum(y.compareTo(z)));
34 | assertEquals(-1, signum(x.compareTo(z)));
35 |
36 | // Finally, the implementor must ensure that x.compareTo(y)==0 implies that
37 | // sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.
38 | y = new OSHDBTimestampInterval(new OSHDBTimestamp(0), new OSHDBTimestamp(1));
39 | assertEquals(0, x.compareTo(y));
40 | assertEquals(true, signum(x.compareTo(z)) == signum(y.compareTo(z)));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/xmlreader/MutableOSMEntity.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.xmlreader;
2 |
3 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
4 |
5 | /**
6 | * A mutable OSM entity, specifically for use in {@link OSMXmlReader}.
7 | */
8 | public class MutableOSMEntity {
9 |
10 | private long id;
11 |
12 | private int version;
13 | private boolean visible;
14 | private long timestamp;
15 | private long changeset;
16 | private int userId;
17 | private int[] tags;
18 |
19 | public long getId() {
20 | return id;
21 | }
22 |
23 | public void setId(long id) {
24 | this.id = id;
25 | }
26 |
27 | public int getVersion() {
28 | return version;
29 | }
30 |
31 | public boolean isVisible() {
32 | return visible;
33 | }
34 |
35 | public void isVisible(boolean visible) {
36 | this.visible = visible;
37 | }
38 |
39 |
40 | public void setVersion(int version) {
41 | this.version = version;
42 | }
43 |
44 | public long getEpochSecond() {
45 | return timestamp;
46 | }
47 |
48 |
49 | public void setTimestamp(OSHDBTimestamp timestamp) {
50 | this.timestamp = timestamp.getEpochSecond();
51 | }
52 |
53 | public void setTimestamp(long timestamp) {
54 | this.timestamp = timestamp;
55 | }
56 |
57 | public long getChangeset() {
58 | return changeset;
59 | }
60 |
61 | public void setChangeset(long changeset) {
62 | this.changeset = changeset;
63 | }
64 |
65 | public int getUserId() {
66 | return userId;
67 | }
68 |
69 | public void setUserId(int userId) {
70 | this.userId = userId;
71 | }
72 |
73 | public int[] getTags() {
74 | return tags;
75 | }
76 |
77 | public void setTags(int[] tags) {
78 | this.tags = tags;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/xmlreader/MutableOSMNode.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.xmlreader;
2 |
3 | /**
4 | * A mutable OSM node, specifically for use in {@link OSMXmlReader}.
5 | */
6 | public class MutableOSMNode extends MutableOSMEntity {
7 | private int longitude;
8 | private int latitude;
9 |
10 | public int getLon() {
11 | return longitude;
12 | }
13 |
14 | public void setLon(int longitude) {
15 | this.longitude = longitude;
16 | }
17 |
18 | public int getLat() {
19 | return latitude;
20 | }
21 |
22 | public void setLat(int latitude) {
23 | this.latitude = latitude;
24 | }
25 |
26 | public void setExtension(int longitude, int latitude) {
27 | this.longitude = longitude;
28 | this.latitude = latitude;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/xmlreader/MutableOSMRelation.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.xmlreader;
2 |
3 | import org.heigit.ohsome.oshdb.osm.OSMMember;
4 |
5 | /**
6 | * A mutable OSM relation, specifically for use in {@link OSMXmlReader}.
7 | */
8 | public class MutableOSMRelation extends MutableOSMEntity {
9 | private OSMMember[] members;
10 |
11 | public OSMMember[] getMembers() {
12 | return members;
13 | }
14 |
15 | public void setExtension(OSMMember[] members) {
16 | this.members = members;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/xmlreader/MutableOSMWay.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.xmlreader;
2 |
3 | import org.heigit.ohsome.oshdb.osm.OSMMember;
4 |
5 | /**
6 | * A mutable OSM way, specifically for use in {@link OSMXmlReader}.
7 | */
8 | public class MutableOSMWay extends MutableOSMEntity {
9 | private OSMMember[] members;
10 |
11 | public OSMMember[] getMembers() {
12 | return members;
13 | }
14 |
15 | public void setExtension(OSMMember[] members) {
16 | this.members = members;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/resources/different-timestamps/not-osm-type-specific.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/resources/geometryBuilder.osh:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/resources/incomplete-osm/way.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | # Root logger option
2 | log4j.rootLogger=WARN, stderr
3 |
4 | # Redirect log messages to console
5 | log4j.appender.stderr=org.apache.log4j.ConsoleAppender
6 | log4j.appender.stderr.Target=System.err
7 | log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
8 | log4j.appender.stderr.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
9 |
--------------------------------------------------------------------------------
/oshdb-util/src/test/resources/osm-testdata/readme.md.txt:
--------------------------------------------------------------------------------
1 | Test data from [osmcode/osm-testdata](https://github.com/osmcode/osm-testdata). Downloaded on 2018-03-20.
--------------------------------------------------------------------------------
/oshdb-util/src/test/resources/relations/invalid-inner-rings.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/oshdb/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.heigit.ohsome
7 | oshdb-parent
8 | 1.3.0-SNAPSHOT
9 |
10 |
11 | oshdb
12 | OSHDB core
13 | The central data model of the OpenStreetMap History Database.
14 |
15 |
16 | 3.3.0
17 |
18 |
19 |
20 |
21 | org.slf4j
22 | slf4j-api
23 |
24 |
25 |
26 | com.google.guava
27 | guava
28 | ${guava.version}
29 |
30 |
31 |
32 | org.slf4j
33 | slf4j-log4j12
34 | test
35 |
36 |
37 |
38 | com.h2database
39 | h2
40 | ${h2.version}
41 | test
42 |
43 |
44 |
45 |
46 |
47 | withDep
48 |
49 |
50 |
51 | org.apache.maven.plugins
52 | maven-assembly-plugin
53 | ${mavenassembly.version}
54 |
55 |
56 | jar-with-dependencies
57 |
58 |
59 |
60 |
61 | make-assembly
62 | package
63 |
64 | single
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/OSHDB.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb;
2 |
3 | public class OSHDB {
4 | private OSHDB() {}
5 |
6 | public static final int MAXZOOM = 14;
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/OSHDBRole.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb;
2 |
3 | import java.io.Serializable;
4 | import java.util.Objects;
5 | import java.util.stream.IntStream;
6 |
7 | /**
8 | * Class for representing the role of a relation member.
9 | *
10 | */
11 | public class OSHDBRole implements Serializable {
12 | /**
13 | * The empty OSHDBRole.
14 | */
15 | public static final OSHDBRole EMPTY = new OSHDBRole(-1);
16 |
17 | private static final int CACHE_SIZE = 256;
18 | private static final OSHDBRole[] cache = IntStream.range(0, CACHE_SIZE)
19 | .mapToObj(OSHDBRole::new)
20 | .toArray(OSHDBRole[]::new);
21 |
22 | /**
23 | * Returns an {@code OSHDBRole} instance representing the specified
24 | * {@code role id} value.
25 | *
26 | * @param id integer id of the OSHDBRole.
27 | * @return OSHDBRole instance.
28 | */
29 | public static OSHDBRole of(int id) {
30 | if (id == -1) {
31 | return EMPTY;
32 | }
33 | if (id >= 0 && id < CACHE_SIZE) {
34 | return cache[id];
35 | }
36 | return new OSHDBRole(id);
37 | }
38 |
39 | private static final long serialVersionUID = 1L;
40 | private int role;
41 |
42 | private OSHDBRole(int role) {
43 | this.role = role;
44 | }
45 |
46 | /**
47 | * Return integer id representation for this OSHDBRole object.
48 | *
49 | * @return integer id
50 | */
51 | public int getId() {
52 | return this.role;
53 | }
54 |
55 | @Override
56 | public int hashCode() {
57 | return Objects.hash(role);
58 | }
59 |
60 | @Override
61 | public boolean equals(Object obj) {
62 | if (this == obj) {
63 | return true;
64 | }
65 | if (!(obj instanceof OSHDBRole)) {
66 | return false;
67 | }
68 | OSHDBRole other = (OSHDBRole) obj;
69 | return role == other.role;
70 | }
71 |
72 | @Override
73 | public String toString() {
74 | return Integer.toString(this.role);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/OSHDBTag.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb;
2 |
3 | import java.io.Serializable;
4 | import java.util.Comparator;
5 | import java.util.Objects;
6 |
7 | /**
8 | * Key/Value id base OSM Tag class.
9 | *
10 | */
11 | public class OSHDBTag implements Comparable, Serializable {
12 | /**
13 | * Order by keyId/valueId, default Comparator for OSHDBTag.
14 | */
15 | public static final Comparator ORDER_BY_ID = Comparator
16 | .comparingInt(OSHDBTag::getKey)
17 | .thenComparingInt(OSHDBTag::getValue);
18 |
19 | private static final long serialVersionUID = 1L;
20 | private final int key;
21 | private final int value;
22 |
23 | public OSHDBTag(int key, int value) {
24 | this.key = key;
25 | this.value = value;
26 | }
27 |
28 | public int getKey() {
29 | return this.key;
30 | }
31 |
32 | public int getValue() {
33 | return this.value;
34 | }
35 |
36 | @Override
37 | public int compareTo(OSHDBTag o) {
38 | return ORDER_BY_ID.compare(this, o);
39 | }
40 |
41 | @Override
42 | public boolean equals(Object o) {
43 | return o instanceof OSHDBTag
44 | && ((OSHDBTag) o).key == this.key && ((OSHDBTag) o).value == this.value;
45 | }
46 |
47 | @Override
48 | public int hashCode() {
49 | return Objects.hash(this.key, this.value);
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return key + "=" + value;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/OSHDBTemporal.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb;
2 |
3 | import java.time.Instant;
4 | import java.time.ZoneOffset;
5 | import java.time.ZonedDateTime;
6 | import java.time.format.DateTimeFormatter;
7 |
8 | /**
9 | * Interface for objects which are associated to a single timestamp.
10 | */
11 | public interface OSHDBTemporal {
12 |
13 | long getEpochSecond();
14 |
15 | default boolean isBefore(OSHDBTemporal other) {
16 | return getEpochSecond() < other.getEpochSecond();
17 | }
18 |
19 | default boolean isAfter(OSHDBTemporal other) {
20 | return getEpochSecond() > other.getEpochSecond();
21 | }
22 |
23 | static int compare(OSHDBTemporal a, OSHDBTemporal b) {
24 | return Long.compare(a.getEpochSecond(), b.getEpochSecond());
25 | }
26 |
27 | /**
28 | * Converts the given {@code OSHDBTemporal} to an iso-date-time string.
29 | *
30 | * @param temporal The {@code OSHDBTemporal} which should converted.
31 | * @return the iso-date-time string for the {@code OSHDBTemporal}
32 | */
33 | static String toIsoDateTime(OSHDBTemporal temporal) {
34 | ZonedDateTime zdt =
35 | ZonedDateTime.ofInstant(Instant.ofEpochSecond(temporal.getEpochSecond()), ZoneOffset.UTC);
36 | return zdt.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/OSHDBTimestamp.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | public class OSHDBTimestamp implements OSHDBTemporal, Comparable, Serializable {
7 | private static final long serialVersionUID = 1L;
8 | private final long epochSecond;
9 |
10 | public OSHDBTimestamp(OSHDBTemporal temporal) {
11 | this(temporal.getEpochSecond());
12 | }
13 |
14 | public OSHDBTimestamp(long tstamp) {
15 | this.epochSecond = tstamp;
16 | }
17 |
18 | public OSHDBTimestamp(Date tstamp) {
19 | this(tstamp.getTime() / 1000);
20 | }
21 |
22 | @Override
23 | public int compareTo(OSHDBTimestamp other) {
24 | return Long.compare(this.epochSecond, other.epochSecond);
25 | }
26 |
27 | @Override
28 | public boolean equals(Object other) {
29 | if (other instanceof OSHDBTimestamp) {
30 | return this.epochSecond == ((OSHDBTimestamp) other).epochSecond;
31 | } else {
32 | return super.equals(other);
33 | }
34 | }
35 |
36 | @Override
37 | public int hashCode() {
38 | return Long.hashCode(this.epochSecond);
39 | }
40 |
41 | public Date toDate() {
42 | return new Date(this.epochSecond * 1000);
43 | }
44 |
45 | @Override
46 | public long getEpochSecond() {
47 | return this.epochSecond;
48 | }
49 |
50 | @Override
51 | public String toString() {
52 | return OSHDBTemporal.toIsoDateTime(this);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/grid/GridOSHEntity.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.grid;
2 |
3 | import java.io.Serializable;
4 | import java.util.Locale;
5 | import org.heigit.ohsome.oshdb.OSHDBBoundingBox;
6 | import org.heigit.ohsome.oshdb.index.XYGrid;
7 | import org.heigit.ohsome.oshdb.osh.OSHEntity;
8 | import org.heigit.ohsome.oshdb.util.CellId;
9 |
10 | public abstract class GridOSHEntity
11 | implements Serializable {
12 |
13 | private static final long serialVersionUID = 1L;
14 | protected final long id;
15 | protected final int level;
16 |
17 | protected final long baseTimestamp;
18 |
19 | protected final long baseLongitude;
20 | protected final long baseLatitude;
21 |
22 | protected final long baseId;
23 |
24 | protected final int[] index;
25 | protected final byte[] data;
26 |
27 | /**
28 | * Base constructor {@code GridOSHEntity}.
29 | */
30 | protected GridOSHEntity(final long id, final int level, final long baseId,
31 | final long baseTimestamp, final int baseLongitude, final int baseLatitude, final int[] index,
32 | final byte[] data) {
33 |
34 | this.id = id;
35 | this.level = level;
36 | this.baseTimestamp = baseTimestamp;
37 | this.baseLongitude = baseLongitude;
38 | this.baseLatitude = baseLatitude;
39 | this.baseId = baseId;
40 |
41 | this.index = index;
42 | this.data = data;
43 | }
44 |
45 | public long getId() {
46 | return id;
47 | }
48 |
49 | public int getLevel() {
50 | return level;
51 | }
52 |
53 | public abstract Iterable extends OSHEntity> getEntities();
54 |
55 | @Override
56 | public String toString() {
57 | if (id >= 0) {
58 | OSHDBBoundingBox bbox = XYGrid.getBoundingBox(new CellId(level, id));
59 | return String.format(Locale.ENGLISH, "ID:%d Level:%d %s", id, level, bbox);
60 | } else {
61 | return String.format(Locale.ENGLISH, "ID:%d Level:%d", id, level);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/grid/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This package holds the top-level abstraction of the OSM-Data, grouping it in cells.
3 | */
4 | package org.heigit.ohsome.oshdb.grid;
5 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/index/Grid.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.index;
2 |
3 | public interface Grid {
4 | long getId(double longitude, double latitude);
5 | }
6 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/index/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Definitions for Grid-Cells.
3 | */
4 | package org.heigit.ohsome.oshdb.index;
5 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osh/OSHEntity.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osh;
2 |
3 | import java.util.Collections;
4 | import java.util.List;
5 | import org.heigit.ohsome.oshdb.OSHDBBoundable;
6 | import org.heigit.ohsome.oshdb.osm.OSMEntity;
7 | import org.heigit.ohsome.oshdb.osm.OSMType;
8 | import org.heigit.ohsome.oshdb.util.OSHDBTagKey;
9 |
10 | public interface OSHEntity {
11 |
12 | long getId();
13 |
14 | OSMType getType();
15 |
16 | OSHDBBoundable getBoundable();
17 |
18 | Iterable getTagKeys();
19 |
20 | boolean hasTagKey(OSHDBTagKey tag);
21 |
22 | boolean hasTagKey(int key);
23 |
24 | Iterable extends OSMEntity> getVersions();
25 |
26 | default List getNodes() {
27 | return Collections.emptyList();
28 | }
29 |
30 | default List getWays() {
31 | return Collections.emptyList();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osh/OSHNode.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osh;
2 |
3 | import org.heigit.ohsome.oshdb.osm.OSMNode;
4 | import org.heigit.ohsome.oshdb.osm.OSMType;
5 |
6 | public interface OSHNode extends OSHEntity {
7 |
8 | @Override
9 | default OSMType getType() {
10 | return OSMType.NODE;
11 | }
12 |
13 | @Override
14 | Iterable getVersions();
15 | }
16 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osh/OSHRelation.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osh;
2 |
3 | import org.heigit.ohsome.oshdb.osm.OSMRelation;
4 | import org.heigit.ohsome.oshdb.osm.OSMType;
5 |
6 | public interface OSHRelation extends OSHEntity {
7 |
8 | @Override
9 | default OSMType getType() {
10 | return OSMType.RELATION;
11 | }
12 |
13 | @Override
14 | Iterable getVersions();
15 | }
16 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osh/OSHWay.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osh;
2 |
3 | import org.heigit.ohsome.oshdb.osm.OSMType;
4 | import org.heigit.ohsome.oshdb.osm.OSMWay;
5 |
6 | public interface OSHWay extends OSHEntity {
7 |
8 | @Override
9 | default OSMType getType() {
10 | return OSMType.WAY;
11 | }
12 |
13 | @Override
14 | Iterable getVersions();
15 | }
16 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osh/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * OSHDB-Representation of OSM-Objects over time.
3 | */
4 | package org.heigit.ohsome.oshdb.osh;
5 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osm/OSMCoordinates.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osm;
2 |
3 | /**
4 | * Helper class for converting double precision floating point lon/lat to
5 | * osm-coordinate fix presision 7 decimal integer system.
6 | */
7 | public class OSMCoordinates {
8 |
9 | // osm only stores 7 decimals for each coordinate
10 | public static final double GEOM_PRECISION_TO_LONG = 1E7;
11 | public static final double GEOM_PRECISION = 1.0 / GEOM_PRECISION_TO_LONG;
12 |
13 | public static int toOSM(double value) {
14 | return (int) (value * GEOM_PRECISION_TO_LONG);
15 | }
16 |
17 | public static double toWgs84(int value) {
18 | return value * GEOM_PRECISION;
19 | }
20 |
21 | public static boolean validLon(int lon) {
22 | return Math.abs(lon) < 180_0000000;
23 | }
24 |
25 | public static boolean validLat(int lat) {
26 | return Math.abs(lat) < 90_0000000;
27 | }
28 |
29 | private OSMCoordinates() {}
30 | }
31 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osm/OSMEntity.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osm;
2 |
3 | import java.io.Serializable;
4 | import org.heigit.ohsome.oshdb.OSHDBTags;
5 | import org.heigit.ohsome.oshdb.OSHDBTemporal;
6 |
7 | /**
8 | * Base interface for single version osm-elements.
9 | *
10 | */
11 | public interface OSMEntity extends OSHDBTemporal, Serializable {
12 |
13 |
14 | OSMType getType();
15 |
16 | long getId();
17 |
18 | int getVersion();
19 |
20 | long getChangesetId();
21 |
22 | int getUserId();
23 |
24 | boolean isVisible();
25 |
26 | /**
27 | * Returns a "view" of the current osm tags.
28 | */
29 | OSHDBTags getTags();
30 | }
31 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osm/OSMMember.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osm;
2 |
3 | import java.io.Serializable;
4 | import java.util.Objects;
5 | import org.heigit.ohsome.oshdb.OSHDBRole;
6 | import org.heigit.ohsome.oshdb.osh.OSHEntity;
7 |
8 | /**
9 | * Holds an OSH-Object that belongs to the Way or Relation this Member is contained in.
10 | */
11 | public class OSMMember implements Serializable {
12 | private final long id;
13 | private final OSMType type;
14 | private final OSHDBRole role;
15 | private final transient OSHEntity entity;
16 |
17 | public OSMMember(final long id, final OSMType type, final int roleId) {
18 | this(id, type, roleId, null);
19 | }
20 |
21 | /**
22 | * Create a new {@code OSMMember} instance.
23 | */
24 | public OSMMember(final long id, final OSMType type, final int roleId,
25 | OSHEntity entity) {
26 | this.id = id;
27 | this.type = type;
28 | this.role = OSHDBRole.of(roleId);
29 | this.entity = entity;
30 | }
31 |
32 | public long getId() {
33 | return id;
34 | }
35 |
36 | public OSMType getType() {
37 | return type;
38 | }
39 |
40 | public OSHDBRole getRole() {
41 | return role;
42 | }
43 |
44 | public OSHEntity getEntity() {
45 | return entity;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return String.format("T:%s ID:%d R:%d", type, id, role.getId());
51 | }
52 |
53 | @Override
54 | public int hashCode() {
55 | return Objects.hash(type, id, role.getId());
56 | }
57 |
58 | @Override
59 | public boolean equals(Object obj) {
60 | if (this == obj) {
61 | return true;
62 | }
63 | if (!(obj instanceof OSMMember)) {
64 | return false;
65 | }
66 | OSMMember other = (OSMMember) obj;
67 | return type == other.type && id == other.id && role.equals(other.role);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osm/OSMNode.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osm;
2 |
3 | /**
4 | * Interface for single version osm-element node.
5 | *
6 | */
7 | public interface OSMNode extends OSMEntity {
8 |
9 | @Override
10 | default OSMType getType() {
11 | return OSMType.NODE;
12 | }
13 |
14 | public double getLongitude();
15 |
16 | public double getLatitude();
17 |
18 | public int getLon();
19 |
20 | public int getLat();
21 | }
22 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osm/OSMRelation.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osm;
2 |
3 | import java.util.function.Predicate;
4 | import java.util.stream.Stream;
5 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
6 |
7 | /**
8 | * Interface for single version osm-element relation.
9 | */
10 | public interface OSMRelation extends OSMEntity {
11 |
12 | @Override
13 | default OSMType getType() {
14 | return OSMType.RELATION;
15 | }
16 |
17 | /**
18 | * Returns the members for this current version.
19 | *
20 | * @return OSMMember for this version
21 | */
22 | OSMMember[] getMembers();
23 |
24 | /**
25 | * Returns a stream of all member entities (OSM) for the given timestamp.
26 | *
27 | * @param timestamp the timestamp for the osm member entity
28 | * @param memberFilter apply filter to Stream of members
29 | * @return stream of member entities (OSM)
30 | */
31 | Stream getMemberEntities(OSHDBTimestamp timestamp, Predicate memberFilter);
32 |
33 | /**
34 | * Returns a stream of all member entities (OSM) for the given timestamp.
35 | *
36 | * @param timestamp the timestamp for the osm member entity
37 | * @return stream of member entities (OSM)
38 | */
39 | Stream getMemberEntities(OSHDBTimestamp timestamp);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osm/OSMType.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osm;
2 |
3 | public enum OSMType {
4 | NODE(0),
5 | WAY(1),
6 | RELATION(2);
7 |
8 | private final int value;
9 |
10 | OSMType(final int value) {
11 | this.value = value;
12 | }
13 |
14 | /**
15 | * Returns an {@code OSMType} instance represented by the given integer value (0-2), or throws an
16 | * exception otherwise.
17 | */
18 | public static OSMType fromInt(final int value) {
19 | switch (value) {
20 | case 0:
21 | return NODE;
22 | case 1:
23 | return WAY;
24 | case 2:
25 | return RELATION;
26 | default: {
27 | final String msg =
28 | String.format("Unknown OSMType! Should be between 0 and 2, got [%d]", value);
29 | throw new IllegalArgumentException(msg);
30 | }
31 | }
32 | }
33 |
34 | public final int intValue() {
35 | return this.value;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return name().toLowerCase();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osm/OSMWay.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osm;
2 |
3 | import java.util.stream.Stream;
4 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
5 |
6 | /**
7 | * Interface for single version osm-element way.
8 | */
9 | public interface OSMWay extends OSMEntity {
10 |
11 | @Override
12 | default OSMType getType() {
13 | return OSMType.WAY;
14 | }
15 |
16 | /**
17 | * Returns the members for this current version.
18 | *
19 | * @return OSMMember for this version
20 | */
21 | OSMMember[] getMembers();
22 |
23 | /**
24 | * Returns a stream of all member entities (OSM) for the given timestamp.
25 | *
26 | * @param timestamp the timestamp for the osm member entity
27 | * @return stream of member entities (OSM)
28 | */
29 | Stream getMemberEntities(OSHDBTimestamp timestamp);
30 | }
31 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/osm/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * OSHDB-Representation of OSM-Data.
3 | */
4 | package org.heigit.ohsome.oshdb.osm;
5 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Core of the OSHDB-Project. It contains the three level of data-abstraction.
3 | */
4 | package org.heigit.ohsome.oshdb;
5 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/util/OSHDBTagKey.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util;
2 |
3 | import java.io.Serializable;
4 |
5 | public class OSHDBTagKey implements Serializable {
6 | private static final long serialVersionUID = 1L;
7 | private int key;
8 |
9 | public OSHDBTagKey(int key) {
10 | this.key = key;
11 | }
12 |
13 | public int toInt() {
14 | return this.key;
15 | }
16 |
17 | public boolean isPresentInKeytables() {
18 | return this.key >= 0;
19 | }
20 |
21 | @Override
22 | public boolean equals(Object o) {
23 | return o instanceof OSHDBTagKey && ((OSHDBTagKey) o).key == this.key;
24 | }
25 |
26 | @Override
27 | public int hashCode() {
28 | return this.key;
29 | }
30 |
31 | @Override
32 | public String toString() {
33 | return Integer.toString(this.key);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/util/bytearray/OSHDBByteArrayOutputStream.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util.bytearray;
2 |
3 | import java.io.ByteArrayOutputStream;
4 |
5 | public class OSHDBByteArrayOutputStream extends ByteArrayOutputStream {
6 |
7 | public OSHDBByteArrayOutputStream(int size) {
8 | super(size);
9 | }
10 |
11 | public byte[] array() {
12 | return buf;
13 | }
14 |
15 | public int length() {
16 | return count;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/oshdb/src/main/java/org/heigit/ohsome/oshdb/util/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utilities and helpers for a comfortable, fast and easy (raw) data access.
3 | */
4 | package org.heigit.ohsome.oshdb.util;
5 |
--------------------------------------------------------------------------------
/oshdb/src/test/java/org/heigit/ohsome/oshdb/OSHDBRoleTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
5 |
6 | import org.junit.jupiter.api.Test;
7 | import org.junit.jupiter.params.ParameterizedTest;
8 | import org.junit.jupiter.params.provider.ValueSource;
9 |
10 | class OSHDBRoleTest {
11 |
12 | @Test
13 | void testEmptyRole() {
14 | var empty = OSHDBRole.of(-1);
15 | assertEquals(-1, empty.getId());
16 | assertEquals(OSHDBRole.EMPTY, empty);
17 | }
18 |
19 | @ParameterizedTest
20 | @ValueSource(ints = {-2, -1, 0, 1, 3, 5, 15, 256, 525, Integer.MAX_VALUE})
21 | void testHashCodeAndEquals(int id) {
22 | var expected = OSHDBRole.of(id);
23 | var role = OSHDBRole.of(id);
24 | assertEquals(role, role);
25 | assertEquals(expected, role);
26 | assertEquals(expected.hashCode(), role.hashCode());
27 |
28 | var unexpect = OSHDBRole.of(2);
29 | assertNotEquals(unexpect, role);
30 | }
31 |
32 | @Test
33 | void testNotEqualsOtherType() {
34 | var unexpect = OSHDBRole.of(2);
35 | assertNotEquals(unexpect, unexpect.toString());
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/oshdb/src/test/java/org/heigit/ohsome/oshdb/OSHDBTagTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
6 |
7 | import org.junit.jupiter.api.Test;
8 |
9 | class OSHDBTagTest {
10 |
11 | @Test
12 | void test() {
13 | var tag = new OSHDBTag(10, 20);
14 | assertEquals(10, tag.getKey());
15 | assertEquals(20, tag.getValue());
16 | }
17 |
18 | @Test
19 | void testComparable() {
20 | var tag = new OSHDBTag(10, 10);
21 |
22 | assertEquals(0, tag.compareTo(new OSHDBTag(10, 10)));
23 | assertTrue(tag.compareTo(new OSHDBTag(5, 10)) > 0);
24 | assertTrue(tag.compareTo(new OSHDBTag(10, 5)) > 0);
25 | assertTrue(tag.compareTo(new OSHDBTag(20, 10)) < 0);
26 | assertTrue(tag.compareTo(new OSHDBTag(10, 15)) < 0);
27 | }
28 |
29 | @Test
30 | void testHashEqual() {
31 | var tag = new OSHDBTag(10, 10);
32 |
33 | assertEquals(tag, tag);
34 | assertEquals(tag, new OSHDBTag(10, 10));
35 | assertEquals(tag.hashCode(), new OSHDBTag(10, 10).hashCode());
36 |
37 | assertNotEquals(tag, new OSHDBTag(10, 20));
38 | assertNotEquals(tag, new OSHDBTag(20, 10));
39 |
40 | assertNotEquals(tag, tag.toString());;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/oshdb/src/test/java/org/heigit/ohsome/oshdb/grid/GridOSHNodesTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.grid;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 |
5 | import com.google.common.collect.Iterables;
6 | import java.io.IOException;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 | import org.heigit.ohsome.oshdb.impl.osh.OSHNodeImpl;
10 | import org.heigit.ohsome.oshdb.osh.OSHNode;
11 | import org.heigit.ohsome.oshdb.osm.OSM;
12 | import org.heigit.ohsome.oshdb.osm.OSMNode;
13 | import org.junit.jupiter.api.Test;
14 |
15 | class GridOSHNodesTest {
16 |
17 | @Test
18 | void testRebaseEntities() throws IOException {
19 | List hosmNodes = new ArrayList<>();
20 | for (int i = 0; i < 3; i++) {
21 | List versions = new ArrayList<>();
22 | versions.add(OSM.node(123L + 10 * i, 1, 123001L + 10 * i, 0L, 123, new int[] {},
23 | 86809727 - 1000000 * i, 494094984 - 1000000 * i));
24 | versions.add(OSM.node(123L + 10 * i, 2, 123002L + 10 * i, 0L, 123, new int[] {},
25 | 86809727 - 1000000 * i, 494094984 - 1000000 * i));
26 | hosmNodes.add(OSHNodeImpl.build(versions));
27 | }
28 |
29 | GridOSHNodes instance = GridOSHNodes.rebase(2, 2, 100, 100000L, 86000000, 490000000, hosmNodes);
30 | var entities = instance.getEntities();
31 | assertEquals(hosmNodes.size(), Iterables.size(entities));
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/oshdb/src/test/java/org/heigit/ohsome/oshdb/grid/GridOSHWaysTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.grid;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 |
5 | import com.google.common.collect.Iterables;
6 | import java.io.IOException;
7 | import java.util.ArrayList;
8 | import java.util.Arrays;
9 | import java.util.List;
10 | import org.heigit.ohsome.oshdb.impl.osh.OSHNodeImpl;
11 | import org.heigit.ohsome.oshdb.impl.osh.OSHWayImpl;
12 | import org.heigit.ohsome.oshdb.osh.OSHNode;
13 | import org.heigit.ohsome.oshdb.osh.OSHWay;
14 | import org.heigit.ohsome.oshdb.osm.OSM;
15 | import org.heigit.ohsome.oshdb.osm.OSMMember;
16 | import org.heigit.ohsome.oshdb.osm.OSMNode;
17 | import org.heigit.ohsome.oshdb.osm.OSMType;
18 | import org.heigit.ohsome.oshdb.osm.OSMWay;
19 | import org.junit.jupiter.api.Test;
20 |
21 | class GridOSHWaysTest {
22 |
23 | static OSHNode buildOSHNode(List versions) {
24 | return OSHNodeImpl.build(versions);
25 | }
26 |
27 | OSHNode node100 = buildOSHNode(
28 | Arrays.asList(OSM.node(100L, 1, 1L, 0L, 123, new int[] {1, 2}, 494094984, 86809727)));
29 | OSHNode node102 = buildOSHNode(
30 | Arrays.asList(OSM.node(102L, 1, 1L, 0L, 123, new int[] {2, 1}, 494094984, 86809727)));
31 | OSHNode node104 = buildOSHNode(
32 | Arrays.asList(OSM.node(104L, 1, 1L, 0L, 123, new int[] {2, 4}, 494094984, 86809727)));
33 |
34 | @Test
35 | void testGrid() throws IOException {
36 | List hosmWays = new ArrayList<>();
37 | for (int i = 0; i < 3; i++) {
38 | List versions = new ArrayList<>();
39 | versions.add(OSM.way(123, 1, 3333L, 4444L, 23, new int[] {1, 1, 2, 1}, new OSMMember[] {
40 | new OSMMember(102, OSMType.NODE, 0), new OSMMember(104, OSMType.NODE, 0)}));
41 | versions.add(OSM.way(123, 3, 3333L, 4444L, 23, new int[] {1, 1, 2, 2}, new OSMMember[] {
42 | new OSMMember(100, OSMType.NODE, 0), new OSMMember(104, OSMType.NODE, 0)}));
43 | hosmWays.add(OSHWayImpl.build(versions, Arrays.asList(node100, node102, node104)));
44 | }
45 |
46 | GridOSHWays instance = GridOSHWays.compact(2, 2, 100, 100000L, 86000000, 490000000, hosmWays);
47 | var entities = instance.getEntities();
48 | assertEquals(hosmWays.size(), Iterables.size(entities));
49 | }
50 | }
--------------------------------------------------------------------------------
/oshdb/src/test/java/org/heigit/ohsome/oshdb/osh/OSHEntityTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.osh;
2 |
3 | import static org.heigit.ohsome.oshdb.osh.OSHNodeTest.buildOSHNode;
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
5 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
6 |
7 | import com.google.common.collect.Lists;
8 | import java.io.IOException;
9 | import java.util.Collections;
10 | import org.heigit.ohsome.oshdb.impl.osh.OSHRelationImpl;
11 | import org.heigit.ohsome.oshdb.osm.OSM;
12 | import org.heigit.ohsome.oshdb.osm.OSMMember;
13 | import org.junit.jupiter.api.Test;
14 |
15 | class OSHEntityTest {
16 |
17 | @Test
18 | void testHashCodeEquals() throws IOException {
19 | var expected = buildOSHNode(
20 | OSM.node(123L, 1, 1L, 0L, 1, new int[0], 0, 0)
21 | );
22 |
23 | var a = buildOSHNode(
24 | OSM.node(123L, 1, 1L, 0L, 1, new int[0], 0, 0)
25 | );
26 |
27 | var b = OSHRelationImpl.build(Lists.newArrayList(
28 | OSM.relation(123L, 1, 3333L, 4444L, 23, new int[0],
29 | new OSMMember[0])), Collections.emptyList(), Collections.emptyList());
30 |
31 | assertEquals(expected.hashCode(), a.hashCode());
32 | assertNotEquals(expected.hashCode(), b.hashCode());
33 |
34 | assertEquals(expected, a);
35 | assertNotEquals(expected, b);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/oshdb/src/test/java/org/heigit/ohsome/oshdb/util/CellIdTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 |
5 | import org.junit.jupiter.api.Test;
6 |
7 | class CellIdTest {
8 |
9 | @Test
10 | void testGetid() {
11 | CellId instance = new CellId(1, 1L);
12 | long expResult = 1L;
13 | long result = instance.getId();
14 | assertEquals(expResult, result);
15 | }
16 |
17 | @Test
18 | void testGetzoomlevel() {
19 | CellId instance = new CellId(1, 1L);
20 | int expResult = 1;
21 | int result = instance.getZoomLevel();
22 | assertEquals(expResult, result);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/oshdb/src/test/java/org/heigit/ohsome/oshdb/util/OSHDBBoundableTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertFalse;
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
6 |
7 | import org.heigit.ohsome.oshdb.OSHDBBoundable;
8 | import org.heigit.ohsome.oshdb.OSHDBBoundingBox;
9 | import org.junit.jupiter.api.Test;
10 |
11 | class OSHDBBoundableTest {
12 | private OSHDBBoundable point = OSHDBBoundingBox.bboxOSMCoordinates(0, 0, 0, 0);
13 | private OSHDBBoundable box = OSHDBBoundingBox.bboxOSMCoordinates(-1, -1, 1, 1);
14 |
15 | @Test
16 | void testPoint() {
17 | assertTrue(point.isPoint());
18 | assertFalse(box.isPoint());
19 | }
20 |
21 | @Test
22 | void testValid() {
23 | assertTrue(point.isValid());
24 | assertTrue(box.isValid());
25 | OSHDBBoundable invalid = OSHDBBoundingBox.bboxOSMCoordinates(1, 1, -1, -1);
26 | assertFalse(invalid.isValid());
27 | }
28 |
29 | @Test
30 | void testCovered() {
31 | assertTrue(point.coveredBy(box));
32 | assertFalse(point.coveredBy(null));
33 | }
34 |
35 | @Test
36 | void testIntersects() {
37 | assertTrue(point.intersects(box));
38 | assertFalse(point.intersects(null));
39 | }
40 |
41 | @Test
42 | void testIntersection() {
43 | OSHDBBoundable box2 = OSHDBBoundingBox.bboxOSMCoordinates(0, 0, 2, 2);
44 | OSHDBBoundable intersection = box2.intersection(box);
45 | assertEquals(0, intersection.getMinLongitude());
46 | assertEquals(0, intersection.getMinLatitude());
47 | assertEquals(1, intersection.getMaxLongitude());
48 | assertEquals(1, intersection.getMaxLatitude());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/oshdb/src/test/java/org/heigit/ohsome/oshdb/util/OSHDBTemporalTest.java:
--------------------------------------------------------------------------------
1 | package org.heigit.ohsome.oshdb.util;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertTrue;
5 |
6 | import org.heigit.ohsome.oshdb.OSHDBTemporal;
7 | import org.heigit.ohsome.oshdb.OSHDBTimestamp;
8 | import org.junit.jupiter.api.Test;
9 |
10 | class OSHDBTemporalTest {
11 | @Test
12 | void testBeforeAfter() {
13 | OSHDBTemporal t1 = new OSHDBTimestamp(0);
14 | OSHDBTemporal t2 = new OSHDBTimestamp(1);
15 | assertTrue(t1.isBefore(t2));
16 | assertTrue(t2.isAfter(t1));
17 | assertEquals(0, OSHDBTemporal.compare(t1, t1));
18 | assertTrue(OSHDBTemporal.compare(t1, t2) < 0);
19 | assertTrue(OSHDBTemporal.compare(t2, t1) > 0);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/oshdb/src/test/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | # Root logger option
2 | log4j.rootLogger=WARN, stderr
3 |
4 | # Redirect log messages to console
5 | log4j.appender.stderr=org.apache.log4j.ConsoleAppender
6 | log4j.appender.stderr.Target=System.err
7 | log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
8 | log4j.appender.stderr.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
9 |
--------------------------------------------------------------------------------
/pipeline_config.groovy:
--------------------------------------------------------------------------------
1 | libraries{
2 | maven
3 | misc
4 | rocketchat
5 | }
--------------------------------------------------------------------------------