Search in sources :

Example 71 with BinaryMapIndexReader

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

the class IndexRouteCreator method writeBinaryRouteIndex.

public void writeBinaryRouteIndex(File fl, BinaryMapIndexWriter writer, String regionName, boolean generateLowLevel) throws IOException, SQLException {
    closePreparedStatements(mapRouteInsertStat);
    if (basemapRouteInsertStat != null) {
        closePreparedStatements(basemapRouteInsertStat);
    }
    mapConnection.commit();
    try {
        writer.startWriteRouteIndex(regionName);
        // write map encoding rules
        // save position
        writer.writeRouteEncodingRules(routeTypes.getEncodingRuleTypes());
        RandomAccessFile raf = writer.getRaf();
        writer.flush();
        long fp = raf.getFilePointer();
        // 1st write
        writeRouteSections(writer);
        String fname = null;
        if (baserouteTree != null) {
            // prewrite end of file to read it
            writer.simulateWriteEndRouteIndex();
            writer.preclose();
            writer.flush();
            // use file to recalulate tree
            raf.seek(0);
            appendMissingRoadsForBaseMap(mapConnection, new BinaryMapIndexReader(raf, fl));
            // repack
            fname = baserouteTree.getFileName();
            baserouteTree = packRtreeFile(baserouteTree, fname, fname + "p");
            // seek to previous position
            raf.seek(fp);
            raf.getChannel().truncate(fp);
            // 2nd write
            writeRouteSections(writer);
        }
        writer.endWriteRouteIndex();
        writer.flush();
        if (generateLowLevel) {
            baserouteTree = null;
            new File(fname + "p").delete();
        }
    } catch (RTreeException e) {
        throw new IllegalStateException(e);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) RTreeException(rtree.RTreeException) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 72 with BinaryMapIndexReader

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

the class IconVisibility method compare.

public String compare(String filePath, String renderFilePath) throws IOException {
    File file = new File(filePath);
    RandomAccessFile raf = new RandomAccessFile(file.getAbsolutePath(), "r");
    BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, file);
    RenderingRulesStorage storage = getRenderingStorage(renderFilePath);
    RenderingRuleSearchRequest request = new RenderingRuleSearchRequest(storage);
    initCustomRules(storage, request);
    loadMapObject(reader, request);
    return compareOrder();
}
Also used : RenderingRuleSearchRequest(net.osmand.render.RenderingRuleSearchRequest) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage)

Example 73 with BinaryMapIndexReader

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

the class JUnitRouteTest method setupFiles.

