Search in sources :

Example 1 with IndexCreator

use of net.osmand.obf.preparation.IndexCreator in project OsmAnd-tools by osmandapp.

the class DownloadOsmGPX method generateObfFile.

private void generateObfFile(QueryParams qp) throws IOException, SQLException, InterruptedException, XmlPullParserException {
    if (qp.obfFile != null) {
        IndexCreatorSettings settings = new IndexCreatorSettings();
        settings.indexMap = true;
        settings.indexAddress = false;
        settings.indexPOI = true;
        settings.indexTransport = false;
        settings.indexRouting = false;
        RTree.clearCache();
        File folder = new File(qp.obfFile.getParentFile(), "gen");
        String fileName = qp.obfFile.getName();
        File targetObf = qp.obfFile;
        try {
            folder.mkdirs();
            IndexCreator ic = new IndexCreator(folder, settings);
            MapRenderingTypesEncoder types = new MapRenderingTypesEncoder(null, fileName);
            ic.setMapFileName(fileName);
            IProgress prog = IProgress.EMPTY_PROGRESS;
            prog = new ConsoleProgressImplementation();
            ic.generateIndexes(qp.osmFile, prog, null, MapZooms.getDefault(), types, null);
            new File(folder, ic.getMapFileName()).renameTo(targetObf);
        } finally {
            Algorithms.removeAllFiles(folder);
        }
    }
}
Also used : IndexCreatorSettings(net.osmand.obf.preparation.IndexCreatorSettings) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) IProgress(net.osmand.IProgress) IndexCreator(net.osmand.obf.preparation.IndexCreator) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation)

Example 2 with IndexCreator

use of net.osmand.obf.preparation.IndexCreator 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();
                IndexCreatorSettings settings = new IndexCreatorSettings() {

                    public String getString(String key) {
                        return Messages.getString(key);
                    }
                };
                settings.indexMap = buildMapIndex.isSelected();
                settings.indexAddress = buildAddressIndex.isSelected();
                settings.indexPOI = buildPoiIndex.isSelected();
                settings.indexTransport = buildTransportIndex.isSelected();
                settings.indexRouting = buildRoutingIndex.isSelected();
                settings.suppressWarningsForDuplicateIds = DataExtractionSettings.getSettings().isSupressWarningsForDuplicatedId();
                settings.houseNameAddAdditionalInfo = DataExtractionSettings.getSettings().isAdditionalInfo();
                settings.houseNumberPreferredOverName = DataExtractionSettings.getSettings().isHousenumberPrefered();
                try {
                    settings.zoomWaySmoothness = Integer.parseInt(DataExtractionSettings.getSettings().getLineSmoothness());
                } catch (NumberFormatException e) {
                }
                IndexCreator creator = new IndexCreator(dir, settings);
                try {
                    String fn = DataExtractionSettings.getSettings().getMapRenderingTypesFile();
                    if (!Algorithms.isEmpty(DataExtractionSettings.getSettings().getPoiTypesFile())) {
                        MapPoiTypes.setDefault(new MapPoiTypes(DataExtractionSettings.getSettings().getPoiTypesFile()));
                    }
                    MapRenderingTypesEncoder types;
                    types = new MapRenderingTypesEncoder(fn, f.getName());
                    RTree.clearCache();
                    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 : IndexCreatorSettings(net.osmand.obf.preparation.IndexCreatorSettings) SQLException(java.sql.SQLException) IndexCreator(net.osmand.obf.preparation.IndexCreator) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) MapPoiTypes(net.osmand.osm.MapPoiTypes) InvocationTargetException(java.lang.reflect.InvocationTargetException) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File) JDialog(javax.swing.JDialog)

Example 3 with IndexCreator

use of net.osmand.obf.preparation.IndexCreator in project OsmAnd-tools by osmandapp.

the class OsmGpxWriteContext method writeObf.

public File writeObf(List<File> files, File tmpFolder, String fileName, File targetObf) throws IOException, SQLException, InterruptedException, XmlPullParserException {
    startDocument();
    for (File gf : files) {
        GPXFile f = GPXUtilities.loadGPXFile(gf);
        GPXTrackAnalysis analysis = f.getAnalysis(gf.lastModified());
        writeTrack(null, null, f, analysis, "GPX");
    }
    endDocument();
    IndexCreatorSettings settings = new IndexCreatorSettings();
    settings.indexMap = true;
    settings.indexAddress = false;
    settings.indexPOI = true;
    settings.indexTransport = false;
    settings.indexRouting = false;
    RTree.clearCache();
    try {
        tmpFolder.mkdirs();
        IndexCreator ic = new IndexCreator(tmpFolder, settings);
        MapRenderingTypesEncoder types = new MapRenderingTypesEncoder(null, fileName);
        ic.setMapFileName(fileName);
        // IProgress.EMPTY_PROGRESS
        IProgress prog = IProgress.EMPTY_PROGRESS;
        // prog = new ConsoleProgressImplementation();
        ic.generateIndexes(qp.osmFile, prog, null, MapZooms.getDefault(), types, null);
        new File(tmpFolder, ic.getMapFileName()).renameTo(targetObf);
    } finally {
        Algorithms.removeAllFiles(tmpFolder);
    }
    return targetObf;
}
Also used : IndexCreatorSettings(net.osmand.obf.preparation.IndexCreatorSettings) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) IProgress(net.osmand.IProgress) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) IndexCreator(net.osmand.obf.preparation.IndexCreator) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile)

