Search in sources :

Example 11 with IndexCreatorSettings

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

the class BinaryMerger method combinePoiIndex.

private void combinePoiIndex(String name, BinaryMapIndexWriter writer, long dateCreated, PoiRegion[] poiRegions, BinaryMapIndexReader[] indexes) throws IOException, SQLException {
    final int[] writtenPoiCount = { 0 };
    MapRenderingTypesEncoder renderingTypes = new MapRenderingTypesEncoder(null, name);
    boolean overwriteIds = false;
    IndexCreatorSettings settings = new IndexCreatorSettings();
    settings.indexPOI = true;
    final IndexPoiCreator indexPoiCreator = new IndexPoiCreator(settings, renderingTypes, overwriteIds);
    indexPoiCreator.createDatabaseStructure(new File(new File(System.getProperty("user.dir")), IndexCreator.getPoiFileName(name)));
    final Map<Long, List<Amenity>> amenityRelations = new HashMap<Long, List<Amenity>>();
    final TLongHashSet set = new TLongHashSet();
    final long[] generatedRelationId = { -1 };
    for (int i = 0; i < poiRegions.length; i++) {
        BinaryMapIndexReader index = indexes[i];
        final TLongHashSet file = new TLongHashSet();
        log.info("Region: " + extractRegionName(index));
        index.searchPoi(BinaryMapIndexReader.buildSearchPoiRequest(0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, -1, BinaryMapIndexReader.ACCEPT_ALL_POI_TYPE_FILTER, new ResultMatcher<Amenity>() {

            @Override
            public boolean publish(Amenity amenity) {
                try {
                    boolean isRelation = amenity.getId() < 0;
                    if (isRelation) {
                        long j = latlon(amenity);
                        List<Amenity> list;
                        if (!amenityRelations.containsKey(j)) {
                            list = new ArrayList<Amenity>(1);
                            amenityRelations.put(j, list);
                        } else {
                            list = amenityRelations.get(j);
                        }
                        boolean unique = true;
                        for (Amenity a : list) {
                            if (a.getType() == amenity.getType() && Algorithms.objectEquals(a.getSubType(), amenity.getSubType())) {
                                unique = false;
                                break;
                            }
                        }
                        if (unique) {
                            amenity.setId(generatedRelationId[0]--);
                            amenityRelations.get(j).add(amenity);
                            indexPoiCreator.insertAmenityIntoPoi(amenity);
                            writtenPoiCount[0]++;
                        }
                    } else {
                        if (!set.contains(amenity.getId())) {
                            file.add(amenity.getId());
                            indexPoiCreator.insertAmenityIntoPoi(amenity);
                            writtenPoiCount[0]++;
                        }
                    }
                    return false;
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public boolean isCancelled() {
                return false;
            }
        }));
        set.addAll(file);
    }
    indexPoiCreator.writeBinaryPoiIndex(writer, name, null);
    indexPoiCreator.commitAndClosePoiFile(dateCreated);
    // REMOVE_POI_DB = false;
    if (REMOVE_POI_DB) {
        indexPoiCreator.removePoiFile();
    }
    log.info("Written " + writtenPoiCount[0] + " POI.");
}
Also used : Amenity(net.osmand.data.Amenity) IndexCreatorSettings(net.osmand.obf.preparation.IndexCreatorSettings) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) IndexPoiCreator(net.osmand.obf.preparation.IndexPoiCreator) ResultMatcher(net.osmand.ResultMatcher) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) TLongHashSet(gnu.trove.set.hash.TLongHashSet) List(java.util.List) ArrayList(java.util.ArrayList) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 12 with IndexCreatorSettings

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