@Before
public void setupFiles() throws IOException {
    if (rs != null) {
        return;
    }
    // test without native because it is not present on the server
    // lib = NativeSwingRendering.getDefaultFromSettings();
    RouteResultPreparation.PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST = true;
    String obfdir = System.getenv("OBF_DIR");
    if (Algorithms.isEmpty(obfdir)) {
        obfdir = DataExtractionSettings.getSettings().getBinaryFilesDir();
    }
    List<File> files = new ArrayList<File>();
    for (File f : new File(obfdir).listFiles()) {
        if (f.getName().endsWith(".obf")) {
            files.add(f);
        }
    }
    rs = new BinaryMapIndexReader[files.size()];
    int it = 0;
    for (File f : files) {
        // $NON-NLS-1$ //$NON-NLS-2$
        RandomAccessFile raf = new RandomAccessFile(f, "r");
        rs[it++] = new BinaryMapIndexReader(raf, f);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) ArrayList(java.util.ArrayList) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Before(org.junit.Before)

Example 74 with BinaryMapIndexReader

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

the class MapRouterLayer method selfRoute.

public List<Entity> selfRoute(LatLon start, LatLon end, List<LatLon> intermediates, boolean gpx, List<RouteSegmentResult> previousRoute, RouteCalculationMode rm) {
    this.gpx = gpx;
    List<Entity> res = new ArrayList<Entity>();
    long time = System.currentTimeMillis();
    final boolean animateRoutingCalculation = DataExtractionSettings.getSettings().isAnimateRouting();
    if (animateRoutingCalculation) {
        nextTurn.setVisible(true);
        playPauseButton.setVisible(true);
        stopButton.setVisible(true);
        pause = true;
        playPauseButton.setText("Play");
    }
    stop = false;
    System.out.println("Self made route from " + start + " to " + end);
    if (start != null && end != null) {
        try {
            BinaryMapIndexReader[] files = DataExtractionSettings.getSettings().getObfReaders();
            if (files.length == 0) {
                JOptionPane.showMessageDialog(OsmExtractionUI.MAIN_APP.getFrame(), "Please specify obf file in settings", "Obf file not found", JOptionPane.ERROR_MESSAGE);
                return null;
            }
            String m = DataExtractionSettings.getSettings().getRouteMode();
            String[] props = m.split("\\,");
            RoutePlannerFrontEnd router = new RoutePlannerFrontEnd();
            Map<String, String> paramsR = new LinkedHashMap<String, String>();
            for (String p : props) {
                if (p.contains("=")) {
                    paramsR.put(p.split("=")[0], p.split("=")[1]);
                } else {
                    paramsR.put(p, "true");
                }
            }
            RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(2000, DEFAULT_NATIVE_MEMORY_LIMIT * 10);
            RoutingConfiguration config = DataExtractionSettings.getSettings().getRoutingConfig().setDirectionPoints(directionPointsFile).build(props[0], /* RoutingConfiguration.DEFAULT_MEMORY_LIMIT */
            memoryLimit, paramsR);
            PrecalculatedRouteDirection precalculatedRouteDirection = null;
            // config.ZOOM_TO_LOAD_TILES = 14;
            try {
                config.routeCalculationTime = new SimpleDateFormat("dd.MM.yyyy HH:mm", Locale.US).parse("19.07.2019 12:40").getTime();
            } catch (Exception e) {
            }
            config.routeCalculationTime = System.currentTimeMillis();
            final RoutingContext ctx = router.buildRoutingContext(config, DataExtractionSettings.getSettings().useNativeRouting() ? NativeSwingRendering.getDefaultFromSettings() : null, files, rm);
            ctx.leftSideNavigation = false;
            ctx.previouslyCalculatedRoute = previousRoute;
            log.info("Use " + config.routerName + " mode for routing");
            final DataTileManager<Entity> points = map.getPoints();
            map.setPoints(points);
            ctx.setVisitor(createSegmentVisitor(animateRoutingCalculation, points));
            // Choose native or not native
            long nt = System.nanoTime();
            startProgressThread(ctx);
            try {
                GpxRouteApproximation gctx = new GpxRouteApproximation(ctx);
                List<GpxPoint> gpxPoints = router.generateGpxPoints(gctx, new LocationsHolder(intermediates));
                List<RouteSegmentResult> searchRoute = gpx ? getGpxAproximation(router, gctx, gpxPoints) : router.searchRoute(ctx, start, end, intermediates, precalculatedRouteDirection);
                throwExceptionIfRouteNotFound(ctx, searchRoute);
                System.out.println("Routing time " + (System.nanoTime() - nt) / 1.0e9f);
                if (animateRoutingCalculation) {
                    playPauseButton.setVisible(false);
                    nextTurn.setText("FINISH");
                    waitNextPress();
                    nextTurn.setText(">>");
                }
                this.previousRoute = searchRoute;
                calculateResult(res, searchRoute);
            } finally {
                if (ctx.calculationProgress != null) {
                    ctx.calculationProgress.isCancelled = true;
                }
            }
        } catch (Exception e) {
            ExceptionHandler.handle(e);
        } finally {
            playPauseButton.setVisible(false);
            nextTurn.setVisible(false);
            stopButton.setVisible(false);
            if (map.getPoints() != null) {
                map.getPoints().clear();
            }
        }
        System.out.println("!!! Finding self route: " + res.size() + " " + (System.currentTimeMillis() - time) + " ms");
    }
    return res;
}
Also used : Entity(net.osmand.osm.edit.Entity) LocationsHolder(net.osmand.LocationsHolder) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint) RoutingMemoryLimits(net.osmand.router.RoutingConfiguration.RoutingMemoryLimits) RoutingContext(net.osmand.router.RoutingContext) GpxRouteApproximation(net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation) RouteSegmentResult(net.osmand.router.RouteSegmentResult) PrecalculatedRouteDirection(net.osmand.router.PrecalculatedRouteDirection) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) JSONException(org.json.JSONException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)74 File (java.io.File)41 RandomAccessFile (java.io.RandomAccessFile)39 ArrayList (java.util.ArrayList)35 IOException (java.io.IOException)23 LinkedHashMap (java.util.LinkedHashMap)11 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)11 List (java.util.List)10 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)10 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)10 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)10 LatLon (net.osmand.data.LatLon)9 RoutingConfiguration (net.osmand.router.RoutingConfiguration)9 FileOutputStream (java.io.FileOutputStream)8 BinaryIndexPart (net.osmand.binary.BinaryIndexPart)8 AddressRegion (net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion)8 PoiRegion (net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)8 HashMap (java.util.HashMap)7 City (net.osmand.data.City)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6