Fix some geocoding issues
This commit is contained in:
parent
e85424303a
commit
3ac68eb011
1 changed files with 71 additions and 55 deletions
|
@ -58,7 +58,7 @@ public class GeocodingUtilities {
|
||||||
|
|
||||||
public static final float THRESHOLD_MULTIPLIER_SKIP_BUILDINGS_AFTER = 1.5f;
|
public static final float THRESHOLD_MULTIPLIER_SKIP_BUILDINGS_AFTER = 1.5f;
|
||||||
public static final float THRESHOLD_MULTIPLIER_SKIP_STREETS_AFTER = 3;
|
public static final float THRESHOLD_MULTIPLIER_SKIP_STREETS_AFTER = 3;
|
||||||
public static final float DISTANCE_STREET_NAME_PROXIMITY_BY_NAME = 20000;
|
public static final float DISTANCE_STREET_NAME_PROXIMITY_BY_NAME = 15000;
|
||||||
public static final float DISTANCE_BULDING_PROXIMITY = 100;
|
public static final float DISTANCE_BULDING_PROXIMITY = 100;
|
||||||
public static final Comparator<GeocodingResult> DISTANCE_COMPARATOR = new Comparator<GeocodingResult>() {
|
public static final Comparator<GeocodingResult> DISTANCE_COMPARATOR = new Comparator<GeocodingResult>() {
|
||||||
|
|
||||||
|
@ -212,13 +212,13 @@ public class GeocodingUtilities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GeocodingResult> justifyReverseGeocodingSearch(final GeocodingResult r, BinaryMapIndexReader reader,
|
public List<GeocodingResult> justifyReverseGeocodingSearch(final GeocodingResult road, BinaryMapIndexReader reader,
|
||||||
double knownMinBuidlingDistance) throws IOException {
|
double knownMinBuidlingDistance) throws IOException {
|
||||||
// test address index search
|
// test address index search
|
||||||
final List<GeocodingResult> streetsList = new ArrayList<GeocodingResult>();
|
final List<GeocodingResult> streetsList = new ArrayList<GeocodingResult>();
|
||||||
final List<String> streetNamePacked = prepareStreetName(r.streetName);
|
final List<String> streetNamePacked = prepareStreetName(road.streetName);
|
||||||
if (streetNamePacked.size() > 0) {
|
if (streetNamePacked.size() > 0) {
|
||||||
log.info("Search street by name " + r.streetName + " " + streetNamePacked);
|
log.info("Search street by name " + road.streetName + " " + streetNamePacked);
|
||||||
String mainWord = "";
|
String mainWord = "";
|
||||||
for(int i = 0; i < streetNamePacked.size(); i++) {
|
for(int i = 0; i < streetNamePacked.size(); i++) {
|
||||||
String s = streetNamePacked.get(i);
|
String s = streetNamePacked.get(i);
|
||||||
|
@ -235,11 +235,13 @@ public class GeocodingUtilities {
|
||||||
public boolean publish(MapObject object) {
|
public boolean publish(MapObject object) {
|
||||||
if (object instanceof Street
|
if (object instanceof Street
|
||||||
&& prepareStreetName(object.getName()).equals(streetNamePacked)) {
|
&& prepareStreetName(object.getName()).equals(streetNamePacked)) {
|
||||||
double d = MapUtils.getDistance(object.getLocation(), r.searchPoint.getLatitude(),
|
double d = MapUtils.getDistance(object.getLocation(), road.searchPoint.getLatitude(),
|
||||||
r.searchPoint.getLongitude());
|
road.searchPoint.getLongitude());
|
||||||
if (d < DISTANCE_STREET_NAME_PROXIMITY_BY_NAME) {
|
if (d < DISTANCE_STREET_NAME_PROXIMITY_BY_NAME) {
|
||||||
GeocodingResult rs = new GeocodingResult(r);
|
GeocodingResult rs = new GeocodingResult(road);
|
||||||
rs.street = (Street) object;
|
rs.street = (Street) object;
|
||||||
|
// set connection point to sort
|
||||||
|
rs.connectionPoint = rs.street.getLocation();
|
||||||
rs.city = rs.street.getCity();
|
rs.city = rs.street.getCity();
|
||||||
streetsList.add(rs);
|
streetsList.add(rs);
|
||||||
return true;
|
return true;
|
||||||
|
@ -259,24 +261,59 @@ public class GeocodingUtilities {
|
||||||
|
|
||||||
final List<GeocodingResult> res = new ArrayList<GeocodingResult>();
|
final List<GeocodingResult> res = new ArrayList<GeocodingResult>();
|
||||||
if(streetsList.size() == 0) {
|
if(streetsList.size() == 0) {
|
||||||
res.add(r);
|
res.add(road);
|
||||||
} else {
|
} else {
|
||||||
for (GeocodingResult s : streetsList) {
|
Collections.sort(streetsList, DISTANCE_COMPARATOR);
|
||||||
|
double streetDistance = 0;
|
||||||
|
for (GeocodingResult street : streetsList) {
|
||||||
|
if(streetDistance == 0) {
|
||||||
|
streetDistance = street.getDistance();
|
||||||
|
} else if(street.getDistance() > streetDistance + 1000) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
street.connectionPoint = road.connectionPoint;
|
||||||
|
final List<GeocodingResult> streetBuildings = loadStreetBuildings(road, reader, street);
|
||||||
|
Collections.sort(streetBuildings, DISTANCE_COMPARATOR);
|
||||||
|
if (streetBuildings.size() > 0) {
|
||||||
|
Iterator<GeocodingResult> it = streetBuildings.iterator();
|
||||||
|
if (knownMinBuidlingDistance == 0) {
|
||||||
|
GeocodingResult firstBld = it.next();
|
||||||
|
knownMinBuidlingDistance = firstBld.getDistance();
|
||||||
|
res.add(firstBld);
|
||||||
|
}
|
||||||
|
while (it.hasNext()) {
|
||||||
|
GeocodingResult nextBld = it.next();
|
||||||
|
if (nextBld.getDistance() > knownMinBuidlingDistance
|
||||||
|
* THRESHOLD_MULTIPLIER_SKIP_BUILDINGS_AFTER) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
res.add(nextBld);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.add(street);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(res, DISTANCE_COMPARATOR);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<GeocodingResult> loadStreetBuildings(final GeocodingResult road, BinaryMapIndexReader reader,
|
||||||
|
GeocodingResult street) throws IOException {
|
||||||
final List<GeocodingResult> streetBuildings = new ArrayList<GeocodingResult>();
|
final List<GeocodingResult> streetBuildings = new ArrayList<GeocodingResult>();
|
||||||
reader.preloadBuildings(s.street, null);
|
reader.preloadBuildings(street.street, null);
|
||||||
log.info("Preload buildings " + s.street.getName() + " " + s.city.getName() + " " + s.street.getId());
|
log.info("Preload buildings " + street.street.getName() + " " + street.city.getName() + " " + street.street.getId());
|
||||||
for (Building b : s.street.getBuildings()) {
|
for (Building b : street.street.getBuildings()) {
|
||||||
if(b.getLatLon2() != null) {
|
if(b.getLatLon2() != null) {
|
||||||
double slat = b.getLocation().getLatitude();
|
double slat = b.getLocation().getLatitude();
|
||||||
double slon = b.getLocation().getLongitude();
|
double slon = b.getLocation().getLongitude();
|
||||||
double tolat = b.getLatLon2().getLatitude();
|
double tolat = b.getLatLon2().getLatitude();
|
||||||
double tolon = b.getLatLon2().getLongitude();
|
double tolon = b.getLatLon2().getLongitude();
|
||||||
double coeff = MapUtils.getProjectionCoeff(r.searchPoint.getLatitude(), r.searchPoint.getLongitude(),
|
double coeff = MapUtils.getProjectionCoeff(road.searchPoint.getLatitude(), road.searchPoint.getLongitude(),
|
||||||
slat, slon, tolat, tolon);
|
slat, slon, tolat, tolon);
|
||||||
double plat = slat + (tolat - slat) * coeff;
|
double plat = slat + (tolat - slat) * coeff;
|
||||||
double plon = slon + (tolon - slon) * coeff;
|
double plon = slon + (tolon - slon) * coeff;
|
||||||
if (MapUtils.getDistance(r.searchPoint, plat, plon) < DISTANCE_BULDING_PROXIMITY) {
|
if (MapUtils.getDistance(road.searchPoint, plat, plon) < DISTANCE_BULDING_PROXIMITY) {
|
||||||
GeocodingResult bld = new GeocodingResult(s);
|
GeocodingResult bld = new GeocodingResult(street);
|
||||||
bld.building = b;
|
bld.building = b;
|
||||||
bld.connectionPoint = b.getLocation();
|
bld.connectionPoint = b.getLocation();
|
||||||
streetBuildings.add(bld);
|
streetBuildings.add(bld);
|
||||||
|
@ -301,34 +338,13 @@ public class GeocodingUtilities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (MapUtils.getDistance(b.getLocation(), r.searchPoint) < DISTANCE_BULDING_PROXIMITY) {
|
} else if (MapUtils.getDistance(b.getLocation(), road.searchPoint) < DISTANCE_BULDING_PROXIMITY) {
|
||||||
GeocodingResult bld = new GeocodingResult(s);
|
GeocodingResult bld = new GeocodingResult(street);
|
||||||
bld.building = b;
|
bld.building = b;
|
||||||
bld.connectionPoint = b.getLocation();
|
bld.connectionPoint = b.getLocation();
|
||||||
streetBuildings.add(bld);
|
streetBuildings.add(bld);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(streetBuildings, DISTANCE_COMPARATOR);
|
return streetBuildings;
|
||||||
if (streetBuildings.size() > 0) {
|
|
||||||
Iterator<GeocodingResult> it = streetBuildings.iterator();
|
|
||||||
if (knownMinBuidlingDistance == 0) {
|
|
||||||
GeocodingResult firstBld = it.next();
|
|
||||||
knownMinBuidlingDistance = firstBld.getDistance();
|
|
||||||
res.add(firstBld);
|
|
||||||
}
|
|
||||||
while (it.hasNext()) {
|
|
||||||
GeocodingResult nextBld = it.next();
|
|
||||||
if (nextBld.getDistance() > knownMinBuidlingDistance
|
|
||||||
* THRESHOLD_MULTIPLIER_SKIP_BUILDINGS_AFTER) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
res.add(nextBld);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res.add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.sort(res, DISTANCE_COMPARATOR);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue