Search in sources :

Example 26 with BoundingBox

use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.

the class ElementGeometry method getBounds.

public BoundingBox getBounds() {
    List<List<LatLon>> points;
    if (polygons != null)
        points = polygons;
    else if (polylines != null)
        points = polylines;
    else
        return new BoundingBox(center.getLatitude(), center.getLongitude(), center.getLatitude(), center.getLongitude());
    Double latMin = null, lonMin = null, latMax = null, lonMax = null;
    for (List<LatLon> ps : points) {
        for (LatLon p : ps) {
            double lat = p.getLatitude();
            double lon = p.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) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) List(java.util.List) ArrayList(java.util.ArrayList)

Example 27 with BoundingBox

use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.

the class CreateNoteUpload method findAlreadyExistingNoteWithSameAssociatedElement.

private Note findAlreadyExistingNoteWithSameAssociatedElement(final CreateNote newNote) {
    SingleElementHandler<Note> handler = new SingleElementHandler<Note>() {

        @Override
        public void handle(Note oldNote) {
            if (newNote.hasAssociatedElement()) {
                String firstCommentText = oldNote.comments.get(0).text;
                String newNoteRegex = getAssociatedElementRegex(newNote);
                if (firstCommentText.matches(newNoteRegex)) {
                    super.handle(oldNote);
                }
            }
        }
    };
    final int hideClosedNoteAfter = 7;
    osmDao.getAll(new BoundingBox(newNote.position.getLatitude(), newNote.position.getLongitude(), newNote.position.getLatitude(), newNote.position.getLongitude()), handler, 10, hideClosedNoteAfter);
    return handler.get();
}
Also used : Note(de.westnordost.osmapi.notes.Note) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) SingleElementHandler(de.westnordost.osmapi.common.SingleElementHandler)

Example 28 with BoundingBox

use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.

the class SphericalEarthMathTest method testEnclosingBoundingBoxLine.

public void testEnclosingBoundingBoxLine() {
    List<LatLon> positions = new ArrayList<>();
    positions.add(new OsmLatLon(-4, 0));
    positions.add(new OsmLatLon(12, 3));
    positions.add(new OsmLatLon(1, 16));
    positions.add(new OsmLatLon(0, -6));
    BoundingBox bbox = SphericalEarthMath.enclosingBoundingBox(positions);
    assertEquals(-4.0, bbox.getMinLatitude());
    assertEquals(12.0, bbox.getMaxLatitude());
    assertEquals(16.0, bbox.getMaxLongitude());
    assertEquals(-6.0, bbox.getMinLongitude());
}
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) 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