use of net.osmand.binary.BinaryMapIndexReader in project Osmand by osmandapp.
the class CurrentPositionHelper method justifyResult.
private void justifyResult(List<GeocodingResult> res, final ResultMatcher<GeocodingResult> result) {
List<GeocodingResult> complete = new ArrayList<>();
double minBuildingDistance = 0;
if (res != null) {
for (GeocodingResult r : res) {
BinaryMapIndexReader foundRepo = null;
List<BinaryMapReaderResource> rts = usedReaders;
for (BinaryMapReaderResource rt : rts) {
if (rt.isClosed()) {
continue;
}
BinaryMapIndexReader reader = rt.getReader(BinaryMapReaderResourceType.STREET_LOOKUP);
for (RouteRegion rb : reader.getRoutingIndexes()) {
if (r.regionFP == rb.getFilePointer() && r.regionLen == rb.getLength()) {
foundRepo = reader;
break;
}
}
}
if (result.isCancelled()) {
break;
} else if (foundRepo != null) {
List<GeocodingResult> justified = null;
try {
justified = new GeocodingUtilities().justifyReverseGeocodingSearch(r, foundRepo, minBuildingDistance, result);
} catch (IOException e) {
log.error("Exception happened during reverse geocoding", e);
e.printStackTrace();
}
if (justified != null && !justified.isEmpty()) {
double md = justified.get(0).getDistance();
if (minBuildingDistance == 0) {
minBuildingDistance = md;
} else {
minBuildingDistance = Math.min(md, minBuildingDistance);
}
complete.addAll(justified);
}
} else {
complete.add(r);
}
}
}
if (result.isCancelled()) {
app.runInUIThread(new Runnable() {
public void run() {
result.publish(null);
}
});
return;
}
Collections.sort(complete, GeocodingUtilities.DISTANCE_COMPARATOR);
// for(GeocodingResult rt : complete) {
// System.out.println(rt.toString());
// }
final GeocodingResult rts = complete.size() > 0 ? complete.get(0) : new GeocodingResult();
app.runInUIThread(new Runnable() {
public void run() {
result.publish(rts);
}
});
}
use of net.osmand.binary.BinaryMapIndexReader in project Osmand by osmandapp.
the class CurrentPositionHelper method initCtx.
private void initCtx(OsmandApplication app, List<BinaryMapReaderResource> checkReaders, @NonNull ApplicationMode appMode) {
am = appMode;
String p;
if (am.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
p = GeneralRouterProfile.BICYCLE.name().toLowerCase();
} else if (am.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
p = GeneralRouterProfile.PEDESTRIAN.name().toLowerCase();
} else if (am.isDerivedRoutingFrom(ApplicationMode.CAR)) {
p = GeneralRouterProfile.CAR.name().toLowerCase();
} else {
p = "geocoding";
}
BinaryMapIndexReader[] rs = new BinaryMapIndexReader[checkReaders.size()];
if (rs.length > 0) {
int i = 0;
for (BinaryMapReaderResource rep : checkReaders) {
rs[i++] = rep.getReader(BinaryMapReaderResourceType.STREET_LOOKUP);
}
RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p, 10, new HashMap<String, String>());
ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, rs);
RoutingConfiguration defCfg = app.getDefaultRoutingConfig().build("geocoding", 10, new HashMap<String, String>());
defCtx = new RoutePlannerFrontEnd(false).buildRoutingContext(defCfg, null, rs);
} else {
ctx = null;
defCtx = null;
}
usedReaders = checkReaders;
}
use of net.osmand.binary.BinaryMapIndexReader in project Osmand by osmandapp.
the class TestRouting method runAllTests.
public static boolean runAllTests(Parameters params, NativeLibrary lib) throws FileNotFoundException, IOException, Exception {
BinaryMapIndexReader[] rs = collectFiles(params.obfDir.getAbsolutePath());
boolean allSuccess = true;
for (File f : params.tests) {
System.out.println("Before test " + f.getAbsolutePath());
System.out.flush();
allSuccess &= test(lib, new FileInputStream(f), rs, params.configBuilder);
}
return allSuccess;
}
use of net.osmand.binary.BinaryMapIndexReader in project Osmand by osmandapp.
the class SearchPhrase method getDiffsByRegion.
private Map<String, List<BinaryMapIndexReader>> getDiffsByRegion() {
Map<String, List<BinaryMapIndexReader>> result = new HashMap<>();
Iterator<BinaryMapIndexReader> it = indexes.iterator();
while (it.hasNext()) {
BinaryMapIndexReader r = it.next();
if (r == null || r.getFile() == null) {
continue;
}
String filename = r.getFile().getName();
if (filename.matches("([a-zA-Z-]+_)+([0-9]+_){2}[0-9]+\\.obf")) {
String currRegionName = r.getRegionName();
if (result.containsKey(currRegionName)) {
result.get(currRegionName).add(r);
} else {
result.put(currRegionName, new ArrayList<>(Arrays.asList(r)));
}
it.remove();
}
}
return result;
}
use of net.osmand.binary.BinaryMapIndexReader in project Osmand by osmandapp.
the class ResourceManager method setRepositories.
private void setRepositories() {
ArrayList<File> files = new ArrayList<>();
File appPath = app.getAppPath(null);
SampleUtils.collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
SampleUtils.collectFiles(app.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
for (File f : files) {
try {
RandomAccessFile mf = new RandomAccessFile(f.getPath(), "r");
BinaryMapIndexReader reader = new BinaryMapIndexReader(mf, f);
if (reader.containsPoiData()) {
amenityRepositories.put(f.getName(), new AmenityIndexRepositoryBinary(reader));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aggregations