Search in sources :

Example 1 with IndexCreator

use of net.osmand.data.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();
                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 IndexCreator

use of net.osmand.data.preparation.IndexCreator 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)

Example 3 with IndexCreator

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

the class CountryOcbfGeneration method createFile.

private void createFile(CountryRegion global, Map<String, Set<TranslateEntity>> translates, Map<String, File> polygonFiles, String targetObf, String targetOsmXml) throws IOException, SQLException, InterruptedException, XmlPullParserException {
    File osm = new File(targetOsmXml);
    XmlSerializer serializer = new org.kxml2.io.KXmlSerializer();
    FileOutputStream fous = new FileOutputStream(osm);
    serializer.setOutput(fous, "UTF-8");
    serializer.startDocument("UTF-8", true);
    serializer.startTag(null, "osm");
    serializer.attribute(null, "version", "0.6");
    serializer.attribute(null, "generator", "OsmAnd");
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    for (CountryRegion r : global.children) {
        r.parent = null;
        processRegion(r, translates, polygonFiles, targetObf, targetOsmXml, "", serializer);
    }
    serializer.endDocument();
    serializer.flush();
    fous.close();
    // $NON-NLS-1$
    IndexCreator creator = new IndexCreator(new File(targetObf).getParentFile());
    creator.setMapFileName(new File(targetObf).getName());
    creator.setIndexMap(true);
    creator.setIndexAddress(false);
    creator.setIndexPOI(false);
    creator.setIndexTransport(false);
    creator.setIndexRouting(false);
    MapZooms zooms = MapZooms.parseZooms("5-6");
    creator.generateIndexes(osm, new ConsoleProgressImplementation(1), null, zooms, new MapRenderingTypesEncoder("regions"), log);
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) FileOutputStream(java.io.FileOutputStream) MapZooms(net.osmand.binary.MapZooms) IndexCreator(net.osmand.data.preparation.IndexCreator) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 4 with IndexCreator

use of net.osmand.data.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();
        IndexCreator ic = new IndexCreator(targetObfZip.getParentFile());
        ic.setIndexAddress(false);
        ic.setIndexPOI(true);
        ic.setIndexRouting(true);
        ic.setIndexMap(true);
        ic.setLastModifiedDate(targetTimestamp);
        ic.setGenerateLowLevelIndexes(false);
        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 : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) IndexCreator(net.osmand.data.preparation.IndexCreator) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 5 with IndexCreator

use of net.osmand.data.preparation.IndexCreator in project wikivoyage-listings by baturin.

the class OBF method createObf.

public static void createObf(String outputFilename, String workingDir, String mapFile) throws IOException, SAXException, SQLException, InterruptedException {
    IndexCreator creator = new IndexCreator(new File(workingDir));
    creator.setMapFileName(mapFile);
    creator.setIndexPOI(true);
    creator.generateIndexes(new File(outputFilename), IProgress.EMPTY_PROGRESS, null, null, null, null);
}
Also used : IndexCreator(net.osmand.data.preparation.IndexCreator) File(java.io.File)

Aggregations

File (java.io.File)8 IndexCreator (net.osmand.data.preparation.IndexCreator)8 MapRenderingTypesEncoder (net.osmand.osm.MapRenderingTypesEncoder)6 ConsoleProgressImplementation (net.osmand.impl.ConsoleProgressImplementation)5 FileOutputStream (java.io.FileOutputStream)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 FileNotFoundException (java.io.FileNotFoundException)1 RandomAccessFile (java.io.RandomAccessFile)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 FileHandler (java.util.logging.FileHandler)1 SimpleFormatter (java.util.logging.SimpleFormatter)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 JDialog (javax.swing.JDialog)1 JOptionPane (javax.swing.JOptionPane)1