use of net.osmand.binary.GeocodingUtilities.GeocodingResult in project OsmAnd-tools by osmandapp.
the class MapAddressLayer method justifyResults.
private double justifyResults(List<BinaryMapIndexReader> list, GeocodingUtilities su, List<GeocodingResult> complete, List<GeocodingResult> res) throws IOException {
double minBuildingDistance = 0;
for (GeocodingResult r : res) {
BinaryMapIndexReader reader = null;
for (BinaryMapIndexReader b : list) {
for (RouteRegion rb : b.getRoutingIndexes()) {
if (r.regionFP == rb.getFilePointer() && r.regionLen == rb.getLength()) {
reader = b;
break;
}
}
if (reader != null) {
break;
}
}
if (reader != null) {
List<GeocodingResult> justified = su.justifyReverseGeocodingSearch(r, reader, minBuildingDistance, null);
if (!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);
}
}
return minBuildingDistance;
}
use of net.osmand.binary.GeocodingUtilities.GeocodingResult in project OsmAnd-tools by osmandapp.
the class MapAddressLayer method whereAmI.
private List<Entity> whereAmI(double lat, double lon, final DataTileManager<Entity> points) throws IOException {
List<Entity> results = new ArrayList<Entity>();
int x = MapUtils.get31TileNumberX(lon);
int y = MapUtils.get31TileNumberY(lat);
List<BinaryMapIndexReader> list = new ArrayList<BinaryMapIndexReader>();
for (File f : new File(DataExtractionSettings.getSettings().getBinaryFilesDir()).listFiles()) {
if (f.getName().endsWith(".obf")) {
// $NON-NLS-1$ //$NON-NLS-2$
RandomAccessFile raf = new RandomAccessFile(f, "r");
BinaryMapIndexReader rd = new BinaryMapIndexReader(raf, f);
if (rd.containsAddressData() && rd.containsRouteData(x, y, x, y, 15)) {
list.add(rd);
} else {
rd.close();
raf.close();
}
}
}
RoutingConfiguration cfg = DataExtractionSettings.getSettings().getRoutingConfig().build("geocoding", 100, new HashMap<String, String>());
RoutingContext ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, list.toArray(new BinaryMapIndexReader[list.size()]));
GeocodingUtilities su = new GeocodingUtilities();
double minBuildingDistance = 0;
List<GeocodingResult> complete = new ArrayList<GeocodingUtilities.GeocodingResult>();
List<GeocodingResult> res = su.reverseGeocodingSearch(ctx, lat, lon, false);
minBuildingDistance = justifyResults(list, su, complete, res);
// complete.addAll(res);
Collections.sort(complete, GeocodingUtilities.DISTANCE_COMPARATOR);
long lid = -1;
for (GeocodingResult r : complete) {
if (r.building != null && r.getDistance() > minBuildingDistance * GeocodingUtilities.THRESHOLD_MULTIPLIER_SKIP_BUILDINGS_AFTER) {
continue;
}
Node n = new Node(r.getLocation().getLatitude(), r.getLocation().getLongitude(), lid--);
n.putTag(OSMTagKey.NAME.getValue(), r.toString());
results.add(n);
}
for (BinaryMapIndexReader l : list) {
l.close();
}
return results;
}
use of net.osmand.binary.GeocodingUtilities.GeocodingResult in project Osmand by osmandapp.
the class GeocodingLookupService method geocode.
private boolean geocode(final LatLon latLon) {
Location loc = new Location("");
loc.setLatitude(latLon.getLatitude());
loc.setLongitude(latLon.getLongitude());
return app.getLocationProvider().getGeocodingResult(loc, new ResultMatcher<GeocodingResult>() {
@Override
public boolean publish(GeocodingResult object) {
String result = null;
if (object != null) {
String lang = SampleApplication.LANGUAGE;
boolean transliterate = SampleApplication.TRANSLITERATE;
String geocodingResult = "";
double relevantDistance = -1;
if (object.building != null) {
String bldName = object.building.getName(lang, transliterate);
if (!Algorithms.isEmpty(object.buildingInterpolation)) {
bldName = object.buildingInterpolation;
}
geocodingResult = object.street.getName(lang, transliterate) + " " + bldName + ", " + object.city.getName(lang, transliterate);
} else if (object.street != null) {
geocodingResult = object.street.getName(lang, transliterate) + ", " + object.city.getName(lang, transliterate);
relevantDistance = object.getDistanceP();
} else if (object.city != null) {
geocodingResult = object.city.getName(lang, transliterate);
} else if (object.point != null) {
RouteDataObject rd = object.point.getRoad();
String sname = rd.getName(lang, transliterate);
if (Algorithms.isEmpty(sname)) {
sname = "";
}
String ref = rd.getRef(lang, transliterate, true);
if (!Algorithms.isEmpty(ref)) {
if (!Algorithms.isEmpty(sname)) {
sname += ", ";
}
sname += ref;
}
geocodingResult = sname;
relevantDistance = object.getDistanceP();
}
result = geocodingResult;
if (relevantDistance == -1) {
relevantDistance = object.getDistance();
}
if (!Algorithms.isEmpty(result) && relevantDistance > 100) {
result = app.getString("shared_string_near") + " " + result;
}
}
lastFoundAddress = result;
searchDone = true;
return true;
}
@Override
public boolean isCancelled() {
return !hasAnyRequest(latLon);
}
});
}
use of net.osmand.binary.GeocodingUtilities.GeocodingResult 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<BinaryMapIndexReader> rts = usedReaders;
for (BinaryMapIndexReader reader : rts) {
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.GeocodingUtilities.GeocodingResult 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);
}
});
}
Aggregations