Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-12-02 00:33:44 +01:00
commit ee4227c5fc

View file

@ -1,5 +1,19 @@
package net.osmand.binary; package net.osmand.binary;
import gnu.trove.set.hash.TLongHashSet;
import java.io.IOException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
@ -18,20 +32,29 @@ import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
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 String[] SUFFIXES = new String[] {"av.", "avenue", "просп.", "пер.", "пр.","заул.", "проспект", "переул.", "бул.", "бульвар", "тракт"};
public static final String[] DEFAULT_SUFFIXES = new String[] {"str.", "street", "улица", "ул."};
private static Set<String> SET_DEF_SUFFIXES = null;
private static Set<String> SET_SUFFIXES = null;
public static Set<String> getDefSuffixesSet() {
if(SET_DEF_SUFFIXES == null) {
SET_DEF_SUFFIXES = new TreeSet<String>();
SET_DEF_SUFFIXES.addAll(Arrays.asList(DEFAULT_SUFFIXES));
}
return SET_DEF_SUFFIXES;
}
public static Set<String> getSuffixesSet() {
if(SET_SUFFIXES == null) {
SET_SUFFIXES = new TreeSet<String>();
SET_SUFFIXES.addAll(Arrays.asList(SUFFIXES));
}
return SET_SUFFIXES;
}
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;
@ -155,34 +178,84 @@ public class GeocodingUtilities {
return lst; return lst;
} }
public List<String> prepareStreetName(String s) {
List<String> ls = new ArrayList<String>();
int beginning = 0;
for (int i = 1; i < s.length(); i++) {
if (s.charAt(i) == ' ') {
addWord(ls, s.substring(beginning, i));
beginning = i;
} else if (s.charAt(i) == '(') {
addWord(ls, s.substring(beginning, i));
while (i < s.length()) {
char c = s.charAt(i);
i++;
beginning = i;
if (c == ')')
break;
}
}
}
if (beginning < s.length()) {
String lastWord = s.substring(beginning, s.length());
addWord(ls, lastWord);
}
Collections.sort(ls, Collator.getInstance());
return ls;
}
private void addWord(List<String> ls, String word) {
String w = word.trim().toLowerCase();
if (!Algorithms.isEmpty(w) && !getDefSuffixesSet().contains(w)) {
ls.add(w);
}
}
public List<GeocodingResult> justifyReverseGeocodingSearch(final GeocodingResult r, BinaryMapIndexReader reader, public List<GeocodingResult> justifyReverseGeocodingSearch(final GeocodingResult r, 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>();
log.info("Search street by name " + r.streetName); final List<String> streetNamePacked = prepareStreetName(r.streetName);
SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(new ResultMatcher<MapObject>() { if (streetNamePacked.size() > 0) {
@Override log.info("Search street by name " + r.streetName + " " + streetNamePacked);
public boolean publish(MapObject object) { String mainWord = "";
if(object instanceof Street && object.getName().equalsIgnoreCase(r.streetName)) { for(int i = 0; i < streetNamePacked.size(); i++) {
double d = MapUtils.getDistance(object.getLocation(), r.searchPoint.getLatitude(), String s = streetNamePacked.get(i);
r.searchPoint.getLongitude()); if(!getSuffixesSet().contains(s) && s.length() > mainWord.length()) {
if(d < DISTANCE_STREET_NAME_PROXIMITY_BY_NAME) { mainWord = s;
GeocodingResult rs = new GeocodingResult(r);
rs.street = (Street) object;
rs.city = rs.street.getCity();
streetsList.add(rs);
return true;
}
return false;
} }
return false;
} }
@Override if(Algorithms.isEmpty(mainWord)) {
public boolean isCancelled() { mainWord = streetNamePacked.get(0);
return false;
} }
}, r.streetName); SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(
reader.searchAddressDataByName(req); new ResultMatcher<MapObject>() {
@Override
public boolean publish(MapObject object) {
if (object instanceof Street
&& prepareStreetName(object.getName()).equals(streetNamePacked)) {
double d = MapUtils.getDistance(object.getLocation(), r.searchPoint.getLatitude(),
r.searchPoint.getLongitude());
if (d < DISTANCE_STREET_NAME_PROXIMITY_BY_NAME) {
GeocodingResult rs = new GeocodingResult(r);
rs.street = (Street) object;
rs.city = rs.street.getCity();
streetsList.add(rs);
return true;
}
return false;
}
return false;
}
@Override
public boolean isCancelled() {
return false;
}
}, mainWord);
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) {