use of net.osmand.binary.RouteDataObject in project OsmAnd-tools by osmandapp.
the class CheckRoadConnectivity method collectDisconnectedRoads.
public TLongObjectHashMap<RouteDataObject> collectDisconnectedRoads(BinaryMapIndexReader reader) throws IOException {
TLongObjectHashMap<List<RouteDataObject>> all = new TLongObjectHashMap<List<RouteDataObject>>();
TLongObjectHashMap<List<RouteDataObject>> onlyRoads = new TLongObjectHashMap<List<RouteDataObject>>();
TLongHashSet registeredRoadIds = new TLongHashSet();
findAllBaseRoadIntersections(reader, all, onlyRoads, registeredRoadIds);
return calculateDisconnectedRoadsToAddAndDelete(onlyRoads, all, reader, null, registeredRoadIds);
}
use of net.osmand.binary.RouteDataObject in project OsmAnd-tools by osmandapp.
the class ObfFileInMemory method writeRouteData.
private void writeRouteData(BinaryMapIndexWriter writer, TLongObjectHashMap<RouteDataObject> routeObjs, File fileToWrite) throws IOException, RTreeException, SQLException {
File nonpackRtree = new File(fileToWrite.getParentFile(), "nonpackroute." + fileToWrite.getName() + ".rtree");
File packRtree = new File(fileToWrite.getParentFile(), "packroute." + fileToWrite.getName() + ".rtree");
RTree rtree = null;
try {
rtree = new RTree(nonpackRtree.getAbsolutePath());
for (long key : routeObjs.keys()) {
RouteDataObject obj = routeObjs.get(key);
int minX = obj.getPoint31XTile(0);
int maxX = obj.getPoint31XTile(0);
int maxY = obj.getPoint31YTile(0);
int minY = obj.getPoint31YTile(0);
for (int i = 1; i < obj.getPointsLength(); i++) {
minX = Math.min(minX, obj.getPoint31XTile(i));
minY = Math.min(minY, obj.getPoint31YTile(i));
maxX = Math.max(maxX, obj.getPoint31XTile(i));
maxY = Math.max(maxY, obj.getPoint31YTile(i));
}
try {
rtree.insert(new LeafElement(new Rect(minX, minY, maxX, maxY), obj.getId()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
rtree = AbstractIndexPartCreator.packRtreeFile(rtree, nonpackRtree.getAbsolutePath(), packRtree.getAbsolutePath());
TLongObjectHashMap<BinaryFileReference> treeHeader = new TLongObjectHashMap<BinaryFileReference>();
long rootIndex = rtree.getFileHdr().getRootIndex();
rtree.Node root = rtree.getReadNode(rootIndex);
Rect rootBounds = IndexUploader.calcBounds(root);
if (rootBounds != null) {
IndexRouteCreator.writeBinaryRouteTree(root, rootBounds, rtree, writer, treeHeader, false);
RouteWriteContext wc = new RouteWriteContext(null, treeHeader, null, routeObjs);
IndexRouteCreator.writeBinaryMapBlock(root, rootBounds, rtree, writer, wc, false);
}
} finally {
if (rtree != null) {
RandomAccessFile file = rtree.getFileHdr().getFile();
file.close();
}
nonpackRtree.delete();
packRtree.delete();
RTree.clearCache();
}
}
use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class AvoidSpecificRoads method addImpassableRoad.
public void addImpassableRoad(@Nullable final MapActivity activity, @NonNull final LatLon loc, final boolean showDialog, @Nullable final AvoidSpecificRoadsCallback callback, final boolean skipWritingSettings) {
final Location ll = new Location("");
ll.setLatitude(loc.getLatitude());
ll.setLongitude(loc.getLongitude());
ApplicationMode appMode = app.getRoutingHelper().getAppMode();
app.getLocationProvider().getRouteSegment(ll, appMode, new ResultMatcher<RouteDataObject>() {
@Override
public boolean publish(RouteDataObject object) {
if (object == null) {
if (activity != null) {
Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
}
if (callback != null) {
callback.onAddImpassableRoad(false, null);
}
} else {
addImpassableRoadInternal(object, ll, showDialog, activity, loc);
if (callback != null) {
callback.onAddImpassableRoad(true, object);
}
}
return true;
}
@Override
public boolean isCancelled() {
return callback != null && callback.isCancelled();
}
});
if (!skipWritingSettings) {
app.getSettings().addImpassableRoad(loc.getLatitude(), loc.getLongitude());
}
}
use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class AvoidSpecificRoads method replaceImpassableRoad.
public void replaceImpassableRoad(final MapActivity activity, final RouteDataObject currentObject, final LatLon loc, final boolean showDialog, final AvoidSpecificRoadsCallback callback) {
LatLon latLon = getLocation(currentObject);
app.getSettings().moveImpassableRoad(latLon, loc);
final Location ll = new Location("");
ll.setLatitude(loc.getLatitude());
ll.setLongitude(loc.getLongitude());
ApplicationMode appMode = app.getRoutingHelper().getAppMode();
app.getLocationProvider().getRouteSegment(ll, appMode, new ResultMatcher<RouteDataObject>() {
@Override
public boolean publish(RouteDataObject object) {
if (object == null) {
Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
if (callback != null) {
callback.onAddImpassableRoad(false, null);
}
} else {
app.getDefaultRoutingConfig().removeImpassableRoad(currentObject);
addImpassableRoadInternal(object, ll, showDialog, activity, loc);
if (callback != null) {
callback.onAddImpassableRoad(true, object);
}
}
return true;
}
@Override
public boolean isCancelled() {
return callback != null && callback.isCancelled();
}
});
}
use of net.osmand.binary.RouteDataObject in project Osmand by osmandapp.
the class AvoidSpecificRoads method createAdapter.
private ArrayAdapter<RouteDataObject> createAdapter(final MapActivity ctx) {
final ArrayList<RouteDataObject> points = new ArrayList<>();
points.addAll(getImpassableRoads());
final LatLon mapLocation = ctx.getMapLocation();
return new ArrayAdapter<RouteDataObject>(ctx, R.layout.waypoint_reached, R.id.title, points) {
@NonNull
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
View v = convertView;
if (v == null || v.findViewById(R.id.info_close) == null) {
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, parent, false);
}
final RouteDataObject obj = getItem(position);
v.findViewById(R.id.all_points).setVisibility(View.GONE);
((ImageView) v.findViewById(R.id.waypoint_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_road_works_dark));
double dist = MapUtils.getDistance(mapLocation, MapUtils.get31LatitudeY(obj.getPoint31YTile(0)), MapUtils.get31LongitudeX(obj.getPoint31XTile(0)));
((TextView) v.findViewById(R.id.waypoint_dist)).setText(OsmAndFormatter.getFormattedDistance((float) dist, app));
((TextView) v.findViewById(R.id.waypoint_text)).setText(getText(obj));
ImageButton remove = (ImageButton) v.findViewById(R.id.info_close);
remove.setVisibility(View.VISIBLE);
remove.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
remove(obj);
removeImpassableRoad(obj);
notifyDataSetChanged();
RoutingHelper rh = app.getRoutingHelper();
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
rh.recalculateRouteDueToSettingsChange();
}
}
});
return v;
}
};
}
Aggregations