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);
}
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());
}
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));
}
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);
}
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();
}
Aggregations