Search in sources :

Example 31 with BinaryMapIndexReader

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

the class IndexUploader method checkfileAndGetDescription.

private String checkfileAndGetDescription(File mainFile) throws OneFileException, IOException, RTreeException {
    String fileName = mainFile.getName();
    boolean srtmFile = mainFile.getName().contains(".srtm");
    boolean roadFile = mainFile.getName().contains(".road");
    boolean wikiFile = mainFile.getName().contains(".wiki");
    boolean tourFile = fileName.endsWith(IndexConstants.TOUR_INDEX_EXT) || fileName.endsWith(IndexConstants.TOUR_INDEX_EXT_ZIP);
    boolean worldFile = fileName.toLowerCase().contains("basemap") || fileName.toLowerCase().contains("world");
    boolean regionFile = !srtmFile && !roadFile && !wikiFile && !tourFile && !worldFile;
    if (srtmFile != this.srtmProcess) {
        return null;
    }
    if (tourFile != this.tourProcess) {
        return null;
    }
    if (roadFile != this.roadProcess) {
        return null;
    }
    if (wikiFile != this.wikiProcess) {
        return null;
    }
    if (regionFile) {
        extractRoadOnlyFile(mainFile, new File(mainFile.getParentFile(), fileName.replace(IndexConstants.BINARY_MAP_INDEX_EXT, IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)));
    }
    if (tourFile) {
        File fl = new File(mainFile, "inventory.xml");
        if (!fl.exists()) {
            System.err.println("inventory.xml doesn't exist " + fl.getAbsolutePath());
            return null;
        }
        try {
            Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(fl);
            return ((Element) doc.getElementsByTagName("shortDescription").item(0)).getTextContent();
        } catch (Exception e) {
            throw new OneFileException("Not supported file format " + fileName, e);
        }
    } else if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) || fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
        RandomAccessFile raf = null;
        try {
            raf = new RandomAccessFile(mainFile, "r");
            BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, mainFile);
            if (reader.getVersion() != IndexConstants.BINARY_MAP_VERSION) {
                throw new OneFileException("Uploader version is not compatible " + reader.getVersion() + " to current " + IndexConstants.BINARY_MAP_VERSION);
            }
            String summary = getDescription(reader, fileName);
            reader.close();
            mainFile.setLastModified(reader.getDateCreated());
            return summary;
        } catch (IOException e) {
            if (raf != null) {
                try {
                    raf.close();
                } catch (IOException e1) {
                }
            }
            throw new OneFileException("Reader could not read the index: " + e.getMessage());
        }
    } else {
        throw new OneFileException("Not supported file format " + fileName);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) LeafElement(rtree.LeafElement) Element(org.w3c.dom.Element) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) IOException(java.io.IOException) Document(org.w3c.dom.Document) RandomAccessFile(java.io.RandomAccessFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) ZipException(java.util.zip.ZipException) FileNotFoundException(java.io.FileNotFoundException) JSchException(com.jcraft.jsch.JSchException) IllegalValueException(rtree.IllegalValueException) RTreeException(rtree.RTreeException) IOException(java.io.IOException)

Example 32 with BinaryMapIndexReader

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

the class ManyToOneRoadCalculation method main.

public static void main(String[] args) throws IOException, InterruptedException {
    File fl = new File("/home/victor/projects/osmand/osm-gen/Netherlands_europe_2.obf");
    // $NON-NLS-1$ //$NON-NLS-2$
    RandomAccessFile raf = new RandomAccessFile(fl, "r");
    BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, fl);
    int zoom = 9;
    double top = 53.2949;
    double bottom = MapUtils.getLatitudeFromTile(zoom, (MapUtils.getTileNumberY(zoom, top) + 1));
    System.out.println(top + " - " + bottom);
    new ManyToOneRoadCalculation().manyToManyCalculation(reader, top, bottom);
}
Also used : RandomAccessFile(java.io.RandomAccessFile) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 33 with BinaryMapIndexReader

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

