Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f85db1938a
1 changed files with 61 additions and 62 deletions
|
@ -36,34 +36,34 @@ import gnu.trove.set.hash.TLongHashSet;
|
||||||
public class GeocodingUtilities {
|
public class GeocodingUtilities {
|
||||||
|
|
||||||
private static final Log log = PlatformUtil.getLog(GeocodingUtilities.class);
|
private static final Log log = PlatformUtil.getLog(GeocodingUtilities.class);
|
||||||
|
|
||||||
public static final float THRESHOLD_MULTIPLIER_SKIP_STREETS_AFTER = 4;
|
public static final float THRESHOLD_MULTIPLIER_SKIP_STREETS_AFTER = 4;
|
||||||
public static final float STOP_SEARCHING_STREET_WITH_MULTIPLIER_RADIUS = 100;
|
public static final float STOP_SEARCHING_STREET_WITH_MULTIPLIER_RADIUS = 100;
|
||||||
public static final float STOP_SEARCHING_STREET_WITHOUT_MULTIPLIER_RADIUS = 400;
|
public static final float STOP_SEARCHING_STREET_WITHOUT_MULTIPLIER_RADIUS = 400;
|
||||||
|
|
||||||
public static final float DISTANCE_STREET_NAME_PROXIMITY_BY_NAME = 15000;
|
public static final float DISTANCE_STREET_NAME_PROXIMITY_BY_NAME = 15000;
|
||||||
public static final float DISTANCE_STREET_FROM_CLOSEST_WITH_SAME_NAME = 1000;
|
public static final float DISTANCE_STREET_FROM_CLOSEST_WITH_SAME_NAME = 1000;
|
||||||
|
|
||||||
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 DISTANCE_BULDING_PROXIMITY = 100;
|
public static final float DISTANCE_BUILDING_PROXIMITY = 100;
|
||||||
|
|
||||||
public static final String[] SUFFIXES = new String[] {
|
public static final String[] SUFFIXES = new String[]{
|
||||||
"av.", "avenue", "просп.", "пер.", "пр.","заул.", "проспект", "переул.", "бул.", "бульвар", "тракт"};
|
"av.", "avenue", "просп.", "пер.", "пр.", "заул.", "проспект", "переул.", "бул.", "бульвар", "тракт"};
|
||||||
public static final String[] DEFAULT_SUFFIXES = new String[] {
|
public static final String[] DEFAULT_SUFFIXES = new String[]{
|
||||||
"str.", "street", "улица", "ул.", "вулица", "вул.", "вулиця"};
|
"str.", "street", "улица", "ул.", "вулица", "вул.", "вулиця"};
|
||||||
private static Set<String> SET_DEF_SUFFIXES = null;
|
private static Set<String> SET_DEF_SUFFIXES = null;
|
||||||
private static Set<String> SET_SUFFIXES = null;
|
private static Set<String> SET_SUFFIXES = null;
|
||||||
|
|
||||||
public static Set<String> getDefSuffixesSet() {
|
public static Set<String> getDefSuffixesSet() {
|
||||||
if(SET_DEF_SUFFIXES == null) {
|
if (SET_DEF_SUFFIXES == null) {
|
||||||
SET_DEF_SUFFIXES = new TreeSet<String>();
|
SET_DEF_SUFFIXES = new TreeSet<String>();
|
||||||
SET_DEF_SUFFIXES.addAll(Arrays.asList(DEFAULT_SUFFIXES));
|
SET_DEF_SUFFIXES.addAll(Arrays.asList(DEFAULT_SUFFIXES));
|
||||||
}
|
}
|
||||||
return SET_DEF_SUFFIXES;
|
return SET_DEF_SUFFIXES;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getSuffixesSet() {
|
public static Set<String> getSuffixesSet() {
|
||||||
if(SET_SUFFIXES == null) {
|
if (SET_SUFFIXES == null) {
|
||||||
SET_SUFFIXES = new TreeSet<String>();
|
SET_SUFFIXES = new TreeSet<String>();
|
||||||
SET_SUFFIXES.addAll(Arrays.asList(SUFFIXES));
|
SET_SUFFIXES.addAll(Arrays.asList(SUFFIXES));
|
||||||
}
|
}
|
||||||
|
@ -76,19 +76,19 @@ public class GeocodingUtilities {
|
||||||
public int compare(GeocodingResult o1, GeocodingResult o2) {
|
public int compare(GeocodingResult o1, GeocodingResult o2) {
|
||||||
LatLon l1 = o1.getLocation();
|
LatLon l1 = o1.getLocation();
|
||||||
LatLon l2 = o2.getLocation();
|
LatLon l2 = o2.getLocation();
|
||||||
if(l1 == null || l2 == null){
|
if (l1 == null || l2 == null) {
|
||||||
return l2 == l1 ? 0 : (l1 == null ? -1 : 1);
|
return l2 == l1 ? 0 : (l1 == null ? -1 : 1);
|
||||||
}
|
}
|
||||||
return Double.compare(MapUtils.getDistance(l1, o1.searchPoint),
|
return Double.compare(MapUtils.getDistance(l1, o1.searchPoint),
|
||||||
MapUtils.getDistance(l2, o2.searchPoint));
|
MapUtils.getDistance(l2, o2.searchPoint));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static class GeocodingResult {
|
public static class GeocodingResult {
|
||||||
public GeocodingResult(){
|
public GeocodingResult() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeocodingResult(GeocodingResult r){
|
public GeocodingResult(GeocodingResult r) {
|
||||||
this.searchPoint = r.searchPoint;
|
this.searchPoint = r.searchPoint;
|
||||||
this.regionFP = r.regionFP;
|
this.regionFP = r.regionFP;
|
||||||
this.regionLen = r.regionLen;
|
this.regionLen = r.regionLen;
|
||||||
|
@ -99,7 +99,7 @@ public class GeocodingUtilities {
|
||||||
this.city = r.city;
|
this.city = r.city;
|
||||||
this.street = r.street;
|
this.street = r.street;
|
||||||
}
|
}
|
||||||
|
|
||||||
// input
|
// input
|
||||||
public LatLon searchPoint;
|
public LatLon searchPoint;
|
||||||
// 1st step
|
// 1st step
|
||||||
|
@ -114,20 +114,20 @@ public class GeocodingUtilities {
|
||||||
public Street street;
|
public Street street;
|
||||||
public City city;
|
public City city;
|
||||||
private double dist = -1;
|
private double dist = -1;
|
||||||
|
|
||||||
public LatLon getLocation() {
|
public LatLon getLocation() {
|
||||||
return connectionPoint;
|
return connectionPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDistance() {
|
public double getDistance() {
|
||||||
if(dist == -1 && connectionPoint != null && searchPoint != null) {
|
if (dist == -1 && connectionPoint != null && searchPoint != null) {
|
||||||
dist = MapUtils.getDistance(connectionPoint, searchPoint);
|
dist = MapUtils.getDistance(connectionPoint, searchPoint);
|
||||||
}
|
}
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDistanceP() {
|
public double getDistanceP() {
|
||||||
if(point != null && searchPoint != null) {
|
if (point != null && searchPoint != null) {
|
||||||
// Need distance between searchPoint and nearest RouteSegmentPoint here, to approximate distance from neareest named road
|
// Need distance between searchPoint and nearest RouteSegmentPoint here, to approximate distance from neareest named road
|
||||||
return Math.sqrt(point.distSquare);
|
return Math.sqrt(point.distSquare);
|
||||||
} else {
|
} else {
|
||||||
|
@ -138,26 +138,25 @@ public class GeocodingUtilities {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder bld = new StringBuilder();
|
StringBuilder bld = new StringBuilder();
|
||||||
if(building != null) {
|
if (building != null) {
|
||||||
bld.append(building.getName());
|
bld.append(building.getName());
|
||||||
}
|
}
|
||||||
if(street != null) {
|
if (street != null) {
|
||||||
bld.append(" str. ").append(street.getName()).append(" city ").append(city.getName());
|
bld.append(" str. ").append(street.getName()).append(" city ").append(city.getName());
|
||||||
} else if(streetName != null) {
|
} else if (streetName != null) {
|
||||||
bld.append(" str. ").append(streetName);
|
bld.append(" str. ").append(streetName);
|
||||||
} else if(city != null) {
|
} else if (city != null) {
|
||||||
bld.append(" city ").append(city.getName());
|
bld.append(" city ").append(city.getName());
|
||||||
}
|
}
|
||||||
if(connectionPoint != null && searchPoint != null) {
|
if (connectionPoint != null && searchPoint != null) {
|
||||||
|
|
||||||
bld.append(" dist=").append((int) getDistance());
|
bld.append(" dist=").append((int) getDistance());
|
||||||
}
|
}
|
||||||
return bld.toString();
|
return bld.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<GeocodingResult> reverseGeocodingSearch(RoutingContext ctx, double lat, double lon) throws IOException {
|
public List<GeocodingResult> reverseGeocodingSearch(RoutingContext ctx, double lat, double lon) throws IOException {
|
||||||
RoutePlannerFrontEnd rp = new RoutePlannerFrontEnd(false);
|
RoutePlannerFrontEnd rp = new RoutePlannerFrontEnd(false);
|
||||||
List<GeocodingResult> lst = new ArrayList<GeocodingUtilities.GeocodingResult>();
|
List<GeocodingResult> lst = new ArrayList<GeocodingUtilities.GeocodingResult>();
|
||||||
|
@ -166,40 +165,40 @@ public class GeocodingUtilities {
|
||||||
double distSquare = 0;
|
double distSquare = 0;
|
||||||
TLongHashSet set = new TLongHashSet();
|
TLongHashSet set = new TLongHashSet();
|
||||||
Set<String> streetNames = new HashSet<String>();
|
Set<String> streetNames = new HashSet<String>();
|
||||||
for(RouteSegmentPoint p : listR) {
|
for (RouteSegmentPoint p : listR) {
|
||||||
RouteDataObject road = p.getRoad();
|
RouteDataObject road = p.getRoad();
|
||||||
if(!set.add(road.getId())) {
|
if (!set.add(road.getId())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// System.out.println(road.toString() + " " + Math.sqrt(p.distSquare));
|
// System.out.println(road.toString() + " " + Math.sqrt(p.distSquare));
|
||||||
boolean emptyName = Algorithms.isEmpty(road.getName()) && Algorithms.isEmpty(road.getRef()) ;
|
boolean emptyName = Algorithms.isEmpty(road.getName()) && Algorithms.isEmpty(road.getRef());
|
||||||
if(!emptyName) {
|
if (!emptyName) {
|
||||||
if(distSquare == 0 || distSquare > p.distSquare) {
|
if (distSquare == 0 || distSquare > p.distSquare) {
|
||||||
distSquare = p.distSquare;
|
distSquare = p.distSquare;
|
||||||
}
|
}
|
||||||
GeocodingResult sr = new GeocodingResult();
|
GeocodingResult sr = new GeocodingResult();
|
||||||
sr.searchPoint = new LatLon(lat, lon);
|
sr.searchPoint = new LatLon(lat, lon);
|
||||||
sr.streetName = Algorithms.isEmpty(road.getName())? road.getRef() : road.getName();
|
sr.streetName = Algorithms.isEmpty(road.getName()) ? road.getRef() : road.getName();
|
||||||
sr.point = p;
|
sr.point = p;
|
||||||
sr.connectionPoint = new LatLon(MapUtils.get31LatitudeY(p.preciseY), MapUtils.get31LongitudeX(p.preciseX));
|
sr.connectionPoint = new LatLon(MapUtils.get31LatitudeY(p.preciseY), MapUtils.get31LongitudeX(p.preciseX));
|
||||||
sr.regionFP = road.region.getFilePointer();
|
sr.regionFP = road.region.getFilePointer();
|
||||||
sr.regionLen = road.region.getLength();
|
sr.regionLen = road.region.getLength();
|
||||||
if(streetNames.add(sr.streetName)) {
|
if (streetNames.add(sr.streetName)) {
|
||||||
lst.add(sr);
|
lst.add(sr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(p.distSquare > STOP_SEARCHING_STREET_WITH_MULTIPLIER_RADIUS * STOP_SEARCHING_STREET_WITH_MULTIPLIER_RADIUS &&
|
if (p.distSquare > STOP_SEARCHING_STREET_WITH_MULTIPLIER_RADIUS * STOP_SEARCHING_STREET_WITH_MULTIPLIER_RADIUS &&
|
||||||
distSquare != 0 && p.distSquare > THRESHOLD_MULTIPLIER_SKIP_STREETS_AFTER * distSquare ) {
|
distSquare != 0 && p.distSquare > THRESHOLD_MULTIPLIER_SKIP_STREETS_AFTER * distSquare) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(p.distSquare > STOP_SEARCHING_STREET_WITHOUT_MULTIPLIER_RADIUS*STOP_SEARCHING_STREET_WITHOUT_MULTIPLIER_RADIUS) {
|
if (p.distSquare > STOP_SEARCHING_STREET_WITHOUT_MULTIPLIER_RADIUS * STOP_SEARCHING_STREET_WITHOUT_MULTIPLIER_RADIUS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(lst, GeocodingUtilities.DISTANCE_COMPARATOR);
|
Collections.sort(lst, GeocodingUtilities.DISTANCE_COMPARATOR);
|
||||||
return lst;
|
return lst;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> prepareStreetName(String s) {
|
public List<String> prepareStreetName(String s) {
|
||||||
List<String> ls = new ArrayList<String>();
|
List<String> ls = new ArrayList<String>();
|
||||||
int beginning = 0;
|
int beginning = 0;
|
||||||
|
@ -233,7 +232,7 @@ public class GeocodingUtilities {
|
||||||
ls.add(w);
|
ls.add(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GeocodingResult> justifyReverseGeocodingSearch(final GeocodingResult road, BinaryMapIndexReader reader,
|
public List<GeocodingResult> justifyReverseGeocodingSearch(final GeocodingResult road, BinaryMapIndexReader reader,
|
||||||
double knownMinBuidlingDistance, final ResultMatcher<GeocodingResult> result) throws IOException {
|
double knownMinBuidlingDistance, final ResultMatcher<GeocodingResult> result) throws IOException {
|
||||||
// test address index search
|
// test address index search
|
||||||
|
@ -242,13 +241,13 @@ public class GeocodingUtilities {
|
||||||
if (streetNamePacked.size() > 0) {
|
if (streetNamePacked.size() > 0) {
|
||||||
log.info("Search street by name " + road.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);
|
||||||
if(!getSuffixesSet().contains(s) && s.length() > mainWord.length()) {
|
if (!getSuffixesSet().contains(s) && s.length() > mainWord.length()) {
|
||||||
mainWord = s;
|
mainWord = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(Algorithms.isEmpty(mainWord)) {
|
if (Algorithms.isEmpty(mainWord)) {
|
||||||
mainWord = streetNamePacked.get(0);
|
mainWord = streetNamePacked.get(0);
|
||||||
}
|
}
|
||||||
SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(
|
SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(
|
||||||
|
@ -280,17 +279,17 @@ public class GeocodingUtilities {
|
||||||
}, mainWord, StringMatcherMode.CHECK_EQUALS_FROM_SPACE);// TODO search boundaries
|
}, mainWord, StringMatcherMode.CHECK_EQUALS_FROM_SPACE);// TODO search boundaries
|
||||||
reader.searchAddressDataByName(req);
|
reader.searchAddressDataByName(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<GeocodingResult> res = new ArrayList<GeocodingResult>();
|
final List<GeocodingResult> res = new ArrayList<GeocodingResult>();
|
||||||
if(streetsList.size() == 0) {
|
if (streetsList.size() == 0) {
|
||||||
res.add(road);
|
res.add(road);
|
||||||
} else {
|
} else {
|
||||||
Collections.sort(streetsList, DISTANCE_COMPARATOR);
|
Collections.sort(streetsList, DISTANCE_COMPARATOR);
|
||||||
double streetDistance = 0;
|
double streetDistance = 0;
|
||||||
for (GeocodingResult street : streetsList) {
|
for (GeocodingResult street : streetsList) {
|
||||||
if(streetDistance == 0) {
|
if (streetDistance == 0) {
|
||||||
streetDistance = street.getDistance();
|
streetDistance = street.getDistance();
|
||||||
} else if(street.getDistance() > streetDistance + DISTANCE_STREET_FROM_CLOSEST_WITH_SAME_NAME) {
|
} else if (street.getDistance() > streetDistance + DISTANCE_STREET_FROM_CLOSEST_WITH_SAME_NAME) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
street.connectionPoint = road.connectionPoint;
|
street.connectionPoint = road.connectionPoint;
|
||||||
|
@ -325,7 +324,7 @@ public class GeocodingUtilities {
|
||||||
reader.preloadBuildings(street.street, null);
|
reader.preloadBuildings(street.street, null);
|
||||||
log.info("Preload buildings " + street.street.getName() + " " + street.city.getName() + " " + street.street.getId());
|
log.info("Preload buildings " + street.street.getName() + " " + street.city.getName() + " " + street.street.getId());
|
||||||
for (Building b : street.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();
|
||||||
|
@ -334,33 +333,33 @@ public class GeocodingUtilities {
|
||||||
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(road.searchPoint, plat, plon) < DISTANCE_BULDING_PROXIMITY) {
|
if (MapUtils.getDistance(road.searchPoint, plat, plon) < DISTANCE_BUILDING_PROXIMITY) {
|
||||||
GeocodingResult bld = new GeocodingResult(street);
|
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);
|
||||||
if(!Algorithms.isEmpty(b.getName2())) {
|
if (!Algorithms.isEmpty(b.getName2())) {
|
||||||
int fi = Algorithms.extractFirstIntegerNumber(b.getName());
|
int fi = Algorithms.extractFirstIntegerNumber(b.getName());
|
||||||
int si = Algorithms.extractFirstIntegerNumber(b.getName2());
|
int si = Algorithms.extractFirstIntegerNumber(b.getName2());
|
||||||
if(si != 0 && fi != 0) {
|
if (si != 0 && fi != 0) {
|
||||||
int num = (int) (fi + (si - fi) * coeff);
|
int num = (int) (fi + (si - fi) * coeff);
|
||||||
BuildingInterpolation type = b.getInterpolationType();
|
BuildingInterpolation type = b.getInterpolationType();
|
||||||
if(type == BuildingInterpolation.EVEN || type == BuildingInterpolation.ODD) {
|
if (type == BuildingInterpolation.EVEN || type == BuildingInterpolation.ODD) {
|
||||||
if(num % 2 == (type == BuildingInterpolation.EVEN ? 1 : 0)) {
|
if (num % 2 == (type == BuildingInterpolation.EVEN ? 1 : 0)) {
|
||||||
num --;
|
num--;
|
||||||
}
|
}
|
||||||
} else if(b.getInterpolationInterval() > 0){
|
} else if (b.getInterpolationInterval() > 0) {
|
||||||
int intv = b.getInterpolationInterval();
|
int intv = b.getInterpolationInterval();
|
||||||
if ((num - fi) % intv != 0) {
|
if ((num - fi) % intv != 0) {
|
||||||
num = ((num - fi) / intv) * intv + fi;
|
num = ((num - fi) / intv) * intv + fi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bld.buildingInterpolation = num +"";
|
bld.buildingInterpolation = num + "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (MapUtils.getDistance(b.getLocation(), road.searchPoint) < DISTANCE_BULDING_PROXIMITY) {
|
} else if (MapUtils.getDistance(b.getLocation(), road.searchPoint) < DISTANCE_BUILDING_PROXIMITY) {
|
||||||
GeocodingResult bld = new GeocodingResult(street);
|
GeocodingResult bld = new GeocodingResult(street);
|
||||||
bld.building = b;
|
bld.building = b;
|
||||||
bld.connectionPoint = b.getLocation();
|
bld.connectionPoint = b.getLocation();
|
||||||
|
|
Loading…
Reference in a new issue