Search in sources :

Example 1 with ConsoleProgressImplementation

use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.

the class IndexCreator method main.

public static void main(String[] args) throws IOException, SQLException, InterruptedException, XmlPullParserException {
    long time = System.currentTimeMillis();
    // if(true){ generateRegionsFile(); return;}
    String rootFolder = "/Users/victorshcherb/osmand/";
    IndexPoiCreator.ZIP_LONG_STRINGS = false;
    // $NON-NLS-1$
    IndexCreator creator = new IndexCreator(new File(rootFolder + "/maps/"));
    creator.setIndexMap(true);
    // creator.setIndexAddress(true);
    creator.setIndexPOI(true);
    // creator.setIndexTransport(true);
    creator.setIndexRouting(true);
    // creator.deleteDatabaseIndexes = false;
    // creator.recreateOnlyBinaryFile = true;
    // creator.deleteOsmDB = false;
    creator.setZoomWaySmoothness(2);
    // MapZooms.parseZooms("15-");
    MapZooms zooms = MapZooms.getDefault();
    String file = rootFolder + "/temp/map.osm";
    // String file = rootFolder + "/temp/ukraine_kiev-city_europe.pbf";
    // String file = rootFolder + "/maps/diff/2017_08_28_00_30_before.osm";
    // String file = rootFolder + "/maps/diff/ukraine_kiev-city_europe.pbf";
    // String file = rootFolder + "/repos/resources/test-resources/synthetic_test_rendering.osm";
    int st = file.lastIndexOf('/');
    int e = file.indexOf('.', st);
    creator.setNodesDBFile(new File(rootFolder + "/maps/" + file.substring(st, e) + ".tmp.odb"));
    creator.setSRTMData(new File(rootFolder + "/maps/srtm/"));
    MapPoiTypes.setDefault(new MapPoiTypes(rootFolder + "/repos//resources/poi/poi_types.xml"));
    MapRenderingTypesEncoder rt = new MapRenderingTypesEncoder(rootFolder + "/repos//resources/obf_creation/rendering_types.xml", new File(file).getName());
    creator.setLastModifiedDate(1504224000000l);
    creator.generateIndexes(new File(file), new ConsoleProgressImplementation(1), null, zooms, rt, log);
    // new File(file),
    // $NON-NLS-1$
    log.info("WHOLE GENERATION TIME :  " + (System.currentTimeMillis() - time));
    // $NON-NLS-1$ //$NON-NLS-2$
    log.info("COORDINATES_SIZE " + BinaryMapIndexWriter.COORDINATES_SIZE + " count " + BinaryMapIndexWriter.COORDINATES_COUNT);
    // $NON-NLS-1$
    log.info("TYPES_SIZE " + BinaryMapIndexWriter.TYPES_SIZE);
    // $NON-NLS-1$
    log.info("ID_SIZE " + BinaryMapIndexWriter.ID_SIZE);
    // $NON-NLS-1$
    log.info("- COORD_TYPES_ID SIZE " + (BinaryMapIndexWriter.COORDINATES_SIZE + BinaryMapIndexWriter.TYPES_SIZE + BinaryMapIndexWriter.ID_SIZE));
    // $NON-NLS-1$
    log.info("- MAP_DATA_SIZE " + BinaryMapIndexWriter.MAP_DATA_SIZE);
    // $NON-NLS-1$
    log.info("- STRING_TABLE_SIZE " + BinaryMapIndexWriter.STRING_TABLE_SIZE);
    // $NON-NLS-1$
    log.info("-- MAP_DATA_AND_STRINGS SIZE " + (BinaryMapIndexWriter.MAP_DATA_SIZE + BinaryMapIndexWriter.STRING_TABLE_SIZE));
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) MapZooms(net.osmand.binary.MapZooms) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) MapPoiTypes(net.osmand.osm.MapPoiTypes)

Example 2 with ConsoleProgressImplementation

use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.

the class IndexPoiCreator method processPOIIntoTree.

