Search in sources :

Example 1 with LatLon

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

Example 2 with LatLon

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

Example 3 with LatLon

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;
}
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 4 with LatLon

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);
}
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 5 with LatLon

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

Aggregations

LatLon (de.westnordost.osmapi.map.data.LatLon)63 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)45 ArrayList (java.util.ArrayList)29 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)13 List (java.util.List)12 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)8 OsmNode (de.westnordost.osmapi.map.data.OsmNode)5 HashMap (java.util.HashMap)5 Point (android.graphics.Point)3 PointF (android.graphics.PointF)3 Node (de.westnordost.osmapi.map.data.Node)3 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)3 LngLat (com.mapzen.tangram.LngLat)2 Point (com.vividsolutions.jts.geom.Point)2 Element (de.westnordost.osmapi.map.data.Element)2 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)2 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)2 OsmNoteQuestType (de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestType)2 Collection (java.util.Collection)2 Map (java.util.Map)2