Search in sources :

Example 26 with LatLon

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

the class ElementGeometryCreator method create.

public ElementGeometry create(Way way) {
    if (data == null)
        throw new NullPointerException();
    List<LatLon> polyline = data.getNodePositions(way.getId());
    // unable to create geometry
    if (polyline.isEmpty())
        return null;
    eliminateDuplicates(polyline);
    List<List<LatLon>> polylines = new ArrayList<>(1);
    polylines.add(polyline);
    ElementGeometry result;
    if (OsmAreas.isArea(way)) {
        // it is defined CCW here.
        if (ElementGeometry.isRingDefinedClockwise(polyline)) {
            Collections.reverse(polyline);
        }
        result = new ElementGeometry(null, polylines);
    } else {
        result = new ElementGeometry(polylines, null);
    }
    if (result.center == null)
        return null;
    return result;
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) ArrayList(java.util.ArrayList) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) ArrayList(java.util.ArrayList) List(java.util.List)

Example 27 with LatLon

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

the class ElementGeometryCreator method getWaysOfRelationWithRole.

private List<List<LatLon>> getWaysOfRelationWithRole(Relation relation, String role) {
    List<List<LatLon>> result = new ArrayList<>();
    for (RelationMember member : relation.getMembers()) {
        if (member.getType() != Element.Type.WAY)
            continue;
        long wayId = member.getRef();
        if (role == null || role.equals(member.getRole())) {
            List<LatLon> nodePositions = data.getNodePositions(wayId);
            eliminateDuplicates(nodePositions);
            if (nodePositions.size() > 1) {
                result.add(nodePositions);
            }
        }
    }
    return result;
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) RelationMember(de.westnordost.osmapi.map.data.RelationMember) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 28 with LatLon

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

the class ElementGeometryCreator method addTo.

/**
 * add <tt>way</tt> to the end of <tt>polyWay</tt>, if necessary in reverse
 */
private static void addTo(List<LatLon> way, List<LatLon> polyWay) {
    if (polyWay.isEmpty()) {
        polyWay.addAll(way);
    } else {
        LatLon addLast = way.get(way.size() - 1);
        LatLon toLast = polyWay.get(polyWay.size() - 1);
        if (addLast.equals(toLast)) {
            // -1 to not add the last vertex because it has already been added
            ListIterator<LatLon> it = way.listIterator(way.size() - 1);
            while (it.hasPrevious()) {
                polyWay.add(it.previous());
            }
        } else {
            // +1 to not add the first vertex because it has already been added
            ListIterator<LatLon> it = way.listIterator(+1);
            while (it.hasNext()) {
                polyWay.add(it.next());
            }
        }
    }
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon)

Example 29 with LatLon

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

the class OverpassMapDataParser method onStartElement.

@Override
protected void onStartElement() throws ParseException {
    String name = getName();
    switch(name) {
        case TAG:
            if (tags == null) {
                tags = new HashMap<>();
            }
            tags.put(getAttribute("k"), getAttribute("v"));
            break;
        case ND:
            Long ndRef = getLongAttribute("ref");
            if (// null for ND nodes in MEMBER
            ndRef != null) {
                nodes.add(ndRef);
            }
            LatLon pos = new OsmLatLon(getDoubleAttribute("lat"), getDoubleAttribute("lon"));
            wayNodes.add(pos);
            break;
        case MEMBER:
            long ref = getLongAttribute("ref");
            String role = getAttribute("role");
            Element.Type type = Element.Type.valueOf(getAttribute("type").toUpperCase(Locale.UK));
            members.add(factory.createRelationMember(ref, role, type));
            startWayGeometry(ref);
            break;
        case NODE:
            retrieveIdAndVersion();
            lat = getDoubleAttribute("lat");
            lon = getDoubleAttribute("lon");
            break;
        case WAY:
            retrieveIdAndVersion();
            nodes = new ArrayList<>();
            nodePositionsByWay = new LongSparseArray<>();
            startWayGeometry(id);
            break;
        case RELATION:
            retrieveIdAndVersion();
            members = new ArrayList<>();
            nodePositionsByWay = new LongSparseArray<>();
            break;
    }
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) Element(de.westnordost.osmapi.map.data.Element) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 30 with LatLon

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

the class AOsmQuestChangesUpload method invalidateAreaAroundQuest.

private void invalidateAreaAroundQuest(OsmQuest quest) {
    // called after a conflict. If there is a conflict, the user is not the only one in that
    // area, so best invalidate all downloaded quests here and redownload on next occasion
    LatLon questPosition = quest.getGeometry().center;
    Point tile = SlippyMapMath.enclosingTile(questPosition, ApplicationConstants.QUEST_TILE_ZOOM);
    downloadedTilesDao.remove(tile);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) Point(android.graphics.Point)

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