Search in sources :

Example 6 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project OsmAnd-tools by osmandapp.

the class MapClusterLayer method searchCluster.

private List<RouteSegment> searchCluster(ClusteringContext cCtx, RoutingContext ctx, RouteSegment st) throws IOException {
    List<RouteSegment> result = new ArrayList<BinaryRoutePlanner.RouteSegment>();
    TLongHashSet visitedIds = new TLongHashSet();
    RouteDataObject startRoad = st.getRoad();
    final int stx = startRoad.getPoint31XTile(st.getSegmentStart());
    final int sty = startRoad.getPoint31YTile(st.getSegmentStart());
    int tileX = startRoad.getPoint31XTile(st.getSegmentStart()) >> cCtx.zm;
    int tileY = startRoad.getPoint31YTile(st.getSegmentStart()) >> cCtx.zm;
    Queue<RouteSegment> queue = new PriorityQueue<RouteSegment>(50, new Comparator<RouteSegment>() {

        @Override
        public int compare(RouteSegment o1, RouteSegment o2) {
            double d1 = MapUtils.squareDist31TileMetric(stx, sty, o1.getRoad().getPoint31XTile(o1.getSegmentStart()), o1.getRoad().getPoint31YTile(o1.getSegmentStart()));
            double d2 = MapUtils.squareDist31TileMetric(stx, sty, o2.getRoad().getPoint31XTile(o2.getSegmentStart()), o2.getRoad().getPoint31YTile(o2.getSegmentStart()));
            return Double.compare(d1, d2);
        }
    });
    queue.add(st);
    while (!queue.isEmpty()) {
        RouteSegment segment = queue.poll();
        if (visitedIds.contains(calculateId(segment))) {
            // System.out.println("contains " + segment.getRoad());
            continue;
        }
        // System.out.println(segment.getRoad());
        visitedIds.add(calculateId(segment));
        // Visualization of steps !
        if (ctx.getVisitor() != null) {
            ctx.getVisitor().visitSegment(segment, -1, true);
        }
        cCtx.roadProcessed++;
        if (cCtx.roadProcessed > 50) {
            float ratio = (float) (queue.size() + cCtx.outOfTile + cCtx.outOfDistance) / cCtx.segmentsProcessed;
            if (ratio < cCtx.minRatio) {
                cCtx.minRatio = ratio;
                cCtx.roadMinProcessed = cCtx.roadProcessed;
            }
        }
        processSegment(cCtx, ctx, segment, queue, result, tileX, tileY, true);
        processSegment(cCtx, ctx, segment, queue, result, tileX, tileY, false);
    }
    System.out.println("Current ratio " + ((float) (queue.size() + cCtx.outOfTile + cCtx.outOfDistance) / cCtx.segmentsProcessed) + " min ratio " + cCtx.minRatio + " min segments procesed " + cCtx.roadMinProcessed);
    String res = "Processed " + cCtx.roadProcessed + " / " + cCtx.segmentsProcessed + " and borders are " + (cCtx.outOfTile + cCtx.outOfDistance) + " out because of distance " + cCtx.outOfDistance;
    log.info(res);
    return result;
}
Also used : BinaryRoutePlanner(net.osmand.router.BinaryRoutePlanner) ArrayList(java.util.ArrayList) PriorityQueue(java.util.PriorityQueue) Point(java.awt.Point) TLongHashSet(gnu.trove.set.hash.TLongHashSet) RouteDataObject(net.osmand.binary.RouteDataObject) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Example 7 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project OsmAnd-tools by osmandapp.

the class ObfDiffGenerator method generateDeletedRouteObject.

private RouteDataObject generateDeletedRouteObject(RouteRegion ri, int deleteId, RouteDataObject objS) {
    RouteDataObject rdo = new RouteDataObject(ri);
    rdo.id = objS.id;
    rdo.pointsX = objS.pointsX;
    rdo.pointsY = objS.pointsY;
    rdo.types = new int[] { deleteId };
    return rdo;
}
Also used : RouteDataObject(net.osmand.binary.RouteDataObject)

Example 8 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project OsmAnd-tools by osmandapp.

the class ObfDiffGenerator method compareRouteData.

private void compareRouteData(ObfFileInMemory fStart, ObfFileInMemory fEnd, boolean print, Set<EntityId> modifiedObjIds) {
    RouteRegion ri = fEnd.getRouteIndex();
    int deleteId = ri.searchRouteEncodingRule(OSMAND_CHANGE_TAG, OSMAND_CHANGE_VALUE);
    if (deleteId == -1) {
        deleteId = ri.routeEncodingRules.size();
        if (deleteId == 0) {
            deleteId = 1;
        }
        ri.initRouteEncodingRule(deleteId, OSMAND_CHANGE_TAG, OSMAND_CHANGE_VALUE);
    }
    TLongObjectHashMap<RouteDataObject> startData = fStart.getRoutingData();
    TLongObjectHashMap<RouteDataObject> endData = fEnd.getRoutingData();
    if (endData == null) {
        return;
    }
    for (Long idx : startData.keys()) {
        RouteDataObject objE = endData.get(idx);
        RouteDataObject objS = startData.get(idx);
        if (print) {
            if (objE == null) {
                System.out.println("Route " + idx + " is missing in (2): " + objS);
            } else {
                if (!objE.compareRoute(objS)) {
                    System.out.println("Route " + idx + " is not equal: " + objS + " != " + objE);
                }
                endData.remove(idx);
            }
        } else {
            if (objE == null) {
                EntityId wayId = new EntityId(EntityType.WAY, idx >> (BinaryInspector.SHIFT_ID));
                if (modifiedObjIds == null || modifiedObjIds.contains(wayId)) {
                    RouteDataObject rdo = generateDeletedRouteObject(ri, deleteId, objS);
                    endData.put(idx, rdo);
                }
            } else if (objE.compareRoute(objS)) {
                endData.remove(idx);
            }
        }
    }
    if (print) {
        for (RouteDataObject e : endData.valueCollection()) {
            System.out.println("Route " + e.getId() + " is missing in (1): " + e);
        }
    }
}
Also used : EntityId(net.osmand.osm.edit.Entity.EntityId) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RouteDataObject(net.osmand.binary.RouteDataObject)

