use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.
the class AbstractQuestAnswerFragment method getCountryInfo.
protected final CountryInfo getCountryInfo() {
// cache it
if (countryInfo != null)
return countryInfo;
LatLon latLon = elementGeometry.center;
countryInfo = countryInfos.get(latLon.getLongitude(), latLon.getLatitude());
return countryInfo;
}
use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.
the class AddRoadNameForm method getRoadnameSuggestions.
private List<Map<String, String>> getRoadnameSuggestions() {
ElementGeometry geometry = getElementGeometry();
if (geometry == null || geometry.polylines == null || geometry.polylines.isEmpty()) {
return new ArrayList<>();
}
List<LatLon> points = geometry.polylines.get(0);
List<LatLon> onlyFirstAndLast = Arrays.asList(points.get(0), points.get(points.size() - 1));
return roadNameSuggestionsDao.getNames(onlyFirstAndLast, AddRoadName.MAX_DIST_FOR_ROAD_NAME_SUGGESTION);
}
use of de.westnordost.osmapi.map.data.LatLon 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.LatLon 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.LatLon in project StreetComplete by westnordost.
the class TangramConst method toLatLon.
public static List<List<LatLon>> toLatLon(List<List<LngLat>> positionLists) {
List<List<LatLon>> result = new ArrayList<>(positionLists.size());
for (List<LngLat> positions : positionLists) {
List<LatLon> resultPositions = new ArrayList<>(positions.size());
for (LngLat pos : positions) {
resultPositions.add(toLatLon(pos));
}
result.add(resultPositions);
}
return result;
}
Aggregations