private void processPOIIntoTree(Map<String, Set<PoiTileBox>> namesIndex, int zoomToStart, IntBbox bbox, Tree<PoiTileBox> rootZoomsTree) throws SQLException {
    ResultSet rs;
    if (useInMemoryCreator) {
        rs = poiConnection.createStatement().executeQuery("SELECT x,y,type,subtype,id,additionalTags from poi");
    } else {
        rs = poiConnection.createStatement().executeQuery("SELECT x,y,type,subtype from poi");
    }
    rootZoomsTree.setNode(new PoiTileBox());
    int count = 0;
    ConsoleProgressImplementation console = new ConsoleProgressImplementation();
    console.startWork(1000000);
    Map<PoiAdditionalType, String> additionalTags = new LinkedHashMap<PoiAdditionalType, String>();
    PoiAdditionalType nameRuleType = retrieveAdditionalType("name");
    PoiAdditionalType nameEnRuleType = retrieveAdditionalType("name:en");
    while (rs.next()) {
        int x = rs.getInt(1);
        int y = rs.getInt(2);
        bbox.minX = Math.min(x, bbox.minX);
        bbox.maxX = Math.max(x, bbox.maxX);
        bbox.minY = Math.min(y, bbox.minY);
        bbox.maxY = Math.max(y, bbox.maxY);
        if (count++ > 10000) {
            count = 0;
            console.progress(10000);
        }
        String type = rs.getString(3);
        String subtype = rs.getString(4);
        decodeAdditionalInfo(rs.getString(6), additionalTags);
        Tree<PoiTileBox> prevTree = rootZoomsTree;
        rootZoomsTree.getNode().categories.addCategory(type, subtype, additionalTags);
        for (int i = zoomToStart; i <= ZOOM_TO_SAVE_END; i++) {
            int xs = x >> (31 - i);
            int ys = y >> (31 - i);
            Tree<PoiTileBox> subtree = null;
            for (Tree<PoiTileBox> sub : prevTree.getSubtrees()) {
                if (sub.getNode().x == xs && sub.getNode().y == ys && sub.getNode().zoom == i) {
                    subtree = sub;
                    break;
                }
            }
            if (subtree == null) {
                subtree = new Tree<PoiTileBox>();
                PoiTileBox poiBox = new PoiTileBox();
                subtree.setNode(poiBox);
                poiBox.x = xs;
                poiBox.y = ys;
                poiBox.zoom = i;
                prevTree.addSubTree(subtree);
            }
            subtree.getNode().categories.addCategory(type, subtype, additionalTags);
            prevTree = subtree;
        }
        Set<String> otherNames = null;
        Iterator<Entry<PoiAdditionalType, String>> it = additionalTags.entrySet().iterator();
        while (it.hasNext()) {
            Entry<PoiAdditionalType, String> e = it.next();
            if (e.getKey().getTag().contains("name") && !"name:en".equals(e.getKey().getTag())) {
                if (otherNames == null) {
                    otherNames = new TreeSet<String>();
                }
                otherNames.add(e.getValue());
            }
        }
        addNamePrefix(additionalTags.get(nameRuleType), additionalTags.get(nameEnRuleType), prevTree.getNode(), namesIndex, otherNames);
        if (useInMemoryCreator) {
            if (prevTree.getNode().poiData == null) {
                prevTree.getNode().poiData = new ArrayList<PoiData>();
            }
            PoiData poiData = new PoiData();
            poiData.x = x;
            poiData.y = y;
            poiData.type = type;
            poiData.subtype = subtype;
            poiData.id = rs.getLong(5);
            poiData.additionalTags.putAll(additionalTags);
            prevTree.getNode().poiData.add(poiData);
        }
    }
    log.info("Poi processing finished");
}
Also used : ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) ResultSet(java.sql.ResultSet)

Example 3 with ConsoleProgressImplementation

use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.

the class ObfChangesCreator method createObfFiles.

private void createObfFiles(File country, GroupFiles g) throws Exception {
    File obf = g.getObfFileName(country);
    if (!obf.exists() || g.getTimestamp() - obf.lastModified() > 1000) {
        if (obf.exists()) {
            log.info("The file " + obf.getName() + " was updated for " + (g.getTimestamp() - obf.lastModified()) / 1000 + " seconds");
        } else {
            log.info("The file " + obf.getName() + " doesn't exist");
        }
        RTree.clearCache();
        IndexCreator ic = new IndexCreator(country);
        ic.setIndexAddress(false);
        ic.setBackwardCompatibleIds(true);
        ic.setIndexPOI(true);
        ic.setIndexRouting(true);
        ic.setIndexMap(true);
        ic.setGenerateLowLevelIndexes(false);
        ic.setDialects(DBDialect.SQLITE_IN_MEMORY, DBDialect.SQLITE_IN_MEMORY);
        ic.setLastModifiedDate(g.getTimestamp());
        File tmpFile = new File(g.dayName + ".tmp.odb");
        tmpFile.delete();
        ic.setRegionName(Algorithms.capitalizeFirstLetterAndLowercase(g.dayName));
        ic.setNodesDBFile(tmpFile);
        log.info("Processing " + g.dayName + " " + g.osmGzFiles.size() + " files");
        ic.generateIndexes(g.getSortedFiles(), new ConsoleProgressImplementation(), null, MapZooms.parseZooms("13-14;15-"), new MapRenderingTypesEncoder(country.getName()), log, false, true);
        File targetFile = new File(country, ic.getMapFileName());
        targetFile.setLastModified(g.getTimestamp());
        FileInputStream fis = new FileInputStream(targetFile);
        GZIPOutputStream gzout = new GZIPOutputStream(new FileOutputStream(obf));
        Algorithms.streamCopy(fis, gzout);
        fis.close();
        gzout.close();
        obf.setLastModified(g.getTimestamp());
        targetFile.delete();
    }
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) FileInputStream(java.io.FileInputStream)

