Search in sources :

Example 1 with MapRenderingTypesEncoder

use of net.osmand.osm.MapRenderingTypesEncoder in project OsmAnd-tools by osmandapp.

the class OsmExtractionUI method loadCountry.

public void loadCountry(final File f, final IOsmStorageFilter filter) {
    try {
        // $NON-NLS-1$
        final ProgressDialog dlg = new ProgressDialog(frame, Messages.getString("OsmExtractionUI.LOADING_OSM_FILE"));
        dlg.setRunnable(new Runnable() {

            @Override
            public void run() {
                File dir = DataExtractionSettings.getSettings().getDefaultWorkingDir();
                IndexCreator creator = new IndexCreator(dir);
                try {
                    creator.setIndexAddress(buildAddressIndex.isSelected());
                    creator.setIndexPOI(buildPoiIndex.isSelected());
                    creator.setIndexTransport(buildTransportIndex.isSelected());
                    creator.setIndexMap(buildMapIndex.isSelected());
                    creator.setIndexRouting(buildRoutingIndex.isSelected());
                    creator.setCityAdminLevel(DataExtractionSettings.getSettings().getCityAdminLevel());
                    String fn = DataExtractionSettings.getSettings().getMapRenderingTypesFile();
                    MapRenderingTypesEncoder types;
                    types = new MapRenderingTypesEncoder(fn, f.getName());
                    RTree.clearCache();
                    int smoothness = 0;
                    try {
                        smoothness = Integer.parseInt(DataExtractionSettings.getSettings().getLineSmoothness());
                    } catch (NumberFormatException e) {
                    }
                    creator.setZoomWaySmoothness(smoothness);
                    creator.generateIndexes(f, dlg, filter, DataExtractionSettings.getSettings().getMapZooms(), types, log);
                } catch (IOException e) {
                    throw new IllegalArgumentException(e);
                } catch (XmlPullParserException e) {
                    throw new IllegalStateException(e);
                } catch (SQLException e) {
                    throw new IllegalStateException(e);
                } catch (InterruptedException e) {
                    throw new IllegalStateException(e);
                }
                regionName = creator.getRegionName();
                StringBuilder msg = new StringBuilder();
                // $NON-NLS-1$ //$NON-NLS-2$
                msg.append(Messages.getString("OsmExtractionUI.INDEXES_FOR")).append(regionName).append(" : ");
                boolean comma = false;
                if (buildMapIndex.isSelected()) {
                    // $NON-NLS-1$
                    if (comma)
                        msg.append(", ");
                    comma = true;
                    // $NON-NLS-1$
                    msg.append(Messages.getString("OsmExtractionUI.MAP"));
                }
                if (buildPoiIndex.isSelected()) {
                    // $NON-NLS-1$
                    if (comma)
                        msg.append(", ");
                    comma = true;
                    // $NON-NLS-1$
                    msg.append(Messages.getString("OsmExtractionUI.POI"));
                }
                if (buildAddressIndex.isSelected()) {
                    // $NON-NLS-1$
                    if (comma)
                        msg.append(", ");
                    comma = true;
                    // $NON-NLS-1$
                    msg.append(Messages.getString("OsmExtractionUI.ADDRESS"));
                }
                if (buildTransportIndex.isSelected()) {
                    // $NON-NLS-1$
                    if (comma)
                        msg.append(", ");
                    comma = true;
                    // $NON-NLS-1$
                    msg.append(Messages.getString("OsmExtractionUI.TRANSPORT"));
                }
                // $NON-NLS-1$
                msg.append(MessageFormat.format(Messages.getString("OsmExtractionUI.WERE_SUCCESFULLY_CREATED"), dir.getAbsolutePath()));
                JOptionPane pane = new JOptionPane(msg);
                // $NON-NLS-1$
                JDialog dialog = pane.createDialog(frame, Messages.getString("OsmExtractionUI.GENERATION_DATA"));
                dialog.setVisible(true);
            }
        });
        dlg.run();
        // $NON-NLS-1$
        frame.setTitle(Messages.getString("OsmExtractionUI.OSMAND_MAP_CREATOR_FILE") + f.getName());
    } catch (InterruptedException e1) {
        // $NON-NLS-1$
        log.error("Interrupted", e1);
    } catch (InvocationTargetException e1) {
        // $NON-NLS-1$
        ExceptionHandler.handle("Exception during operation", e1.getCause());
    }
}
Also used : SQLException(java.sql.SQLException) IndexCreator(net.osmand.data.preparation.IndexCreator) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) InvocationTargetException(java.lang.reflect.InvocationTargetException) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) JDialog(javax.swing.JDialog)

Example 2 with MapRenderingTypesEncoder

use of net.osmand.osm.MapRenderingTypesEncoder 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 3 with MapRenderingTypesEncoder

use of net.osmand.osm.MapRenderingTypesEncoder 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 MapRenderingTypesEncoder

use of net.osmand.osm.MapRenderingTypesEncoder 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 MapRenderingTypesEncoder

use of net.osmand.osm.MapRenderingTypesEncoder 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

MapRenderingTypesEncoder (net.osmand.osm.MapRenderingTypesEncoder)17 File (java.io.File)16 ConsoleProgressImplementation (net.osmand.impl.ConsoleProgressImplementation)10 RandomAccessFile (java.io.RandomAccessFile)7 FileOutputStream (java.io.FileOutputStream)6 IndexCreator (net.osmand.data.preparation.IndexCreator)6 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 MapZooms (net.osmand.binary.MapZooms)4 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)3 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)2 Amenity (net.osmand.data.Amenity)2 IndexPoiCreator (net.osmand.data.preparation.IndexPoiCreator)2 Entity (net.osmand.osm.edit.Entity)2