Search in sources :

Example 1 with BoundingBox

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;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) Point(com.vividsolutions.jts.geom.Point) Envelope(com.vividsolutions.jts.geom.Envelope) Point(com.vividsolutions.jts.geom.Point)

Example 2 with BoundingBox

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) LatLon(de.westnordost.osmapi.map.data.LatLon) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with BoundingBox

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);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) PointF(android.graphics.PointF) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) Point(android.graphics.Point)

Example 4 with BoundingBox

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));
}
Also used : BoundingBox(de.westnordost.osmapi.map.data.BoundingBox)

Example 5 with BoundingBox

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());
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Aggregations

BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)28 LatLon (de.westnordost.osmapi.map.data.LatLon)13 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)11 ArrayList (java.util.ArrayList)7 Rect (android.graphics.Rect)4 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)4 Point (android.graphics.Point)3 Note (de.westnordost.osmapi.notes.Note)3 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)3 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)3 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)3 Collection (java.util.Collection)3 List (java.util.List)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 OsmNode (de.westnordost.osmapi.map.data.OsmNode)2 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)2 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)2 Date (java.util.Date)2 Cursor (android.database.Cursor)1 PointF (android.graphics.PointF)1