Search in sources :

Example 31 with RouteDataObject

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);
}
Also used : TLongHashSet(gnu.trove.set.hash.TLongHashSet) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) RouteDataObject(net.osmand.binary.RouteDataObject)

Example 32 with RouteDataObject

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();
    }
}
Also used : Rect(rtree.Rect) RouteWriteContext(net.osmand.data.preparation.IndexRouteCreator.RouteWriteContext) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) BinaryFileReference(net.osmand.data.preparation.BinaryFileReference) SQLException(java.sql.SQLException) RTreeException(rtree.RTreeException) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) RouteDataObject(net.osmand.binary.RouteDataObject) RTree(rtree.RTree) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) LeafElement(rtree.LeafElement)

Example 33 with RouteDataObject

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());
    }
}
Also used : RouteDataObject(net.osmand.binary.RouteDataObject) ApplicationMode(net.osmand.plus.ApplicationMode) Location(net.osmand.Location)

Example 34 with RouteDataObject

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();
        }
    });
}
Also used : LatLon(net.osmand.data.LatLon) RouteDataObject(net.osmand.binary.RouteDataObject) ApplicationMode(net.osmand.plus.ApplicationMode) Location(net.osmand.Location)

Example 35 with RouteDataObject

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;
        }
    };
}
Also used : ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) RoutingHelper(net.osmand.plus.routing.RoutingHelper) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) NonNull(android.support.annotation.NonNull) RouteDataObject(net.osmand.binary.RouteDataObject) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

RouteDataObject (net.osmand.binary.RouteDataObject)49 ArrayList (java.util.ArrayList)13 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)9 Location (net.osmand.Location)9 RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)8 TLongHashSet (gnu.trove.set.hash.TLongHashSet)7 LatLon (net.osmand.data.LatLon)6 IOException (java.io.IOException)5 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)4 QuadPoint (net.osmand.data.QuadPoint)4 File (java.io.File)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)3 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)3 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)3 RoutingConfiguration (net.osmand.router.RoutingConfiguration)3 RoutingContext (net.osmand.router.RoutingContext)3 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 Point (java.awt.Point)2