Search in sources :

Example 16 with OsmandRegions

use of net.osmand.map.OsmandRegions in project Osmand by osmandapp.

the class FirstUsageWizardFragment method searchMap.

private void searchMap() {
    if (location != null) {
        int point31x = MapUtils.get31TileNumberX(location.getLongitude());
        int point31y = MapUtils.get31TileNumberY(location.getLatitude());
        ResourceManager rm = getMyApplication().getResourceManager();
        OsmandRegions osmandRegions = rm.getOsmandRegions();
        List<BinaryMapDataObject> mapDataObjects = null;
        try {
            mapDataObjects = osmandRegions.queryBbox(point31x, point31x, point31y, point31y);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String selectedFullName = "";
        if (mapDataObjects != null) {
            Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
            while (it.hasNext()) {
                BinaryMapDataObject o = it.next();
                if (!osmandRegions.contain(o, point31x, point31y)) {
                    it.remove();
                }
            }
            for (BinaryMapDataObject o : mapDataObjects) {
                String fullName = osmandRegions.getFullName(o);
                if (fullName.length() > selectedFullName.length()) {
                    selectedFullName = fullName;
                }
            }
        }
        if (!Algorithms.isEmpty(selectedFullName)) {
            WorldRegion downloadRegion = osmandRegions.getRegionData(selectedFullName);
            if (downloadRegion != null && downloadRegion.isRegionMapDownload()) {
                localDownloadRegion = downloadRegion;
                List<IndexItem> indexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(downloadRegion));
                for (IndexItem item : indexItems) {
                    if (item.getType() == DownloadActivityType.NORMAL_FILE) {
                        localMapIndexItem = item;
                        break;
                    }
                }
            }
        }
        baseMapIndexItem = downloadThread.getIndexes().getWorldBaseMapItem();
        if (localMapIndexItem != null || baseMapIndexItem != null) {
            showMapFoundFragment(getActivity());
        } else {
            closeWizard();
        }
    } else {
        showNoLocationFragment(getActivity());
    }
}
Also used : OsmandRegions(net.osmand.map.OsmandRegions) WorldRegion(net.osmand.map.WorldRegion) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) ResourceManager(net.osmand.plus.resources.ResourceManager) IOException(java.io.IOException) IndexItem(net.osmand.plus.download.IndexItem) LinkedList(java.util.LinkedList)

Example 17 with OsmandRegions

use of net.osmand.map.OsmandRegions in project Osmand by osmandapp.

the class SampleApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    OsmandResources.init(this);
    locationProvider = new SampleLocationProvider(this);
    searchUICore = new QuickSearchHelper(this);
    geocodingLookupService = new GeocodingLookupService(this);
    resourceManager = new ResourceManager(this);
    regions = new OsmandRegions();
    updateRegionVars();
    indexRegionsBoundaries();
    uiHandler = new Handler();
    poiTypes = MapPoiTypes.getDefaultNoInit();
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
        initPoiTypes();
    }
    // Initialize native core
    if (NativeCore.isAvailable() && !NativeCore.isLoaded()) {
        assetsCustom = CoreResourcesFromAndroidAssets.loadFromCurrentApplication(this);
        NativeCore.load(assetsCustom);
    }
    Logger.get().setSeverityLevelThreshold(LogSeverityLevel.Debug);
    iconsCache = new IconsCache(assetsCustom, this);
}
Also used : OsmandRegions(net.osmand.map.OsmandRegions) Handler(android.os.Handler) ResourceManager(net.osmand.core.samples.android.sample1.resources.ResourceManager) QuickSearchHelper(net.osmand.core.samples.android.sample1.search.QuickSearchHelper)

Example 18 with OsmandRegions

use of net.osmand.map.OsmandRegions in project OsmAnd-tools by osmandapp.

the class FixBasemapRoads method process.

private void process(File read, File write, List<File> relationFiles) throws IOException, XMLStreamException, XmlPullParserException, SQLException {
    MapRenderingTypesEncoder renderingTypes = new MapRenderingTypesEncoder("basemap");
    OsmandRegions or = prepareRegions();
    TagsTransformer transformer = new TagsTransformer();
    for (File relFile : relationFiles) {
        LOG.info("Parse relations file " + relFile.getName());
        OsmBaseStorage storage = parseOsmFile(relFile);
        int total = 0;
        for (EntityId e : storage.getRegisteredEntities().keySet()) {
            if (e.getType() == EntityType.RELATION) {
                total++;
                if (total % 1000 == 0) {
                    LOG.info("Processed " + total + " relations");
                }
                Relation es = (Relation) storage.getRegisteredEntities().get(e);
                transformer.handleRelationPropogatedTags(es, renderingTypes, null, EntityConvertApplyType.MAP);
            }
        }
    }
    LOG.info("Parse main file " + read.getName());
    OsmBaseStorage storage = parseOsmFile(read);
    Map<EntityId, Entity> entities = new HashMap<EntityId, Entity>(storage.getRegisteredEntities());
    int total = 0;
    for (EntityId e : entities.keySet()) {
        if (e.getType() == EntityType.WAY) {
            Way es = (Way) storage.getRegisteredEntities().get(e);
            total++;
            if (total % 1000 == 0) {
                LOG.info("Processed " + total + " ways");
            }
            addRegionTag(or, es);
            transformer.addPropogatedTags(es);
            Map<String, String> ntags = renderingTypes.transformTags(es.getModifiableTags(), EntityType.WAY, EntityConvertApplyType.MAP);
            if (es.getModifiableTags() != ntags) {
                es.getModifiableTags().putAll(ntags);
            }
            processWay(es);
        }
    }
    List<EntityId> toWrite = new ArrayList<EntityId>();
    processRegion(toWrite);
    OsmStorageWriter writer = new OsmStorageWriter();
    LOG.info("Writing file... ");
    writer.saveStorage(new FileOutputStream(write), storage, toWrite, true);
    LOG.info("DONE");
}
Also used : OsmStorageWriter(net.osmand.osm.io.OsmStorageWriter) Entity(net.osmand.osm.edit.Entity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TagsTransformer(net.osmand.data.preparation.TagsTransformer) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) Way(net.osmand.osm.edit.Way) EntityId(net.osmand.osm.edit.Entity.EntityId) Relation(net.osmand.osm.edit.Relation) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) OsmandRegions(net.osmand.map.OsmandRegions) OsmBaseStorage(net.osmand.osm.io.OsmBaseStorage) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 19 with OsmandRegions

