use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.
the class AddHousenumber method download.
@Override
public boolean download(BoundingBox bbox, final MapDataWithGeometryHandler handler) {
List<ElementWithGeometry> items = downloadBuildingsWithoutAddresses(bbox);
if (items == null)
return false;
// empty result: We are done
if (items.isEmpty())
return true;
List<Geometry> addrAreas = downloadAreasWithAddresses(bbox);
if (addrAreas == null)
return false;
Envelope bounds = null;
for (ElementWithGeometry item : items) {
Envelope addBounds = item.geometry.getEnvelopeInternal();
if (bounds == null)
bounds = addBounds;
else
bounds.expandToInclude(addBounds);
}
// see #885: The area in which the app should search for address nodes (and areas) must be
// adjusted to the bounding box of all the buildings found. The found buildings may in parts
// not be within the specified bounding box. But in exactly that part, there may be an
// address
BoundingBox adjustedBbox = JTSConst.toBoundingBox(bounds);
ArrayList<Point> addrPositions = downloadFreeFloatingPositionsWithAddresses(adjustedBbox);
if (addrPositions == null)
return false;
for (ElementWithGeometry item : items) {
// exclude buildings with housenumber-nodes inside them
int index = indexOfPointIn(item.geometry, addrPositions);
if (index != -1) {
// performance improvement: one housenumber-node cannot be covered by multiple
// buildings. So, it can be removed to reduce the amount of remaining
// point-in-polygon checks
addrPositions.remove(index);
continue;
}
// further exclude buildings that are contained in an area with a housenumber
if (coveredByAnyArea(item.geometry, addrAreas))
continue;
handler.handle(item.element, item.elementGeometry);
}
return true;
}
use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.
the class RoadNameSuggestionsDao method getNames.
public List<Map<String, String>> getNames(List<LatLon> points, double maxDistance) {
SQLiteDatabase db = dbHelper.getReadableDatabase();
// preselection via intersection check of bounding boxes
String rangeQuery = RoadNamesTable.Columns.MIN_LATITUDE + " <= ? AND " + RoadNamesTable.Columns.MIN_LONGITUDE + " <= ? AND " + RoadNamesTable.Columns.MAX_LATITUDE + " >= ? AND " + RoadNamesTable.Columns.MAX_LONGITUDE + " >= ? ";
StringBuilder query = new StringBuilder();
String[] args = new String[points.size() * 4];
for (int i = 0; i < points.size(); i++) {
if (i != 0)
query.append(" OR ");
query.append(rangeQuery);
LatLon point = points.get(i);
BoundingBox bbox = SphericalEarthMath.enclosingBoundingBox(point, maxDistance);
int ai = i * 4;
args[ai + 0] = "" + bbox.getMaxLatitude();
args[ai + 1] = "" + bbox.getMaxLongitude();
args[ai + 2] = "" + bbox.getMinLatitude();
args[ai + 3] = "" + bbox.getMinLongitude();
}
List<Map<String, String>> result = new ArrayList<>();
String[] cols = new String[] { RoadNamesTable.Columns.GEOMETRY, RoadNamesTable.Columns.NAMES };
try (Cursor cursor = db.query(RoadNamesTable.NAME, cols, query.toString(), args, null, null, null)) {
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
ArrayList<LatLon> geometry = serializer.toObject(cursor.getBlob(0), ArrayList.class);
if (SphericalEarthMath.isWithinDistance(maxDistance, points, geometry)) {
result.add(serializer.toObject(cursor.getBlob(1), HashMap.class));
}
cursor.moveToNext();
}
}
}
return result;
}
use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.
the class QuestsMapFragment method getDisplayedArea.
public BoundingBox getDisplayedArea(Rect offset) {
if (controller == null)
return null;
if (getView() == null)
return null;
Point size = new Point(getView().getWidth() - offset.left - offset.right, getView().getHeight() - offset.top - offset.bottom);
if (size.equals(0, 0))
return null;
// 45°
if (controller.getTilt() > Math.PI / 4f)
return null;
LatLon[] positions = new LatLon[4];
positions[0] = getPositionAt(new PointF(offset.left, offset.top));
positions[1] = getPositionAt(new PointF(offset.left + size.x, offset.top));
positions[2] = getPositionAt(new PointF(offset.left, offset.top + size.y));
positions[3] = getPositionAt(new PointF(offset.left + size.x, offset.top + size.y));
// dealing with rotation: find each the largest latlon and the smallest latlon, that'll
// be our bounding box
Double latMin = null, lonMin = null, latMax = null, lonMax = null;
for (LatLon position : positions) {
double lat = position.getLatitude();
double lon = position.getLongitude();
if (latMin == null || latMin > lat)
latMin = lat;
if (latMax == null || latMax < lat)
latMax = lat;
if (lonMin == null || lonMin > lon)
lonMin = lon;
if (lonMax == null || lonMax < lon)
lonMax = lon;
}
return new BoundingBox(latMin, lonMin, latMax, lonMax);
}
use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.
the class QuestsMapFragment method getMaxZoomThatContains.
private float getMaxZoomThatContains(ElementGeometry geometry) {
BoundingBox objectBounds = geometry.getBounds();
BoundingBox screenArea;
float currentZoom;
synchronized (controller) {
screenArea = getDisplayedArea(questOffset);
if (screenArea == null)
return Float.NaN;
currentZoom = controller.getZoom();
}
double screenWidth = screenArea.getMaxLongitude() - screenArea.getMinLongitude();
double screenHeight = screenArea.getMaxLatitude() - screenArea.getMinLatitude();
double objectWidth = objectBounds.getMaxLongitude() - objectBounds.getMinLongitude();
double objectHeight = objectBounds.getMaxLatitude() - objectBounds.getMinLatitude();
double zoomDeltaX = Math.log10(screenWidth / objectWidth) / Math.log10(2.);
double zoomDeltaY = Math.log10(screenHeight / objectHeight) / Math.log10(2.);
return (float) Math.max(1, currentZoom + Math.min(zoomDeltaX, zoomDeltaY));
}
use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.
the class ElementGeometryTest method testFindCenterOfPolyline.
public void testFindCenterOfPolyline() {
List<List<LatLon>> polylines = new ArrayList<>();
List<LatLon> polyline = new ArrayList<>();
LatLon start = new OsmLatLon(-10, -20);
LatLon finish = new OsmLatLon(10, 20);
polyline.add(start);
polyline.add(finish);
polylines.add(polyline);
ElementGeometry geom = new ElementGeometry(polylines, null);
double dist = SphericalEarthMath.distance(start, finish);
double bearing = SphericalEarthMath.bearing(start, finish);
LatLon expect = SphericalEarthMath.translate(start, dist / 2, bearing);
assertEquals(expect, geom.center);
assertEquals(new BoundingBox(start, finish), geom.getBounds());
}
Aggregations