the class NativeSwingRendering method updateBoundaries.

private void updateBoundaries(File f, String nm) {
    try {
        BinaryMapIndexReader r = new BinaryMapIndexReader(new RandomAccessFile(f, "r"), f);
        try {
            if (r.getMapIndexes().isEmpty() || r.getMapIndexes().get(0).getRoots().isEmpty()) {
                return;
            }
            MapRoot rt = r.getMapIndexes().get(0).getRoots().get(0);
            if (!diffs.containsKey(nm)) {
                MapDiff mm = new MapDiff();
                mm.baseName = nm;
                diffs.put(nm, mm);
            }
            MapDiff dd = diffs.get(nm);
            dd.baseFile = f;
            dd.timestamp = r.getDateCreated();
            dd.bounds = new QuadRect(MapUtils.get31LongitudeX(rt.getLeft()), MapUtils.get31LatitudeY(rt.getTop()), MapUtils.get31LongitudeX(rt.getRight()), MapUtils.get31LatitudeY(rt.getBottom()));
            Iterator<String> iterator = dd.diffs.keySet().iterator();
            while (iterator.hasNext()) {
                dd.selected = iterator.next();
            }
        } finally {
            r.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) MapRoot(net.osmand.binary.BinaryMapIndexReader.MapRoot) IOException(java.io.IOException) QuadRect(net.osmand.data.QuadRect)

Example 34 with BinaryMapIndexReader

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

the class MapClusterLayer method clustering.

private List<RouteSegment> clustering(final ClusteringContext clusterCtx, double lat, double lon, final DataTileManager<Way> points) throws IOException {
    List<BinaryMapIndexReader> rs = new ArrayList<BinaryMapIndexReader>();
    for (File f : new File(DataExtractionSettings.getSettings().getBinaryFilesDir()).listFiles()) {
        if (f.getName().endsWith(".obf")) {
            // $NON-NLS-1$ //$NON-NLS-2$
            RandomAccessFile raf = new RandomAccessFile(f, "r");
            rs.add(new BinaryMapIndexReader(raf, f));
        }
    }
    RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(true);
    Builder builder = RoutingConfiguration.getDefault();
    RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3);
    RoutingContext ctx = router.buildRoutingContext(config, NativeSwingRendering.getDefaultFromSettings(), rs.toArray(new BinaryMapIndexReader[rs.size()]), clusterCtx.BASEMAP_CLUSTERING ? RouteCalculationMode.BASE : RouteCalculationMode.NORMAL);
    // find closest way
    RouteSegment st = router.findRouteSegment(lat, lon, ctx, null);
    if (st != null) {
        RouteDataObject road = st.getRoad();
        String highway = getHighway(road);
        log.info(// road.getName() + " "
        "ROAD TO START " + highway + " " + +road.id);
    }
    map.setPoints(points);
    ctx.setVisitor(new RouteSegmentVisitor() {

        private List<RouteSegment> cache = new ArrayList<RouteSegment>();

        @Override
        public void visitSegment(RouteSegment s, int endSegment, boolean poll) {
            if (!clusterCtx.ANIMATE_CLUSTERING) {
                return;
            }
            cache.add(s);
            if (cache.size() < SIZE_OF_ROUTES_TO_ANIMATE) {
                return;
            }
            for (RouteSegment segment : cache) {
                Way way = new Way(-1);
                for (int i = 0; i < segment.getRoad().getPointsLength(); i++) {
                    net.osmand.osm.edit.Node n = new net.osmand.osm.edit.Node(MapUtils.get31LatitudeY(segment.getRoad().getPoint31YTile(i)), MapUtils.get31LongitudeX(segment.getRoad().getPoint31XTile(i)), -1);
                    way.addNode(n);
                }
                way.putTag("color", "white");
                LatLon n = way.getLatLon();
                points.registerObject(n.getLatitude(), n.getLongitude(), way);
            }
            cache.clear();
            try {
                SwingUtilities.invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        map.prepareImage();
                    }
                });
            } catch (InterruptedException e1) {
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    });
    List<RouteSegment> results = searchCluster(clusterCtx, ctx, st);
    return results;
}
Also used : Builder(net.osmand.router.RoutingConfiguration.Builder) ArrayList(java.util.ArrayList) RouteSegmentVisitor(net.osmand.router.BinaryRoutePlanner.RouteSegmentVisitor) Way(net.osmand.osm.edit.Way) RoutingContext(net.osmand.router.RoutingContext) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) Point(java.awt.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) LatLon(net.osmand.data.LatLon) RandomAccessFile(java.io.RandomAccessFile) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RouteDataObject(net.osmand.binary.RouteDataObject) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 35 with BinaryMapIndexReader

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