Example 9 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project OsmAnd-tools by osmandapp.

the class ObfRegionSplitter method split.

private void split(String[] args) throws IOException {
    File worldObf = new File(args[0]);
    File ocbfFile = new File(args[2]);
    File dir = new File(args[1]);
    String subFolder = args.length > 3 ? args[3] : "";
    String fileSuffix = args.length > 4 ? args[4] : "";
    if (!worldObf.exists() || !ocbfFile.exists()) {
        System.out.println("Incorrect file!");
        System.exit(1);
    }
    if (!dir.exists()) {
        dir.mkdir();
    }
    try {
        ObfFileInMemory fl = new ObfFileInMemory();
        fl.readObfFiles(Collections.singletonList(worldObf));
        OsmandRegions osmandRegions = new OsmandRegions();
        osmandRegions.prepareFile(ocbfFile.getAbsolutePath());
        osmandRegions.cacheAllCountries();
        Map<String, Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>>> regionsMapData = splitRegionMapData(fl, osmandRegions);
        Map<String, TLongObjectHashMap<RouteDataObject>> regionsRouteData = splitRegionRouteData(fl, osmandRegions);
        Map<String, TLongObjectHashMap<Map<String, Amenity>>> regionsPoiData = splitRegionPoiData(fl, osmandRegions);
        TreeSet<String> regionNames = new TreeSet<>();
        regionNames.addAll(regionsMapData.keySet());
        regionNames.addAll(regionsRouteData.keySet());
        for (String regionName : regionNames) {
            File folder = new File(dir, regionName);
            if (!Algorithms.isEmpty(subFolder)) {
                folder = new File(folder, subFolder);
            }
            folder.mkdirs();
            File result = new File(folder, Algorithms.capitalizeFirstLetter(regionName) + fileSuffix + ".obf.gz");
            ObfFileInMemory obf = new ObfFileInMemory();
            Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>> mp = regionsMapData.get(regionName);
            if (mp != null) {
                for (MapZoomPair mzPair : mp.keySet()) {
                    obf.putMapObjects(mzPair, mp.get(mzPair).valueCollection(), true);
                }
            }
            TLongObjectHashMap<RouteDataObject> ro = regionsRouteData.get(regionName);
            if (ro != null) {
                obf.putRoutingData(ro, true);
            }
            TLongObjectHashMap<Map<String, Amenity>> poi = regionsPoiData.get(regionName);
            if (poi != null) {
                obf.putPoiData(poi, true);
            }
            // TODO split Transport
            obf.updateTimestamp(fl.getTimestamp());
            obf.writeFile(result, true);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : Amenity(net.osmand.data.Amenity) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) IOException(java.io.IOException) MapZoomPair(net.osmand.binary.MapZooms.MapZoomPair) OsmandRegions(net.osmand.map.OsmandRegions) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TreeSet(java.util.TreeSet) RouteDataObject(net.osmand.binary.RouteDataObject) File(java.io.File) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) Map(java.util.Map)

Example 10 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project OsmAnd-tools by osmandapp.

the class ObfRegionSplitter method splitRegionRouteData.

private Map<String, TLongObjectHashMap<RouteDataObject>> splitRegionRouteData(ObfFileInMemory fl, OsmandRegions osmandRegions) throws IOException {
    Map<String, TLongObjectHashMap<RouteDataObject>> result = new HashMap<>();
    TLongObjectHashMap<RouteDataObject> routingData = fl.getRoutingData();
    for (RouteDataObject obj : routingData.valueCollection()) {
        // if(obj.getPointsLength() == 0) {
        // continue;
        // }
        int x = obj.getPoint31XTile(0);
        int y = obj.getPoint31YTile(0);
        List<BinaryMapDataObject> l = osmandRegions.query(x, y);
        for (BinaryMapDataObject b : l) {
            if (osmandRegions.contain(b, x, y)) {
                String dw = osmandRegions.getDownloadName(b);
                WorldRegion wr = osmandRegions.getRegionDataByDownloadName(dw);
                if (dw == null || wr == null) {
                    continue;
                }
                if (!Algorithms.isEmpty(dw) && wr.isRegionMapDownload()) {
                    TLongObjectHashMap<RouteDataObject> mp = result.get(dw);
                    if (mp == null) {
                        mp = new TLongObjectHashMap<>();
                        result.put(dw, mp);
                    }
                    mp.put(obj.getId(), obj);
                }
            }
        }
    }
    return result;
}
Also used : WorldRegion(net.osmand.map.WorldRegion) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) RouteDataObject(net.osmand.binary.RouteDataObject)

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