Search in sources :

Example 51 with LatLon

use of de.westnordost.osmapi.map.data.LatLon 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 52 with LatLon

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

the class ElementGeometryCreator method eliminateDuplicates.

private void eliminateDuplicates(List<LatLon> polyline) {
    Iterator<LatLon> it = polyline.iterator();
    LatLon previous = null;
    while (it.hasNext()) {
        LatLon line = it.next();
        if (previous == null || line.getLatitude() != previous.getLatitude() || line.getLongitude() != previous.getLongitude()) {
            previous = line;
        } else {
            it.remove();
        }
    }
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon)

Example 53 with LatLon

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

the class ElementGeometryDao method createObjectFrom.

static ElementGeometry createObjectFrom(Serializer serializer, Cursor cursor) {
    int colGeometryPolygons = cursor.getColumnIndexOrThrow(ElementGeometryTable.Columns.GEOMETRY_POLYGONS), colGeometryPolylines = cursor.getColumnIndexOrThrow(ElementGeometryTable.Columns.GEOMETRY_POLYLINES), colCenterLat = cursor.getColumnIndexOrThrow(ElementGeometryTable.Columns.LATITUDE), colCenterLon = cursor.getColumnIndexOrThrow(ElementGeometryTable.Columns.LONGITUDE);
    List<List<LatLon>> polygons = null, polylines = null;
    if (!cursor.isNull(colGeometryPolygons)) {
        polygons = serializer.toObject(cursor.getBlob(colGeometryPolygons), ArrayList.class);
    }
    if (!cursor.isNull(colGeometryPolylines)) {
        polylines = serializer.toObject(cursor.getBlob(colGeometryPolylines), ArrayList.class);
    }
    LatLon center = new OsmLatLon(cursor.getDouble(colCenterLat), cursor.getDouble(colCenterLon));
    return new ElementGeometry(polylines, polygons, center);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) ArrayList(java.util.ArrayList) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) ArrayList(java.util.ArrayList) List(java.util.List) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 54 with LatLon

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

the class NodeDao method createObjectFrom.

@Override
protected Node createObjectFrom(Cursor cursor) {
    int colId = cursor.getColumnIndexOrThrow(NodeTable.Columns.ID), colLat = cursor.getColumnIndexOrThrow(NodeTable.Columns.LATITUDE), colLon = cursor.getColumnIndexOrThrow(NodeTable.Columns.LONGITUDE), colVersion = cursor.getColumnIndexOrThrow(NodeTable.Columns.VERSION), colTags = cursor.getColumnIndexOrThrow(NodeTable.Columns.TAGS);
    long id = cursor.getLong(colId);
    int version = cursor.getInt(colVersion);
    LatLon latLon = new OsmLatLon(cursor.getDouble(colLat), cursor.getDouble(colLon));
    Map<String, String> tags = null;
    if (!cursor.isNull(colTags)) {
        tags = serializer.toObject(cursor.getBlob(colTags), HashMap.class);
    }
    return new OsmNode(id, version, latLon, tags);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) HashMap(java.util.HashMap) OsmNode(de.westnordost.osmapi.map.data.OsmNode) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 55 with LatLon

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

the class TangramConstTest method testConvertSingle.

public void testConvertSingle() {
    double lng = 10;
    double lat = 5;
    OsmLatLon pos = new OsmLatLon(lat, lng);
    LatLon pos2 = TangramConst.toLatLon(TangramConst.toLngLat(pos));
    assertEquals(pos, pos2);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

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