Search in sources :

Example 21 with BoundingBox

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

the class SphericalEarthMath method enclosingBoundingBox.

/**
 * Calculate a bounding box that contains the given circle. In other words, it is a square
 * centered at the given position and with a side length of radius*2
 * @param center of the circle
 * @param radius in meters
 * @return The bounding box that contains the area
 */
public static BoundingBox enclosingBoundingBox(LatLon center, double radius) {
    double distance = sqrt(2) * radius;
    LatLon min = translate(center, distance, 225);
    LatLon max = translate(center, distance, 45);
    return new BoundingBox(min, max);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox)

Example 22 with BoundingBox

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

the class ElementGeometryTest method testBoundsWithSquare.

public void testBoundsWithSquare() {
    List<List<LatLon>> polygons = new ArrayList<>();
    polygons.add(createSquareAroundOrigin(5, 10));
    ElementGeometry geom = new ElementGeometry(null, polygons);
    BoundingBox expected = new BoundingBox(-5, -10, 5, 10);
    assertEquals(expected, geom.getBounds());
}
Also used : BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 23 with BoundingBox

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

the class OsmQuestDownloadTest method testDeleteObsoleteQuests.

public void testDeleteObsoleteQuests() {
    LatLon pos = new OsmLatLon(3.0, 4.0);
    ElementWithGeometry node4 = new ElementWithGeometry();
    node4.element = new OsmNode(4, 0, pos, null);
    node4.geometry = new ElementGeometry(pos);
    // questType mock will only "find" the Node #4
    OsmElementQuestType questType = new ListBackedQuestType(Collections.singletonList(node4));
    // in the quest database mock, there are quests for node 4 and node 5
    List<OsmQuest> quests = new ArrayList<>();
    quests.add(new OsmQuest(12L, questType, Element.Type.NODE, 4, QuestStatus.NEW, null, null, new Date(), new ElementGeometry(pos)));
    quests.add(new OsmQuest(13L, questType, Element.Type.NODE, 5, QuestStatus.NEW, null, null, new Date(), new ElementGeometry(pos)));
    when(osmQuestDao.getAll(any(BoundingBox.class), any(QuestStatus.class), anyString(), any(Element.Type.class), anyLong())).thenReturn(quests);
    doAnswer(invocation -> {
        Collection<Long> deletedQuests = (Collection<Long>) (invocation.getArguments()[0]);
        assertEquals(1, deletedQuests.size());
        assertEquals(13L, (long) deletedQuests.iterator().next());
        return 1;
    }).when(osmQuestDao).deleteAll(any(Collection.class));
    OsmQuestDownload dl = new OsmQuestDownload(geometryDb, elementDb, osmQuestDao, countryBoundariesFuture);
    VisibleQuestListener listener = mock(VisibleQuestListener.class);
    dl.setQuestListener(listener);
    // -> we expect that quest with node #5 is removed
    dl.download(questType, new BoundingBox(0, 0, 1, 1), null);
    verify(osmQuestDao).deleteAll(any(Collection.class));
    verify(listener).onQuestsRemoved(any(Collection.class), any(QuestGroup.class));
}
Also used : OsmNode(de.westnordost.osmapi.map.data.OsmNode) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) ArrayList(java.util.ArrayList) QuestGroup(de.westnordost.streetcomplete.data.QuestGroup) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) Date(java.util.Date) VisibleQuestListener(de.westnordost.streetcomplete.data.VisibleQuestListener) LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) Matchers.anyLong(org.mockito.Matchers.anyLong) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) Collection(java.util.Collection) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 24 with BoundingBox

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

the class FiltersParserTest method testBoundingBox.

public void testBoundingBox() {
    BoundingBox bbox = new BoundingBox(0, 0, 5, 10);
    check("nodes", "[bbox:0.0,0.0,5.0,10.0];node;out meta geom;", bbox);
    check("nodes with highway", "[bbox:0.0,0.0,5.0,10.0];node[\"highway\"];out meta geom;", bbox);
    check("nodes with highway or railway", "[bbox:0.0,0.0,5.0,10.0];(node[\"highway\"];node[\"railway\"];);out meta geom;", bbox);
}
Also used : BoundingBox(de.westnordost.osmapi.map.data.BoundingBox)

Example 25 with BoundingBox

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

the class RoadNameSuggestionsDao method putRoad.

public void putRoad(long wayId, HashMap<String, String> namesByLanguage, ArrayList<LatLon> geometry) {
    BoundingBox bbox = SphericalEarthMath.enclosingBoundingBox(geometry);
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    db.beginTransaction();
    insert.bindLong(1, wayId);
    insert.bindBlob(2, serializer.toBytes(namesByLanguage));
    insert.bindBlob(3, serializer.toBytes(geometry));
    insert.bindDouble(4, bbox.getMinLatitude());
    insert.bindDouble(5, bbox.getMinLongitude());
    insert.bindDouble(6, bbox.getMaxLatitude());
    insert.bindDouble(7, bbox.getMaxLongitude());
    insert.executeInsert();
    insert.clearBindings();
    db.setTransactionSuccessful();
    db.endTransaction();
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox)

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