Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ Changelog
## 0.8.0-SNAPSHOT (current master)

* fix a bug where contribution-based filters are not applied when used in an and/or operation. ([#409])
* fix a regression in `0.7.0` which prevents queries from being executed on an ignite cluster backend ([#417])

[#409]: https://github.com/GIScience/oshdb/issues/409
[#417]: https://github.com/GIScience/oshdb/pull/417


## 0.7.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class OSHDBBoundingBox implements OSHDBBoundable, Serializable {

/**
* Creates an {@code OSHDBBoundingBox} instance from scaled coordinates.
*
*
* <p>This method is mainly for internal usage.<br>
* OSM stores coordinates with a fixed precision of
* <a href="https://wiki.openstreetmap.org/wiki/Node#Structure">7 decimal
Expand Down
129 changes: 87 additions & 42 deletions oshdb/src/main/java/org/heigit/ohsome/oshdb/index/XYGridTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ public XYGridTree() {
* @param latitude Latitude for the given point
* @return An iterator over the cellIds in all zoomlevel
*/
@SuppressWarnings({"Convert2Lambda", "java:S1604"})
public Iterable<CellId> getIds(long longitude, long latitude) {
return () -> new Iterator<>() {
return new Iterable<>() {
@Override
public Iterator<CellId> iterator() {
return new Iterator<>() {
private int level = -1;

@Override
Expand All @@ -62,6 +66,8 @@ public CellId next() {
return new CellId(gridMap.get(level).getLevel(),
gridMap.get(level).getId(longitude, latitude));
}
};
}
};
}

Expand Down Expand Up @@ -110,51 +116,84 @@ public Iterable<CellId> bbox2CellIds(final OSHDBBoundingBox bbox) {
* @param enlarge {@code true} if the query should include enlarged bboxes
*/
public Iterable<CellId> bbox2CellIds(final OSHDBBoundingBox bbox, final boolean enlarge) {
return () -> new Iterator<>() {
private int level = 0;
private Iterator<IdRange> rows =
gridMap.get(level).bbox2CellIdRanges(bbox, enlarge).iterator();
private IdRange row = rows.next();
private long maxId = row.getEnd();
private long currId = row.getStart() - 1;
return new CellIdIterable(gridMap, bbox, enlarge, maxLevel);
}

@Override
public boolean hasNext() {
if (level < maxLevel) {
return true;
}
if (rows.hasNext()) {
return true;
}
return currId < maxId;
}
private static class CellIdIterable implements Iterable<CellId>, Serializable {
private final Map<Integer, XYGrid> gridMap;
private final OSHDBBoundingBox bbox;
private final boolean enlarge;
private final int maxLevel;

@Override
public CellId next() {
if (currId < maxId) {
currId++;
return new CellId(level, currId);
}
if (rows.hasNext()) {
row = rows.next();
currId = row.getStart();
maxId = row.getEnd();
return new CellId(level, currId);
}
level++;
rows = gridMap.get(level).bbox2CellIdRanges(bbox, enlarge).iterator();
row = rows.next();
currId = row.getStart();
maxId = row.getEnd();
return new CellId(level, currId);
}
};
}
private CellIdIterable(Map<Integer, XYGrid> gridMap, OSHDBBoundingBox bbox, boolean enlarge,
int maxLevel) {
this.gridMap = gridMap;
this.bbox = bbox;
this.enlarge = enlarge;
this.maxLevel = maxLevel;
}

public static class CellIdRange implements Serializable {
@Override
public Iterator<CellId> iterator() {
return new CellIdIterator();
}

@SuppressWarnings("SE_INNER_CLASS")
private class CellIdIterator implements Iterator<CellId> {
private Iterator<IdRange> rows;
private int level;
private IdRange row;
private long maxId;
private long currId;

private static final long serialVersionUID = -8704075537597232890L;

private CellIdIterator() {
this.level = 0;
this.rows = gridMap.get(level).bbox2CellIdRanges(bbox, enlarge).iterator();
this.row = rows.next();
this.maxId = row.getEnd();
this.currId = row.getStart() - 1;
}

@Override
public boolean hasNext() {
if (level < maxLevel) {
return true;
}
if (rows.hasNext()) {
return true;
}
return currId < maxId;
}

@Override
public CellId next() {
if (!hasNext()) {
throw new NoSuchElementException();
}

if (currId < maxId) {
currId++;
return new CellId(level, currId);
}

if (rows.hasNext()) {
row = rows.next();
currId = row.getStart();
maxId = row.getEnd();
return new CellId(level, currId);
}
level++;
rows = gridMap.get(level).bbox2CellIdRanges(bbox, enlarge).iterator();
row = rows.next();
currId = row.getStart();
maxId = row.getEnd();
return new CellId(level, currId);
}
}
}

public static class CellIdRange implements Serializable {
private final CellId start;
private final CellId end;

Expand Down Expand Up @@ -203,9 +242,13 @@ public boolean equals(Object obj) {
* @param enlarge {@code true} to include enlarged bboxes
* @return List of {@code CellIdRanges} which are covered by the given bbox
*/
@SuppressWarnings({"Convert2Lambda", "java:S1604"})
public Iterable<CellIdRange> bbox2CellIdRanges(final OSHDBBoundingBox bbox,
final boolean enlarge) {
return () -> new Iterator<>() {
return new Iterable<>() {
@Override
public Iterator<CellIdRange> iterator() {
return new Iterator<>() {
private int level = 0;
private Iterator<IdRange> rows =
gridMap.get(level).bbox2CellIdRanges(bbox, enlarge).iterator();
Expand All @@ -225,6 +268,8 @@ public CellIdRange next() {
return CellIdRange.of(new CellId(level, row.getStart()),
new CellId(level, row.getEnd()));
}
};
}
};
}

Expand Down