Example 4 with IndexCreator

use of net.osmand.obf.preparation.IndexCreator in project OsmAnd-tools by osmandapp.

the class GenerateDailyObf method generateCountry.

public static void generateCountry(String name, File targetObfZip, File[] array, long targetTimestamp, File nodesFile) throws IOException, SQLException, InterruptedException, XmlPullParserException {
    boolean exception = true;
    try {
        RTree.clearCache();
        IndexCreatorSettings settings = new IndexCreatorSettings();
        settings.indexMap = true;
        settings.indexAddress = false;
        settings.indexPOI = true;
        settings.indexTransport = false;
        settings.indexRouting = false;
        settings.generateLowLevel = false;
        IndexCreator ic = new IndexCreator(targetObfZip.getParentFile(), settings);
        ic.setLastModifiedDate(targetTimestamp);
        ic.setDialects(DBDialect.SQLITE, DBDialect.SQLITE_IN_MEMORY);
        ic.setLastModifiedDate(targetTimestamp);
        ic.setRegionName(Algorithms.capitalizeFirstLetterAndLowercase(name));
        ic.setNodesDBFile(nodesFile);
        ic.setDeleteOsmDB(false);
        ic.generateIndexes(array, new ConsoleProgressImplementation(), null, MapZooms.parseZooms("13-14;15-"), new MapRenderingTypesEncoder(name), log, false, true);
        File targetFile = new File(targetObfZip.getParentFile(), ic.getMapFileName());
        targetFile.setLastModified(targetTimestamp);
        FileInputStream fis = new FileInputStream(targetFile);
        GZIPOutputStream gzout = new GZIPOutputStream(new FileOutputStream(targetObfZip));
        Algorithms.streamCopy(fis, gzout);
        fis.close();
        gzout.close();
        targetObfZip.setLastModified(targetTimestamp);
        targetFile.delete();
        exception = false;
    } finally {
        if (exception) {
            nodesFile.delete();
            nodesFile.deleteOnExit();
        }
    }
}
Also used : IndexCreatorSettings(net.osmand.obf.preparation.IndexCreatorSettings) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) IndexCreator(net.osmand.obf.preparation.IndexCreator) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 5 with IndexCreator

use of net.osmand.obf.preparation.IndexCreator in project OsmAnd-tools by osmandapp.

the class TravelGuideCreatorMain method generateTravelGuide.

private void generateTravelGuide(String dir) throws SQLException, IOException, XmlPullParserException, InterruptedException {
    File directory = new File(dir);
    if (!directory.isDirectory()) {
        throw new RuntimeException("Supplied path is not a directory");
    }
    File[] files = directory.listFiles();
    File sqliteFile = new File(directory, TRAVEL_GUIDE_NAME + BINARY_WIKIVOYAGE_MAP_INDEX_EXT);
    Connection conn = DBDialect.SQLITE.getDatabaseConnection(sqliteFile.getCanonicalPath(), LOG);
    if (conn == null) {
        LOG.error("Couldn't establish the database connection");
        System.exit(1);
    }
    Map<String, List<File>> mapping = getFileMapping(files);
    WikivoyageDataGenerator dataGenerator = new WikivoyageDataGenerator();
    generateTravelSqlite(mapping, conn);
    dataGenerator.generateSearchTable(conn);
    createPopularArticlesTable(conn);
    conn.close();
    File osmFile = new File(directory, TRAVEL_GUIDE_NAME + OSM_GZ_EXT);
    WikivoyageGenOSM.genWikivoyageOsm(sqliteFile, osmFile, -1);
    IndexCreatorSettings settings = new IndexCreatorSettings();
    settings.indexPOI = true;
    IndexCreator ic = new IndexCreator(directory, settings);
    ic.setMapFileName(directory.getName() + BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT);
    MapRenderingTypesEncoder types = new MapRenderingTypesEncoder(settings.renderingTypesFile, osmFile.getName());
    ic.generateIndexes(osmFile, new ConsoleProgressImplementation(), null, MapZooms.getDefault(), types, LOG);
    osmFile.delete();
    sqliteFile.delete();
    new File("regions.ocbf").delete();
}
Also used : IndexCreatorSettings(net.osmand.obf.preparation.IndexCreatorSettings) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) Connection(java.sql.Connection) IndexCreator(net.osmand.obf.preparation.IndexCreator) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation)

Aggregations

IndexCreator (net.osmand.obf.preparation.IndexCreator)10 MapRenderingTypesEncoder (net.osmand.osm.MapRenderingTypesEncoder)10 IndexCreatorSettings (net.osmand.obf.preparation.IndexCreatorSettings)9 File (java.io.File)8 ConsoleProgressImplementation (net.osmand.impl.ConsoleProgressImplementation)8 FileOutputStream (java.io.FileOutputStream)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 GPXFile (net.osmand.GPXUtilities.GPXFile)2 IProgress (net.osmand.IProgress)2 FileNotFoundException (java.io.FileNotFoundException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TreeSet (java.util.TreeSet)1 FileHandler (java.util.logging.FileHandler)1 SimpleFormatter (java.util.logging.SimpleFormatter)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1