the class MainUtilities method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        printSynopsys();
    } else if (args[0].equals("--test-osm-live-tag-removal")) {
        generateAllOsmLiveTests(new File(System.getProperty("repo.dir") + "/resources/test-resources/osm_live"), System.getProperty("maps.dir"), false);
    // String test = "2017_06_18-10_30_tagRemovalBug_01.xml";
    // String osmLivePath = System.getProperty("repo.dir")+"/resources/test-resources/osm_live/";
    // Algorithms.removeAllFiles(new File(osmLivePath, AugmentedDiffsInspector.DEFAULT_REGION));
    // AugmentedDiffsInspector.main(new String[] { osmLivePath + test, osmLivePath });
    // GenerateDailyObf.main(new String[] { osmLivePath });
    } else {
        String utl = args[0];
        List<String> subArgs = new ArrayList<String>(Arrays.asList(args).subList(1, args.length));
        String[] subArgsArray = subArgs.toArray(new String[subArgs.size()]);
        if (utl.equals("check-ocean-tile")) {
            OceanTilesCreator.checkOceanTile(subArgsArray);
        } else if (utl.equals("inspector")) {
            BinaryInspector.main(subArgsArray);
        } else if (utl.equals("compare")) {
            BinaryComparator.main(subArgsArray);
        } else if (utl.equals("merge-index")) {
            BinaryMerger.main(subArgsArray);
        } else if (utl.equals("generate-region-tags")) {
            GenerateRegionTags.main(subArgsArray);
        } else if (utl.equals("generate-obf-files-in-batch")) {
            IndexBatchCreator.main(subArgsArray);
        } else if (utl.equals("generate-ocean-tile-osm")) {
            OceanTilesCreator.createJOSMFile(subArgsArray);
        } else if (utl.equals("generate-java-style")) {
            RenderingRulesStoragePrinter.main(subArgsArray);
        } else if (utl.equals("explain-rendering-style")) {
            RenderingRulesStorage.main(subArgsArray);
        } else if (utl.equals("generate-wiki-world-sqlite")) {
            WikiDatabasePreparation.main(subArgsArray);
        } else if (utl.equals("generate-wikipedia-by-country")) {
            WikipediaByCountryDivider.main(subArgsArray);
        } else if (utl.equals("generate-obf-diff")) {
            ObfDiffGenerator.main(subArgsArray);
        } else if (utl.equals("generate-basemap")) {
            BasemapProcessor.main(subArgsArray);
        } else if (utl.equals("fix-basemap-roads")) {
            FixBasemapRoads.main(subArgsArray);
        } else if (utl.equals("generate-ocean-tile")) {
            OceanTilesCreator.createTilesFile(subArgsArray[0], subArgsArray.length > 1 ? subArgsArray[1] : null);
        } else if (utl.equals("create-sqlitedb")) {
            SQLiteBigPlanetIndex.main(subArgsArray);
        } else if (utl.equals("test-routing")) {
            net.osmand.router.TestRouting.main(subArgsArray);
        } else if (utl.equals("test-icons")) {
            IconVisibility.main(subArgsArray);
        } else if (utl.equals("generate-ocbf")) {
            CountryOcbfGeneration.main(subArgsArray);
        } else if (utl.equals("generate-obf")) {
            IndexCreatorSettings settings = new IndexCreatorSettings();
            settings.indexMap = true;
            settings.indexAddress = true;
            settings.indexPOI = true;
            settings.indexTransport = true;
            settings.indexRouting = true;
            parseIndexCreatorArgs(subArgs, settings);
            generateObf(subArgs, settings);
        } else if (utl.equals("generate-obf-no-address")) {
            IndexCreatorSettings settings = new IndexCreatorSettings();
            settings.indexMap = true;
            settings.indexAddress = false;
            settings.indexPOI = true;
            settings.indexTransport = true;
            settings.indexRouting = true;
            parseIndexCreatorArgs(subArgs, settings);
            generateObf(subArgs, settings);
        } else if (utl.equals("convert-gpx-to-obf")) {
            OsmGpxWriteContext.generateObfFromGpx(subArgs);
        } else if (utl.equals("generate-map")) {
            IndexCreatorSettings settings = new IndexCreatorSettings();
            settings.indexMap = true;
            parseIndexCreatorArgs(subArgs, settings);
            generateObf(subArgs, settings);
        } else if (utl.equals("split-obf")) {
            ObfRegionSplitter.main(subArgsArray);
        } else if (utl.equals("merge-bulk-osmlive-day")) {
            ObfDiffMerger.mergeBulkOsmLiveDay(subArgsArray);
        } else if (utl.equals("merge-bulk-osmlive-month")) {
            ObfDiffMerger.mergeBulkOsmLiveMonth(subArgsArray);
        } else if (utl.equals("merge-flat-obf")) {
            ObfDiffMerger.main(subArgsArray);
        } else if (utl.equals("generate-wikivoyage-raw-lang")) {
            WikivoyageLangPreparation.main(subArgsArray);
        } else if (utl.equals("process-wikivoyage")) {
            for (String s : subArgsArray) {
                if (s.startsWith("--generate-osm=")) {
                    WikivoyageGenOSM.genWikivoyageOsm(new File(subArgsArray[0]), new File(s.substring("--generate-osm=".length())), -1);
                    return;
                }
            }
            WikivoyageDataGenerator.main(subArgsArray);
        } else if (utl.equals("generate-obf-extract-script")) {
            GenerateExtractScript.main(subArgsArray);
        } else if (utl.equals("generate-address")) {
            IndexCreatorSettings settings = new IndexCreatorSettings();
            settings.indexAddress = true;
            parseIndexCreatorArgs(subArgs, settings);
            generateObf(subArgs, settings);
        } else if (utl.equals("extract-roads-only")) {
            File mainFile = new File(subArgsArray[0]);
            IndexUploader.extractRoadOnlyFile(mainFile, new File(mainFile.getParentFile(), mainFile.getName().replace(IndexConstants.BINARY_MAP_INDEX_EXT, IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)));
        } else if (utl.equals("generate-poi")) {
            IndexCreatorSettings settings = new IndexCreatorSettings();
            settings.indexPOI = true;
            parseIndexCreatorArgs(subArgs, settings);
            generateObf(subArgs, settings);
        } else if (utl.equals("delete-unused-strings")) {
            ResourceDeleter.main(subArgsArray);
        } else if (utl.equals("index-uploader-std")) {
            // should be split into server utilites and map generation
            IndexUploader.main(subArgsArray);
        } else if (utl.equals("combine-srtm-into-file")) {
            CombineSRTMIntoFile.main(subArgsArray);
        } else if (utl.equals("split-hillshade-into-regions")) {
            SplitHillshadeIntoRegions.main(subArgsArray);
        } else if (utl.equals("merge-std-files")) {
            BinaryMerger.mergeStandardFiles(subArgsArray);
        } else if (utl.equals("generate-roads")) {
            IndexCreatorSettings settings = new IndexCreatorSettings();
            settings.indexRouting = true;
            parseIndexCreatorArgs(subArgs, settings);
            generateObf(subArgs, settings);
        } else if (utl.equals("filter-osm-by-tag")) {
            FilterOsmByTags.main(subArgsArray);
        } else if (utl.contentEquals("generate-osmlive-tests")) {
            if (subArgsArray.length < 1) {
                System.out.println("Usage: <path_to_directory_with_resources_project> <optional_path_to_unpack_files>");
                return;
            }
            File testResources = new File(subArgsArray[0] + "/resources/test-resources/osm_live/");
            generateAllOsmLiveTests(testResources, subArgsArray.length > 1 ? subArgsArray[1] : null, false);
        } else if (utl.contentEquals("generate-from-overpass")) {
            if (subArgsArray.length < 2) {
                System.out.println("Usage: PATH_TO_OVERPASS PATH_TO_WORKING_DIR");
                return;
            }
            String[] argsToGenerateOsm = new String[] { subArgsArray[0], subArgsArray[1] };
            AugmentedDiffsInspector.main(argsToGenerateOsm);
            String[] argsToGenerateObf = new String[] { subArgsArray[1] };
            GenerateDailyObf.main(argsToGenerateObf);
        } else if (utl.equals("travel-guide-creator")) {
            TravelGuideCreatorMain.main(subArgsArray);
        } else {
            printSynopsys();
        }
    }
}
Also used : IndexCreatorSettings(net.osmand.obf.preparation.IndexCreatorSettings) CombineSRTMIntoFile(net.osmand.util.CombineSRTMIntoFile)

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