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,55 +261,18 @@ 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);
|
||||||
final List<GeocodingResult> streetBuildings = new ArrayList<GeocodingResult>();
|
double streetDistance = 0;
|
||||||
reader.preloadBuildings(s.street, null);
|
for (GeocodingResult street : streetsList) {
|
||||||
log.info("Preload buildings " + s.street.getName() + " " + s.city.getName() + " " + s.street.getId());
|
if(streetDistance == 0) {
|
||||||
for (Building b : s.street.getBuildings()) {
|
streetDistance = street.getDistance();
|
||||||
if(b.getLatLon2() != null) {
|
} else if(street.getDistance() > streetDistance + 1000) {
|
||||||
double slat = b.getLocation().getLatitude();
|
continue;
|
||||||
double slon = b.getLocation().getLongitude();
|
|
||||||
double tolat = b.getLatLon2().getLatitude();
|
|
||||||
double tolon = b.getLatLon2().getLongitude();
|
|
||||||
double coeff = MapUtils.getProjectionCoeff(r.searchPoint.getLatitude(), r.searchPoint.getLongitude(),
|
|
||||||
slat, slon, tolat, tolon);
|
|
||||||
double plat = slat + (tolat - slat) * coeff;
|
|
||||||
double plon = slon + (tolon - slon) * coeff;
|
|
||||||
if (MapUtils.getDistance(r.searchPoint, plat, plon) < DISTANCE_BULDING_PROXIMITY) {
|
|
||||||
GeocodingResult bld = new GeocodingResult(s);
|
|
||||||
bld.building = b;
|
|
||||||
bld.connectionPoint = b.getLocation();
|
|
||||||
streetBuildings.add(bld);
|
|
||||||
if(!Algorithms.isEmpty(b.getName2())) {
|
|
||||||
int fi = Algorithms.extractFirstIntegerNumber(b.getName());
|
|
||||||
int si = Algorithms.extractFirstIntegerNumber(b.getName2());
|
|
||||||
if(si != 0 && fi != 0) {
|
|
||||||
int num = (int) (fi + (si - fi) * coeff);
|
|
||||||
BuildingInterpolation type = b.getInterpolationType();
|
|
||||||
if(type == BuildingInterpolation.EVEN || type == BuildingInterpolation.ODD) {
|
|
||||||
if(num % 2 == (type == BuildingInterpolation.EVEN ? 1 : 0)) {
|
|
||||||
num --;
|
|
||||||
}
|
|
||||||
} else if(b.getInterpolationInterval() > 0){
|
|
||||||
int intv = b.getInterpolationInterval();
|
|
||||||
if ((num - fi) % intv != 0) {
|
|
||||||
num = ((num - fi) / intv) * intv + fi;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bld.buildingInterpolation = num +"";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (MapUtils.getDistance(b.getLocation(), r.searchPoint) < DISTANCE_BULDING_PROXIMITY) {
|
|
||||||
GeocodingResult bld = new GeocodingResult(s);
|
|
||||||
bld.building = b;
|
|
||||||
bld.connectionPoint = b.getLocation();
|
|
||||||
streetBuildings.add(bld);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
street.connectionPoint = road.connectionPoint;
|
||||||
|
final List<GeocodingResult> streetBuildings = loadStreetBuildings(road, reader, street);
|
||||||
Collections.sort(streetBuildings, DISTANCE_COMPARATOR);
|
Collections.sort(streetBuildings, DISTANCE_COMPARATOR);
|
||||||
if (streetBuildings.size() > 0) {
|
if (streetBuildings.size() > 0) {
|
||||||
Iterator<GeocodingResult> it = streetBuildings.iterator();
|
Iterator<GeocodingResult> it = streetBuildings.iterator();
|
||||||
|
@ -325,10 +290,61 @@ public class GeocodingUtilities {
|
||||||
res.add(nextBld);
|
res.add(nextBld);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.add(s);
|
res.add(street);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(res, DISTANCE_COMPARATOR);
|
Collections.sort(res, DISTANCE_COMPARATOR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<GeocodingResult> loadStreetBuildings(final GeocodingResult road, BinaryMapIndexReader reader,
|
||||||
|
GeocodingResult street) throws IOException {
|
||||||
|
final List<GeocodingResult> streetBuildings = new ArrayList<GeocodingResult>();
|
||||||
|
reader.preloadBuildings(street.street, null);
|
||||||
|
log.info("Preload buildings " + street.street.getName() + " " + street.city.getName() + " " + street.street.getId());
|
||||||
|
for (Building b : street.street.getBuildings()) {
|
||||||
|
if(b.getLatLon2() != null) {
|
||||||
|
double slat = b.getLocation().getLatitude();
|
||||||
|
double slon = b.getLocation().getLongitude();
|
||||||
|
double tolat = b.getLatLon2().getLatitude();
|
||||||
|
double tolon = b.getLatLon2().getLongitude();
|
||||||
|
double coeff = MapUtils.getProjectionCoeff(road.searchPoint.getLatitude(), road.searchPoint.getLongitude(),
|
||||||
|
slat, slon, tolat, tolon);
|
||||||
|
double plat = slat + (tolat - slat) * coeff;
|
||||||
|
double plon = slon + (tolon - slon) * coeff;
|
||||||
|
if (MapUtils.getDistance(road.searchPoint, plat, plon) < DISTANCE_BULDING_PROXIMITY) {
|
||||||
|
GeocodingResult bld = new GeocodingResult(street);
|
||||||
|
bld.building = b;
|
||||||
|
bld.connectionPoint = b.getLocation();
|
||||||
|
streetBuildings.add(bld);
|
||||||
|
if(!Algorithms.isEmpty(b.getName2())) {
|
||||||
|
int fi = Algorithms.extractFirstIntegerNumber(b.getName());
|
||||||
|
int si = Algorithms.extractFirstIntegerNumber(b.getName2());
|
||||||
|
if(si != 0 && fi != 0) {
|
||||||
|
int num = (int) (fi + (si - fi) * coeff);
|
||||||
|
BuildingInterpolation type = b.getInterpolationType();
|
||||||
|
if(type == BuildingInterpolation.EVEN || type == BuildingInterpolation.ODD) {
|
||||||
|
if(num % 2 == (type == BuildingInterpolation.EVEN ? 1 : 0)) {
|
||||||
|
num --;
|
||||||
|
}
|
||||||
|
} else if(b.getInterpolationInterval() > 0){
|
||||||
|
int intv = b.getInterpolationInterval();
|
||||||
|
if ((num - fi) % intv != 0) {
|
||||||
|
num = ((num - fi) / intv) * intv + fi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bld.buildingInterpolation = num +"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (MapUtils.getDistance(b.getLocation(), road.searchPoint) < DISTANCE_BULDING_PROXIMITY) {
|
||||||
|
GeocodingResult bld = new GeocodingResult(street);
|
||||||
|
bld.building = b;
|
||||||
|
bld.connectionPoint = b.getLocation();
|
||||||
|
streetBuildings.add(bld);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return streetBuildings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue