use of net.osmand.binary.BinaryMapIndexReader in project Osmand by osmandapp.
the class OsmandRegions method prepareFile.
public BinaryMapIndexReader prepareFile(String fileName) throws IOException {
reader = new BinaryMapIndexReader(new RandomAccessFile(fileName, "r"), new File(fileName));
// final Collator clt = OsmAndCollator.primaryCollator();
final Map<String, String> parentRelations = new LinkedHashMap<String, String>();
final ResultMatcher<BinaryMapDataObject> resultMatcher = new ResultMatcher<BinaryMapDataObject>() {
@Override
public boolean publish(BinaryMapDataObject object) {
initTypes(object);
int[] types = object.getTypes();
for (int i = 0; i < types.length; i++) {
TagValuePair tp = object.getMapIndex().decodeType(types[i]);
if ("boundary".equals(tp.value)) {
return false;
}
}
WorldRegion rd = initRegionData(parentRelations, object);
if (rd == null) {
return false;
}
if (rd.regionDownloadName != null) {
downloadNamesToFullNames.put(rd.regionDownloadName, rd.regionFullName);
}
fullNamesToRegionData.put(rd.regionFullName, rd);
return false;
}
@Override
public boolean isCancelled() {
return false;
}
};
iterateOverAllObjects(resultMatcher);
// post process download names
for (Map.Entry<String, String> e : parentRelations.entrySet()) {
String fullName = e.getKey();
String parentFullName = e.getValue();
// String parentParentFulName = parentRelations.get(parentFullName); // could be used for japan/russia
WorldRegion rd = fullNamesToRegionData.get(fullName);
WorldRegion parent = fullNamesToRegionData.get(parentFullName);
if (parent != null && rd != null) {
parent.addSubregion(rd);
}
}
structureWorldRegions(new ArrayList<WorldRegion>(fullNamesToRegionData.values()));
return reader;
}
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;
}
Aggregations