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