use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class GeocodingLookupService method geocode.
private boolean geocode(final LatLon latLon) {
Location loc = new Location("");
loc.setLatitude(latLon.getLatitude());
loc.setLongitude(latLon.getLongitude());
return app.getLocationProvider().getGeocodingResult(loc, new ResultMatcher<GeocodingResult>() {
@Override
public boolean publish(GeocodingResult object) {
String result = null;
if (object != null) {
OsmandSettings settings = app.getSettings();
String lang = settings.MAP_PREFERRED_LOCALE.get();
boolean transliterate = settings.MAP_TRANSLITERATE_NAMES.get();
String geocodingResult = "";
double relevantDistance = -1;
if (object.building != null) {
String bldName = object.building.getName(lang, transliterate);
if (!Algorithms.isEmpty(object.buildingInterpolation)) {
bldName = object.buildingInterpolation;
}
geocodingResult = object.street.getName(lang, transliterate) + " " + bldName + ", " + object.city.getName(lang, transliterate);
} else if (object.street != null) {
geocodingResult = object.street.getName(lang, transliterate) + ", " + object.city.getName(lang, transliterate);
relevantDistance = object.getDistanceP();
} else if (object.city != null) {
geocodingResult = object.city.getName(lang, transliterate);
} else if (object.point != null) {
RouteDataObject rd = object.point.getRoad();
String sname = rd.getName(lang, transliterate);
if (Algorithms.isEmpty(sname)) {
sname = "";
}
String ref = rd.getRef(lang, transliterate, true);
if (!Algorithms.isEmpty(ref)) {
if (!Algorithms.isEmpty(sname)) {
sname += ", ";
}
sname += ref;
}
geocodingResult = sname;
relevantDistance = object.getDistanceP();
}
result = geocodingResult;
if (relevantDistance == -1) {
relevantDistance = object.getDistance();
}
if (!Algorithms.isEmpty(result) && relevantDistance > 100) {
result = app.getString(R.string.shared_string_near) + " " + result;
}
}
lastFoundAddress = result;
searchDone = true;
return true;
}
@Override
public boolean isCancelled() {
return !hasAnyRequest(latLon);
}
});
}
use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class RoutePlannerFrontEnd method projectDistance.
protected double projectDistance(List<RouteSegmentResult> res, int k, int px, int py) {
RouteSegmentResult sr = res.get(k);
RouteDataObject r = sr.getObject();
QuadPoint pp = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(sr.getStartPointIndex()), r.getPoint31YTile(sr.getStartPointIndex()), r.getPoint31XTile(sr.getEndPointIndex()), r.getPoint31YTile(sr.getEndPointIndex()));
double currentsDist = squareDist((int) pp.x, (int) pp.y, px, py);
return currentsDist;
}
use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class RoutePlannerFrontEnd method updateResult.
private void updateResult(RouteSegmentResult routeSegmentResult, LatLon point, boolean st) {
int px = MapUtils.get31TileNumberX(point.getLongitude());
int py = MapUtils.get31TileNumberY(point.getLatitude());
int pind = st ? routeSegmentResult.getStartPointIndex() : routeSegmentResult.getEndPointIndex();
RouteDataObject r = routeSegmentResult.getObject();
QuadPoint before = null;
QuadPoint after = null;
if (pind > 0) {
before = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(pind - 1), r.getPoint31YTile(pind - 1), r.getPoint31XTile(pind), r.getPoint31YTile(pind));
}
if (pind < r.getPointsLength() - 1) {
after = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(pind + 1), r.getPoint31YTile(pind + 1), r.getPoint31XTile(pind), r.getPoint31YTile(pind));
}
int insert = 0;
double dd = MapUtils.getDistance(point, MapUtils.get31LatitudeY(r.getPoint31YTile(pind)), MapUtils.get31LongitudeX(r.getPoint31XTile(pind)));
double ddBefore = Double.POSITIVE_INFINITY;
double ddAfter = Double.POSITIVE_INFINITY;
QuadPoint i = null;
if (before != null) {
ddBefore = MapUtils.getDistance(point, MapUtils.get31LatitudeY((int) before.y), MapUtils.get31LongitudeX((int) before.x));
if (ddBefore < dd) {
insert = -1;
i = before;
}
}
if (after != null) {
ddAfter = MapUtils.getDistance(point, MapUtils.get31LatitudeY((int) after.y), MapUtils.get31LongitudeX((int) after.x));
if (ddAfter < dd && ddAfter < ddBefore) {
insert = 1;
i = after;
}
}
if (insert != 0) {
if (st && routeSegmentResult.getStartPointIndex() < routeSegmentResult.getEndPointIndex()) {
routeSegmentResult.setEndPointIndex(routeSegmentResult.getEndPointIndex() + 1);
}
if (!st && routeSegmentResult.getStartPointIndex() > routeSegmentResult.getEndPointIndex()) {
routeSegmentResult.setStartPointIndex(routeSegmentResult.getStartPointIndex() + 1);
}
if (insert > 0) {
r.insert(pind + 1, (int) i.x, (int) i.y);
if (st) {
routeSegmentResult.setStartPointIndex(routeSegmentResult.getStartPointIndex() + 1);
}
if (!st) {
routeSegmentResult.setEndPointIndex(routeSegmentResult.getEndPointIndex() + 1);
}
} else {
r.insert(pind, (int) i.x, (int) i.y);
}
}
}
use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class RoutePlannerFrontEnd method findRouteSegment.
public RouteSegmentPoint findRouteSegment(double lat, double lon, RoutingContext ctx, List<RouteSegmentPoint> list) throws IOException {
int px = MapUtils.get31TileNumberX(lon);
int py = MapUtils.get31TileNumberY(lat);
ArrayList<RouteDataObject> dataObjects = new ArrayList<RouteDataObject>();
ctx.loadTileData(px, py, 17, dataObjects);
if (dataObjects.isEmpty()) {
ctx.loadTileData(px, py, 15, dataObjects);
}
if (list == null) {
list = new ArrayList<BinaryRoutePlanner.RouteSegmentPoint>();
}
for (RouteDataObject r : dataObjects) {
if (r.getPointsLength() > 1) {
RouteSegmentPoint road = null;
for (int j = 1; j < r.getPointsLength(); j++) {
QuadPoint pr = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(j - 1), r.getPoint31YTile(j - 1), r.getPoint31XTile(j), r.getPoint31YTile(j));
double currentsDistSquare = squareDist((int) pr.x, (int) pr.y, px, py);
if (road == null || currentsDistSquare < road.distSquare) {
RouteDataObject ro = new RouteDataObject(r);
road = new RouteSegmentPoint(ro, j, currentsDistSquare);
road.preciseX = (int) pr.x;
road.preciseY = (int) pr.y;
}
}
if (road != null) {
list.add(road);
}
}
}
Collections.sort(list, new Comparator<RouteSegmentPoint>() {
@Override
public int compare(RouteSegmentPoint o1, RouteSegmentPoint o2) {
return Double.compare(o1.distSquare, o2.distSquare);
}
});
if (list.size() > 0) {
RouteSegmentPoint ps = list.get(0);
ps.others = list;
return ps;
}
return null;
}
use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class RoutingContext method loadAllSubregionTiles.
public List<RoutingSubregionTile> loadAllSubregionTiles(BinaryMapIndexReader reader, RouteSubregion reg) throws IOException {
List<RoutingSubregionTile> list = new ArrayList<RoutingContext.RoutingSubregionTile>();
SearchRequest<RouteDataObject> request = BinaryMapIndexReader.buildSearchRouteRequest(0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, null);
List<RouteSubregion> subregs = reader.searchRouteIndexTree(request, Collections.singletonList(reg));
for (RouteSubregion s : subregs) {
list.add(new RoutingSubregionTile(s));
}
return list;
}
Aggregations