Search in sources :

Example 1 with IndexCreatorSettings

use of net.osmand.obf.preparation.IndexCreatorSettings 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 IndexCreatorSettings

use of net.osmand.obf.preparation.IndexCreatorSettings 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 IndexCreatorSettings

use of net.osmand.obf.preparation.IndexCreatorSettings 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 IndexCreatorSettings

use of net.osmand.obf.preparation.IndexCreatorSettings 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 IndexCreatorSettings

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

the class BinaryMerger method combineAddressIndex.

private void combineAddressIndex(String name, BinaryMapIndexWriter writer, AddressRegion[] addressRegions, BinaryMapIndexReader[] indexes) throws IOException {
    IndexCreatorSettings settings = new IndexCreatorSettings();
    Set<String> attributeTagsTableSet = new TreeSet<String>();
    for (int i = 0; i != addressRegions.length; i++) {
        AddressRegion region = addressRegions[i];
        attributeTagsTableSet.addAll(region.getAttributeTagsTable());
    }
    writer.startWriteAddressIndex(name, attributeTagsTableSet);
    List<String> attributeTagsTable = new ArrayList<String>();
    attributeTagsTable.addAll(attributeTagsTableSet);
    Map<String, Integer> tagRules = new HashMap<String, Integer>();
    Map<String, List<MapObject>> namesIndex = new TreeMap<String, List<MapObject>>(Collator.getInstance());
    ListIterator<String> it = attributeTagsTable.listIterator();
    while (it.hasNext()) {
        tagRules.put(it.next(), it.previousIndex());
    }
    for (int type : BinaryMapAddressReaderAdapter.CITY_TYPES) {
        Map<City, BinaryMapIndexReader> cityMap = new HashMap<City, BinaryMapIndexReader>();
        Map<Long, City> cityIds = new HashMap<Long, City>();
        for (int i = 0; i < addressRegions.length; i++) {
            AddressRegion region = addressRegions[i];
            final BinaryMapIndexReader index = indexes[i];
            for (City city : index.getCities(region, null, type)) {
                normalizePostcode(city, extractCountryName(index));
                // probably code to merge cities below is not needed (it called mostly for postcodes)
                if (cityIds.containsKey(city.getId())) {
                    index.preloadStreets(city, null);
                    City city2 = cityIds.get(city.getId());
                    cityMap.get(city2).preloadStreets(city2, null);
                    if (city.getStreets().size() > city2.getStreets().size()) {
                        cityMap.remove(city2);
                        cityIds.put(city.getId(), city);
                        cityMap.put(city, index);
                    }
                } else {
                    cityMap.put(city, index);
                    cityIds.put(city.getId(), city);
                }
            }
        }
        List<City> cities = new ArrayList<City>(cityMap.keySet());
        Map<City, List<City>> mergeCityGroup = new HashMap<City, List<City>>();
        Collections.sort(cities, MapObject.BY_NAME_COMPARATOR);
        mergeCitiesByNameDistance(cities, mergeCityGroup, cityMap, type == BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE);
        List<BinaryFileReference> refs = new ArrayList<BinaryFileReference>();
        // 1. write cities
        writer.startCityBlockIndex(type);
        Map<City, Map<Street, List<Node>>> namesakesStreetNodes = new HashMap<City, Map<Street, List<Node>>>();
        for (int i = 0; i < cities.size(); i++) {
            City city = cities.get(i);
            BinaryMapIndexReader rindex = cityMap.get(city);
            preloadStreetsAndBuildings(rindex, city, namesakesStreetNodes);
            List<City> namesakes = mergeCityGroup.get(city);
            if (namesakes != null) {
                for (City namesake : namesakes) {
                    preloadStreetsAndBuildings(cityMap.get(namesake), namesake, namesakesStreetNodes);
                    city = mergeCities(city, namesake, namesakesStreetNodes);
                }
            }
            int cityType = city.isPostcode() ? -1 : city.getType().ordinal();
            BinaryFileReference ref = writer.writeCityHeader(city, cityType, tagRules);
            refs.add(ref);
            writer.writeCityIndex(city, city.getStreets(), namesakesStreetNodes.get(city), ref, tagRules);
            IndexAddressCreator.putNamedMapObject(namesIndex, city, ref.getStartPointer(), settings);
            if (!city.isPostcode()) {
                for (Street s : city.getStreets()) {
                    IndexAddressCreator.putNamedMapObject(namesIndex, s, s.getFileOffset(), settings);
                }
            }
            city.getStreets().clear();
            namesakesStreetNodes.clear();
        }
        writer.endCityBlockIndex();
    }
    writer.writeAddressNameIndex(namesIndex);
    writer.endWriteAddressIndex();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(net.osmand.osm.edit.Node) ArrayList(java.util.ArrayList) BinaryFileReference(net.osmand.obf.preparation.BinaryFileReference) TreeSet(java.util.TreeSet) Street(net.osmand.data.Street) List(java.util.List) ArrayList(java.util.ArrayList) AddressRegion(net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion) MapObject(net.osmand.data.MapObject) IndexCreatorSettings(net.osmand.obf.preparation.IndexCreatorSettings) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) City(net.osmand.data.City) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Aggregations

IndexCreatorSettings (net.osmand.obf.preparation.IndexCreatorSettings)12 MapRenderingTypesEncoder (net.osmand.osm.MapRenderingTypesEncoder)10 File (java.io.File)9 IndexCreator (net.osmand.obf.preparation.IndexCreator)9 ConsoleProgressImplementation (net.osmand.impl.ConsoleProgressImplementation)7 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 GPXFile (net.osmand.GPXUtilities.GPXFile)2 IProgress (net.osmand.IProgress)2 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 Node (net.osmand.osm.edit.Node)2 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 FileNotFoundException (java.io.FileNotFoundException)1