Example 4 with ConsoleProgressImplementation

use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.

the class BasemapProcessor method main.

public static void main(String[] p) throws InterruptedException, SQLException, IOException, XMLStreamException, XmlPullParserException {
    if (p.length == 0) {
        System.out.println("Please specify folder with basemap *.osm or *.osm.bz2 files");
    } else {
        boolean mini = false;
        long time = System.currentTimeMillis();
        MapRenderingTypesEncoder rt = new MapRenderingTypesEncoder("basemap");
        // BASEMAP generation
        File folder = new File(p[0]);
        if (p.length >= 2 && p[1].equals("mini")) {
            mini = true;
        }
        // MapZooms zooms = MapZooms.parseZooms("1-2;3;4-5;6-7;8-9;10-");
        int zoomSmoothness = mini ? 2 : 2;
        MapZooms zooms = mini ? MapZooms.parseZooms("1-2;3;4-5;6-") : MapZooms.parseZooms("1-2;3;4-5;6-7;8;9-");
        MOST_DETAILED_APPROXIMATION = mini ? 6 : 11;
        // $NON-NLS-1$
        IndexCreator creator = new IndexCreator(folder);
        creator.setDialects(DBDialect.SQLITE_IN_MEMORY, DBDialect.SQLITE_IN_MEMORY);
        creator.setIndexMap(true);
        creator.setIndexPOI(mini ? false : true);
        creator.setZoomWaySmoothness(zoomSmoothness);
        creator.setMapFileName(mini ? "World_basemap_mini_test_2.obf" : "World_basemap_2.obf");
        ArrayList<File> src = new ArrayList<File>();
        for (File f : folder.listFiles()) {
            if (f.getName().endsWith(".osm") || f.getName().endsWith(".osm.bz2")) {
                src.add(f);
            }
        }
        // BASEMAP generation
        // creator.generateBasemapIndex(new ConsoleProgressImplementation(1), null, zooms, rt, log, "basemap",
        // new File(basemapParent, "10m_coastline_out_fix_caspean_arctic.osm")
        // ,new File(basemapParent, "roads_gen.osm")
        // ,new File(basemapParent, "10m_admin_level.osm")
        // ,new File(basemapParent, "10m_rivers.osm")
        // ,new File(basemapParent, "10m_lakes.osm")
        // ,new File(basemapParent, "10m_populated_places.osm")
        // );
        creator.generateBasemapIndex(new ConsoleProgressImplementation(1), null, zooms, rt, log, "basemap", src.toArray(new File[src.size()]));
    }
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) MapZooms(net.osmand.binary.MapZooms) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation)

Example 5 with ConsoleProgressImplementation

use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.

the class WikipediaByCountryDivider method generateObf.

private static void generateObf(File osmBz2, File obf) throws IOException, SQLException, InterruptedException, XmlPullParserException {
    IndexPoiCreator.ZIP_LONG_STRINGS = true;
    // be independent of previous results
    RTree.clearCache();
    // $NON-NLS-1$
    IndexCreator creator = new IndexCreator(obf.getParentFile());
    new File(obf.getParentFile(), IndexCreator.TEMP_NODES_DB).delete();
    creator.setIndexMap(false);
    creator.setIndexAddress(false);
    creator.setIndexPOI(true);
    creator.setIndexTransport(false);
    creator.setIndexRouting(false);
    creator.setMapFileName(obf.getName());
    creator.generateIndexes(osmBz2, new ConsoleProgressImplementation(1), null, MapZooms.getDefault(), new MapRenderingTypesEncoder(obf.getName()), log);
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) IndexCreator(net.osmand.data.preparation.IndexCreator) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation)

Aggregations

ConsoleProgressImplementation (net.osmand.impl.ConsoleProgressImplementation)16 File (java.io.File)10 MapRenderingTypesEncoder (net.osmand.osm.MapRenderingTypesEncoder)10 FileInputStream (java.io.FileInputStream)8 FileOutputStream (java.io.FileOutputStream)8 IndexCreator (net.osmand.data.preparation.IndexCreator)5 OsmBaseStorage (net.osmand.osm.io.OsmBaseStorage)5 MapZooms (net.osmand.binary.MapZooms)4 LatLon (net.osmand.data.LatLon)4 OsmStorageWriter (net.osmand.osm.io.OsmStorageWriter)4 LinkedHashMap (java.util.LinkedHashMap)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 Entity (net.osmand.osm.edit.Entity)3 EntityId (net.osmand.osm.edit.Entity.EntityId)3 Node (net.osmand.osm.edit.Node)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 RandomAccessFile (java.io.RandomAccessFile)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2