the class CombineSRTMIntoFile method main.

public static void main(String[] args) throws IOException {
    File directoryWithSRTMFiles = new File(args[0]);
    File directoryWithTargetFiles = new File(args[1]);
    String ocbfFile = args[2];
    boolean dryRun = true;
    // mauritius
    String filter = null;
    for (int i = 3; i < args.length; i++) {
        if ("--dry-run".equals(args[i])) {
            dryRun = true;
        } else if (args[i].startsWith("--filter")) {
            filter = args[i].substring("--filter".length());
        }
    }
    OsmandRegions or = new OsmandRegions();
    BinaryMapIndexReader fl = or.prepareFile(ocbfFile);
    Map<String, LinkedList<BinaryMapDataObject>> allCountries = or.cacheAllCountries();
    MapIndex mapIndex = fl.getMapIndexes().get(0);
    int srtm = mapIndex.getRule("region_srtm", "yes");
    int downloadName = mapIndex.getRule("download_name", null);
    int boundary = mapIndex.getRule("osmand_region", "boundary");
    int cnt = 1;
    Set<String> failedCountries = new HashSet<String>();
    for (String fullName : allCountries.keySet()) {
        LinkedList<BinaryMapDataObject> lst = allCountries.get(fullName);
        if (fullName == null || (filter != null && !fullName.contains(filter))) {
            continue;
        }
        BinaryMapDataObject rc = null;
        for (BinaryMapDataObject r : lst) {
            if (!r.containsType(boundary)) {
                rc = r;
                break;
            }
        }
        System.out.println(fullName);
        if (rc != null && rc.containsAdditionalType(srtm)) {
            String dw = rc.getNameByType(downloadName);
            System.out.println("Region " + fullName + " " + cnt++ + " out of " + lst.size());
            try {
                process(rc, lst.subList(1, lst.size()), dw, directoryWithSRTMFiles, directoryWithTargetFiles, dryRun);
            } catch (Exception e) {
                failedCountries.add(fullName);
                e.printStackTrace();
            }
        }
    }
    if (!failedCountries.isEmpty()) {
        throw new IllegalStateException("Failed countries " + failedCountries);
    }
}
Also used : BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) LinkedList(java.util.LinkedList) SQLException(java.sql.SQLException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) OsmandRegions(net.osmand.map.OsmandRegions) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)48 File (java.io.File)26 RandomAccessFile (java.io.RandomAccessFile)25 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)16 List (java.util.List)7 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)7 RoutingConfiguration (net.osmand.router.RoutingConfiguration)7 LinkedHashMap (java.util.LinkedHashMap)6 LatLon (net.osmand.data.LatLon)6 HashMap (java.util.HashMap)5 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)5 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)5 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)5 City (net.osmand.data.City)5 RoutingContext (net.osmand.router.RoutingContext)5 Point (java.awt.Point)4 FileOutputStream (java.io.FileOutputStream)4 GeocodingResult (net.osmand.binary.GeocodingUtilities.GeocodingResult)4 TLongHashSet (gnu.trove.set.hash.TLongHashSet)3