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());
}
}
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);
}
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");
}
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");
}
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);
}
}
Aggregations