use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class RoutingContext method loadRouteSegment.
public RouteSegment loadRouteSegment(int x31, int y31, int memoryLimit) {
long tileId = getRoutingTile(x31, y31, memoryLimit, OPTION_SMART_LOAD);
TLongObjectHashMap<RouteDataObject> excludeDuplications = new TLongObjectHashMap<RouteDataObject>();
RouteSegment original = null;
if (tileRoutes.containsKey(tileId)) {
List<RouteDataObject> routes = tileRoutes.get(tileId);
if (routes != null) {
for (RouteDataObject ro : routes) {
for (int i = 0; i < ro.pointsX.length; i++) {
if (ro.getPoint31XTile(i) == x31 && ro.getPoint31YTile(i) == y31) {
long id = calcRouteId(ro, i);
if (excludeDuplications.contains(id)) {
continue;
}
excludeDuplications.put(id, ro);
RouteSegment segment = new RouteSegment(ro, i);
segment.next = original;
original = segment;
}
}
}
}
}
List<RoutingSubregionTile> subregions = indexedSubregions.get(tileId);
if (subregions != null) {
for (RoutingSubregionTile rs : subregions) {
original = rs.loadRouteSegment(x31, y31, this, excludeDuplications, original);
}
}
return original;
}
use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class BinaryRoutePlanner method proccessRestrictions.
private boolean proccessRestrictions(RoutingContext ctx, RouteSegment segment, RouteSegment inputNext, boolean reverseWay) {
if (!ctx.getRouter().restrictionsAware()) {
return false;
}
RouteDataObject road = segment.getRoad();
RouteSegment parent = getParentDiffId(segment);
if (!reverseWay && road.getRestrictionLength() == 0 && (parent == null || parent.getRoad().getRestrictionLength() == 0)) {
return false;
}
ctx.segmentsToVisitPrescripted.clear();
ctx.segmentsToVisitNotForbidden.clear();
processRestriction(ctx, inputNext, reverseWay, false, road);
if (parent != null) {
processRestriction(ctx, inputNext, reverseWay, true, parent.getRoad());
}
return true;
}
use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class RouteResultPreparation method attachRoadSegments.
private void attachRoadSegments(RoutingContext ctx, List<RouteSegmentResult> result, int routeInd, int pointInd, boolean plus) throws IOException {
RouteSegmentResult rr = result.get(routeInd);
RouteDataObject road = rr.getObject();
long nextL = pointInd < road.getPointsLength() - 1 ? getPoint(road, pointInd + 1) : 0;
long prevL = pointInd > 0 ? getPoint(road, pointInd - 1) : 0;
// attach additional roads to represent more information about the route
RouteSegmentResult previousResult = null;
// by default make same as this road id
long previousRoadId = road.getId();
if (pointInd == rr.getStartPointIndex() && routeInd > 0) {
previousResult = result.get(routeInd - 1);
previousRoadId = previousResult.getObject().getId();
if (previousRoadId != road.getId()) {
if (previousResult.getStartPointIndex() < previousResult.getEndPointIndex() && previousResult.getEndPointIndex() < previousResult.getObject().getPointsLength() - 1) {
rr.attachRoute(pointInd, new RouteSegmentResult(previousResult.getObject(), previousResult.getEndPointIndex(), previousResult.getObject().getPointsLength() - 1));
} else if (previousResult.getStartPointIndex() > previousResult.getEndPointIndex() && previousResult.getEndPointIndex() > 0) {
rr.attachRoute(pointInd, new RouteSegmentResult(previousResult.getObject(), previousResult.getEndPointIndex(), 0));
}
}
}
Iterator<RouteSegment> it;
if (rr.getPreAttachedRoutes(pointInd) != null) {
final RouteSegmentResult[] list = rr.getPreAttachedRoutes(pointInd);
it = new Iterator<BinaryRoutePlanner.RouteSegment>() {
int i = 0;
@Override
public boolean hasNext() {
return i < list.length;
}
@Override
public RouteSegment next() {
RouteSegmentResult r = list[i++];
return new RouteSegment(r.getObject(), r.getStartPointIndex());
}
@Override
public void remove() {
}
};
} else {
RouteSegment rt = ctx.loadRouteSegment(road.getPoint31XTile(pointInd), road.getPoint31YTile(pointInd), ctx.config.memoryLimitation);
it = rt == null ? null : rt.getIterator();
}
// try to attach all segments except with current id
while (it != null && it.hasNext()) {
RouteSegment routeSegment = it.next();
if (routeSegment.road.getId() != road.getId() && routeSegment.road.getId() != previousRoadId) {
RouteDataObject addRoad = routeSegment.road;
checkAndInitRouteRegion(ctx, addRoad);
// TODO restrictions can be considered as well
int oneWay = ctx.getRouter().isOneWay(addRoad);
if (oneWay >= 0 && routeSegment.getSegmentStart() < addRoad.getPointsLength() - 1) {
long pointL = getPoint(addRoad, routeSegment.getSegmentStart() + 1);
if (pointL != nextL && pointL != prevL) {
// if way contains same segment (nodes) as different way (do not attach it)
rr.attachRoute(pointInd, new RouteSegmentResult(addRoad, routeSegment.getSegmentStart(), addRoad.getPointsLength() - 1));
}
}
if (oneWay <= 0 && routeSegment.getSegmentStart() > 0) {
long pointL = getPoint(addRoad, routeSegment.getSegmentStart() - 1);
// if way contains same segment (nodes) as different way (do not attach it)
if (pointL != nextL && pointL != prevL) {
rr.attachRoute(pointInd, new RouteSegmentResult(addRoad, routeSegment.getSegmentStart(), 0));
}
}
}
}
}
use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class CurrentPositionHelper method getLastKnownRouteSegment.
public RouteDataObject getLastKnownRouteSegment(Location loc) {
Location last = lastAskedLocation;
RouteDataObject r = lastFound;
if (loc == null || loc.getAccuracy() > 50) {
return null;
}
if (last != null && last.distanceTo(loc) < 10) {
return r;
}
if (r == null) {
scheduleRouteSegmentFind(loc, true, null, null);
return null;
}
double d = getOrthogonalDistance(r, loc);
if (d > 15) {
scheduleRouteSegmentFind(loc, true, null, null);
}
if (d < 70) {
return r;
}
return null;
}
use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class ImpassableRoadsLayer method collectObjectsFromPoint.
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
if (tileBox.getZoom() >= startZoom) {
int ex = (int) point.x;
int ey = (int) point.y;
int compare = getRadiusPoi(tileBox);
int radius = compare * 3 / 2;
for (RouteDataObject road : getImpassableRoads()) {
Location location = getImpassableRoadLocations().get(road.getId());
if (location != null) {
int x = (int) tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
int y = (int) tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
if (calculateBelongs(ex, ey, x, y, compare)) {
compare = radius;
o.add(road);
}
}
}
}
if (!storedRoadDataObjects.isEmpty()) {
activity.getMyApplication().getAvoidSpecificRoads().initPreservedData();
storedRoadDataObjects.clear();
}
}
Aggregations