use of net.osmand.map.OsmandRegions in project OsmAnd-tools by osmandapp.

the class WikipediaByCountryDivider method generateGlobalWikiFile.

protected static void generateGlobalWikiFile(String folder, String regionsFile) throws IOException, SQLException, FileNotFoundException, UnsupportedEncodingException {
    OsmandRegions regions = new OsmandRegions();
    regions.prepareFile(regionsFile);
    regions.cacheAllCountries();
    final GlobalWikiStructure wikiStructure = new GlobalWikiStructure(folder + "wiki.sqlite", regions, true);
    File fl = new File(folder);
    List<String> langs = new ArrayList<String>();
    for (File f : fl.listFiles()) {
        if (f.getName().endsWith("wiki.sqlite") && f.getName().length() > "wiki.sqlite".length()) {
            langs.add(f.getName().substring(0, f.getName().length() - "wiki.sqlite".length()));
        }
    }
    for (String lang : langs) {
        processLang(lang, folder, wikiStructure);
    }
    wikiStructure.closeConnnection();
    System.out.println("Generation finished");
}
Also used : OsmandRegions(net.osmand.map.OsmandRegions) ArrayList(java.util.ArrayList) File(java.io.File)

Example 20 with OsmandRegions

use of net.osmand.map.OsmandRegions in project OsmAnd-tools by osmandapp.

the class CombineSRTMIntoFile method main.

public static void main(String[] args) throws IOException {
    File directoryWithSRTMFiles = new File(args[0]);
    File directoryWithTargetFiles = new File(args[1]);
    String ocbfFile = args[2];
    boolean dryRun = true;
    // mauritius
    String filter = null;
    for (int i = 3; i < args.length; i++) {
        if ("--dry-run".equals(args[i])) {
            dryRun = true;
        } else if (args[i].startsWith("--filter")) {
            filter = args[i].substring("--filter".length());
        }
    }
    OsmandRegions or = new OsmandRegions();
    BinaryMapIndexReader fl = or.prepareFile(ocbfFile);
    Map<String, LinkedList<BinaryMapDataObject>> allCountries = or.cacheAllCountries();
    MapIndex mapIndex = fl.getMapIndexes().get(0);
    int srtm = mapIndex.getRule("region_srtm", "yes");
    int downloadName = mapIndex.getRule("download_name", null);
    int boundary = mapIndex.getRule("osmand_region", "boundary");
    int cnt = 1;
    Set<String> failedCountries = new HashSet<String>();
    for (String fullName : allCountries.keySet()) {
        LinkedList<BinaryMapDataObject> lst = allCountries.get(fullName);
        if (fullName == null || (filter != null && !fullName.contains(filter))) {
            continue;
        }
        BinaryMapDataObject rc = null;
        for (BinaryMapDataObject r : lst) {
            if (!r.containsType(boundary)) {
                rc = r;
                break;
            }
        }
        System.out.println(fullName);
        if (rc != null && rc.containsAdditionalType(srtm)) {
            String dw = rc.getNameByType(downloadName);
            System.out.println("Region " + fullName + " " + cnt++ + " out of " + lst.size());
            try {
                process(rc, lst.subList(1, lst.size()), dw, directoryWithSRTMFiles, directoryWithTargetFiles, dryRun);
            } catch (Exception e) {
                failedCountries.add(fullName);
                e.printStackTrace();
            }
        }
    }
    if (!failedCountries.isEmpty()) {
        throw new IllegalStateException("Failed countries " + failedCountries);
    }
}
Also used : BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) LinkedList(java.util.LinkedList) SQLException(java.sql.SQLException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) OsmandRegions(net.osmand.map.OsmandRegions) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

OsmandRegions (net.osmand.map.OsmandRegions)20 File (java.io.File)10 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)8 WorldRegion (net.osmand.map.WorldRegion)8 LinkedList (java.util.LinkedList)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)5 IndexItem (net.osmand.plus.download.IndexItem)4 FileOutputStream (java.io.FileOutputStream)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)3 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TagValuePair (net.osmand.binary.BinaryMapIndexReader.TagValuePair)2 AssetIndexItem (net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem)2