Fix issue with buildings
This commit is contained in:
parent
6ab3dced75
commit
68ccbe0450
4 changed files with 51 additions and 68 deletions
|
@ -46,7 +46,10 @@ public class BinaryInspector {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
inspector(args);
|
inspector(args);
|
||||||
// test cases show info
|
// test cases show info
|
||||||
inspector(new String[]{"-vmap", "/home/victor/projects/OsmAnd/data/osm-gen/Map.obf"});
|
|
||||||
|
|
||||||
|
inspector(new String[]{"-vaddress", "/home/victor/projects/OsmAnd/data/osm-gen/Map.obf"});
|
||||||
|
// inspector(new String[]{"-vaddress", "-bbox=18.05,48.33,18.12,48.28", "/home/victor/projects/OsmAnd/temp/Slovakia_europe.obf"});
|
||||||
// test case extract parts
|
// test case extract parts
|
||||||
// test case
|
// test case
|
||||||
}
|
}
|
||||||
|
|
|
@ -434,7 +434,6 @@ public class IndexBatchCreator {
|
||||||
indexCreator.setIndexMap(indexMap);
|
indexCreator.setIndexMap(indexMap);
|
||||||
indexCreator.setLastModifiedDate(f.lastModified());
|
indexCreator.setLastModifiedDate(f.lastModified());
|
||||||
indexCreator.setNormalizeStreets(true);
|
indexCreator.setNormalizeStreets(true);
|
||||||
indexCreator.setSaveAddressWays(true);
|
|
||||||
indexCreator.setRegionName(rName);
|
indexCreator.setRegionName(rName);
|
||||||
if (regionSpecificData != null && regionSpecificData.cityAdminLevel != null) {
|
if (regionSpecificData != null && regionSpecificData.cityAdminLevel != null) {
|
||||||
indexCreator.setCityAdminLevel(regionSpecificData.cityAdminLevel);
|
indexCreator.setCityAdminLevel(regionSpecificData.cityAdminLevel);
|
||||||
|
|
|
@ -74,7 +74,6 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
private String[] normalizeDefaultSuffixes;
|
private String[] normalizeDefaultSuffixes;
|
||||||
private String[] normalizeSuffixes;
|
private String[] normalizeSuffixes;
|
||||||
|
|
||||||
private boolean saveAddressWays;
|
|
||||||
private boolean DEBUG_FULL_NAMES = false; //true to see atached cityPart and boundaries to the street names
|
private boolean DEBUG_FULL_NAMES = false; //true to see atached cityPart and boundaries to the street names
|
||||||
private final int ADDRESS_NAME_CHARACTERS_TO_INDEX = 4;
|
private final int ADDRESS_NAME_CHARACTERS_TO_INDEX = 4;
|
||||||
|
|
||||||
|
@ -108,7 +107,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
|
|
||||||
|
|
||||||
public void initSettings(boolean normalizeStreets, String[] normalizeDefaultSuffixes, String[] normalizeSuffixes,
|
public void initSettings(boolean normalizeStreets, String[] normalizeDefaultSuffixes, String[] normalizeSuffixes,
|
||||||
boolean saveAddressWays, String cityAdminLevel) {
|
String cityAdminLevel) {
|
||||||
cities.clear();
|
cities.clear();
|
||||||
cityManager.clear();
|
cityManager.clear();
|
||||||
postalCodeRelations.clear();
|
postalCodeRelations.clear();
|
||||||
|
@ -116,7 +115,6 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
this.normalizeStreets = normalizeStreets;
|
this.normalizeStreets = normalizeStreets;
|
||||||
this.normalizeDefaultSuffixes = normalizeDefaultSuffixes;
|
this.normalizeDefaultSuffixes = normalizeDefaultSuffixes;
|
||||||
this.normalizeSuffixes = normalizeSuffixes;
|
this.normalizeSuffixes = normalizeSuffixes;
|
||||||
this.saveAddressWays = saveAddressWays;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerCityIfNeeded(Entity e) {
|
public void registerCityIfNeeded(Entity e) {
|
||||||
|
@ -394,7 +392,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
if (street) {
|
if (street) {
|
||||||
for (Map.Entry<Entity, String> r : i.getMemberEntities().entrySet()) {
|
for (Map.Entry<Entity, String> r : i.getMemberEntities().entrySet()) {
|
||||||
if ("street".equals(r.getValue())) { //$NON-NLS-1$
|
if ("street".equals(r.getValue())) { //$NON-NLS-1$
|
||||||
if (r.getKey() instanceof Way && saveAddressWays) {
|
if (r.getKey() instanceof Way) {
|
||||||
streetDAO.writeStreetWayNodes(streetId, (Way) r.getKey());
|
streetDAO.writeStreetWayNodes(streetId, (Way) r.getKey());
|
||||||
}
|
}
|
||||||
} else if ("house".equals(r.getValue())) { //$NON-NLS-1$
|
} else if ("house".equals(r.getValue())) { //$NON-NLS-1$
|
||||||
|
@ -559,7 +557,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
SimpleStreet foundStreet = streetDAO.findStreet(name, city);
|
SimpleStreet foundStreet = streetDAO.findStreet(name, city);
|
||||||
if (foundStreet != null) {
|
if (foundStreet != null) {
|
||||||
//matching the nodes is done somewhere else. This is just a simple check if the streets are really close to each other
|
//matching the nodes is done somewhere else. This is just a simple check if the streets are really close to each other
|
||||||
if (MapUtils.getDistance(location, foundStreet.getLocation()) > 500) {
|
if (MapUtils.getDistance(location, foundStreet.getLocation()) > 900) {
|
||||||
//oops, same street name within one city!
|
//oops, same street name within one city!
|
||||||
if (foundStreet.getCityPart() == null) {
|
if (foundStreet.getCityPart() == null) {
|
||||||
//we need to update the city part first
|
//we need to update the city part first
|
||||||
|
@ -732,19 +730,18 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
&& e.getTag(OSMTagKey.HIGHWAY) != null && e.getTag(OSMTagKey.NAME) != null) {
|
&& e.getTag(OSMTagKey.HIGHWAY) != null && e.getTag(OSMTagKey.NAME) != null) {
|
||||||
// suppose that streets with names are ways for car
|
// suppose that streets with names are ways for car
|
||||||
// Ignore all ways that have house numbers and highway type
|
// Ignore all ways that have house numbers and highway type
|
||||||
boolean exist = false;
|
|
||||||
|
|
||||||
// if we saved address ways we could checked that we registered before
|
// if we saved address ways we could checked that we registered before
|
||||||
if (saveAddressWays) {
|
boolean exist = streetDAO.findStreetNode(e);
|
||||||
exist = streetDAO.findStreetNode(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check that street way is not registered already
|
// check that street way is not registered already
|
||||||
if (!exist) {
|
if (!exist) {
|
||||||
ctx.loadEntityData(e);
|
ctx.loadEntityData(e);
|
||||||
LatLon l = e.getLatLon();
|
LatLon l = e.getLatLon();
|
||||||
Set<Long> idsOfStreet = getStreetInCity(e.getIsInNames(), e.getTag(OSMTagKey.NAME), e.getTag(OSMTagKey.NAME_EN), l);
|
Set<Long> idsOfStreet = getStreetInCity(e.getIsInNames(), e.getTag(OSMTagKey.NAME), e.getTag(OSMTagKey.NAME_EN), l);
|
||||||
if (!idsOfStreet.isEmpty() && saveAddressWays) {
|
if (!idsOfStreet.isEmpty()) {
|
||||||
streetDAO.writeStreetWayNodes(idsOfStreet, (Way) e);
|
streetDAO.writeStreetWayNodes(idsOfStreet, (Way) e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -818,10 +815,8 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
"FROM street A left JOIN building B ON B.street = A.id JOIN city C ON A.city = C.id " + //$NON-NLS-1$
|
"FROM street A left JOIN building B ON B.street = A.id JOIN city C ON A.city = C.id " + //$NON-NLS-1$
|
||||||
//with this order by we get the streets directly in city to not have the suffix if duplication
|
//with this order by we get the streets directly in city to not have the suffix if duplication
|
||||||
"WHERE A.city = ? ORDER BY C.name == A.cityPart DESC"); //$NON-NLS-1$
|
"WHERE A.city = ? ORDER BY C.name == A.cityPart DESC"); //$NON-NLS-1$
|
||||||
PreparedStatement waynodesStat = null;
|
PreparedStatement waynodesStat =
|
||||||
if (saveAddressWays) {
|
mapConnection.prepareStatement("SELECT A.id, A.latitude, A.longitude FROM street_node A WHERE A.street = ? "); //$NON-NLS-1$
|
||||||
waynodesStat = mapConnection.prepareStatement("SELECT A.id, A.latitude, A.longitude FROM street_node A WHERE A.street = ? "); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
// collect suburbs with is in value
|
// collect suburbs with is in value
|
||||||
List<City> suburbs = new ArrayList<City>();
|
List<City> suburbs = new ArrayList<City>();
|
||||||
|
@ -934,7 +929,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
progress.progress(1);
|
progress.progress(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<Street, List<Node>> streetNodes = waynodesStat == null ? null : new LinkedHashMap<Street, List<Node>>();
|
Map<Street, List<Node>> streetNodes = new LinkedHashMap<Street, List<Node>>();
|
||||||
List<City> listSuburbs = null;
|
List<City> listSuburbs = null;
|
||||||
if (suburbs != null) {
|
if (suburbs != null) {
|
||||||
for (City suburb : suburbs) {
|
for (City suburb : suburbs) {
|
||||||
|
@ -1024,20 +1019,19 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
Map<Street, List<Node>> streetNodes, List<City> citySuburbs) throws SQLException {
|
Map<Street, List<Node>> streetNodes, List<City> citySuburbs) throws SQLException {
|
||||||
TLongObjectHashMap<Street> visitedStreets = new TLongObjectHashMap<Street>();
|
TLongObjectHashMap<Street> visitedStreets = new TLongObjectHashMap<Street>();
|
||||||
Map<String, List<StreetAndDistrict>> uniqueNames = new HashMap<String, List<StreetAndDistrict>>();
|
Map<String, List<StreetAndDistrict>> uniqueNames = new HashMap<String, List<StreetAndDistrict>>();
|
||||||
Map<String, Street> streets = new HashMap<String, Street>();
|
|
||||||
|
|
||||||
// read streets for city
|
// read streets for city
|
||||||
readStreatsByBuildingsForCity(streetBuildingsStat, city, streets, waynodesStat, streetNodes, visitedStreets, uniqueNames);
|
readStreetsByBuildingsForCity(streetBuildingsStat, city, waynodesStat, streetNodes, visitedStreets, uniqueNames);
|
||||||
// read streets for suburbs of the city
|
// read streets for suburbs of the city
|
||||||
if (citySuburbs != null) {
|
if (citySuburbs != null) {
|
||||||
for (City suburb : citySuburbs) {
|
for (City suburb : citySuburbs) {
|
||||||
readStreatsByBuildingsForCity(streetBuildingsStat, suburb, streets, waynodesStat, streetNodes, visitedStreets, uniqueNames);
|
readStreetsByBuildingsForCity(streetBuildingsStat, suburb, waynodesStat, streetNodes, visitedStreets, uniqueNames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ArrayList<Street>(streets.values());
|
return new ArrayList<Street>(streetNodes.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readStreatsByBuildingsForCity(PreparedStatement streetBuildingsStat, City city, Map<String, Street> streets,
|
private void readStreetsByBuildingsForCity(PreparedStatement streetBuildingsStat, City city,
|
||||||
PreparedStatement waynodesStat, Map<Street, List<Node>> streetNodes, TLongObjectHashMap<Street> visitedStreets,
|
PreparedStatement waynodesStat, Map<Street, List<Node>> streetNodes, TLongObjectHashMap<Street> visitedStreets,
|
||||||
Map<String, List<StreetAndDistrict>> uniqueNames) throws SQLException {
|
Map<String, List<StreetAndDistrict>> uniqueNames) throws SQLException {
|
||||||
streetBuildingsStat.setLong(1, city.getId());
|
streetBuildingsStat.setLong(1, city.getId());
|
||||||
|
@ -1050,24 +1044,16 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
street.setLocation(set.getDouble(4), set.getDouble(5));
|
street.setLocation(set.getDouble(4), set.getDouble(5));
|
||||||
street.setId(streetId);
|
street.setId(streetId);
|
||||||
// load the street nodes
|
// load the street nodes
|
||||||
loadStreetNodes(street, waynodesStat, streetNodes);
|
List<Node> thisWayNodes = loadStreetNodes(streetId, waynodesStat);
|
||||||
|
|
||||||
// If there are more streets with same name in different districts.
|
// If there are more streets with same name in different districts.
|
||||||
// Add district name to all other names. If sorting is right, the first street was the one in the city
|
// Add district name to all other names. If sorting is right, the first street was the one in the city
|
||||||
String defaultDistrict = set.getString(12);
|
String defaultDistrict = set.getString(12);
|
||||||
String district = identifyBestDistrict(street, streetName, " (" + defaultDistrict + ")", uniqueNames, streetNodes);
|
StreetAndDistrict sandd = identifyBestDistrictAndUpdatename(street, streetName,
|
||||||
street.setName(streetName + district);
|
set.getString(3), defaultDistrict == null? "" : " (" + defaultDistrict + ")",
|
||||||
street.setEnName(set.getString(3) + district);
|
uniqueNames, streetNodes, thisWayNodes);
|
||||||
// if for this street there is already same street, add just nodes to the street.
|
// use already registered
|
||||||
if (!streets.containsKey(street.getName())) {
|
street = sandd.getStreet();
|
||||||
streets.put(street.getName(), street);
|
|
||||||
} else {
|
|
||||||
// add the current streetNodes to the existing street
|
|
||||||
List<Node> firstStreetNodes = streetNodes.get(streets.get(street.getName()));
|
|
||||||
if (firstStreetNodes != null && streetNodes.get(street) != null) {
|
|
||||||
firstStreetNodes.addAll(streetNodes.get(street));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
visitedStreets.put(streetId, street); // mark the street as visited
|
visitedStreets.put(streetId, street); // mark the street as visited
|
||||||
}
|
}
|
||||||
if (set.getObject(6) != null) {
|
if (set.getObject(6) != null) {
|
||||||
|
@ -1100,26 +1086,22 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void loadStreetNodes(Street street, PreparedStatement waynodesStat, Map<Street, List<Node>> streetNodes)
|
private List<Node> loadStreetNodes(long streetId, PreparedStatement waynodesStat) throws SQLException {
|
||||||
throws SQLException {
|
List<Node> list = new ArrayList<Node>();
|
||||||
if (waynodesStat != null && streetNodes != null) {
|
waynodesStat.setLong(1, streetId);
|
||||||
List<Node> list = streetNodes.get(street);
|
ResultSet rs = waynodesStat.executeQuery();
|
||||||
if (list == null) {
|
while (rs.next()) {
|
||||||
list = new ArrayList<Node>();
|
list.add(new Node(rs.getDouble(2), rs.getDouble(3), rs.getLong(1)));
|
||||||
streetNodes.put(street, list);
|
|
||||||
}
|
|
||||||
waynodesStat.setLong(1, street.getId());
|
|
||||||
ResultSet rs = waynodesStat.executeQuery();
|
|
||||||
while (rs.next()) {
|
|
||||||
list.add(new Node(rs.getDouble(2), rs.getDouble(3), rs.getLong(1)));
|
|
||||||
}
|
|
||||||
rs.close();
|
|
||||||
}
|
}
|
||||||
|
rs.close();
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String identifyBestDistrict(final Street street, final String streetName, final String district,
|
private StreetAndDistrict identifyBestDistrictAndUpdatename(final Street street,
|
||||||
final Map<String, List<StreetAndDistrict>> uniqueNames, Map<Street, List<Node>> streetNodes) {
|
final String streetName, final String streetEnName,
|
||||||
|
final String district, final Map<String, List<StreetAndDistrict>> uniqueNames,
|
||||||
|
Map<Street, List<Node>> streetNodes, List<Node> thisWayNodes) {
|
||||||
String result = DEBUG_FULL_NAMES ? district : ""; //TODO make it an option
|
String result = DEBUG_FULL_NAMES ? district : ""; //TODO make it an option
|
||||||
List<StreetAndDistrict> sameStreets = uniqueNames.get(streetName);
|
List<StreetAndDistrict> sameStreets = uniqueNames.get(streetName);
|
||||||
if (sameStreets == null) {
|
if (sameStreets == null) {
|
||||||
|
@ -1129,26 +1111,30 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
|
||||||
result = district;
|
result = district;
|
||||||
// not unique, try to find best matching street with district
|
// not unique, try to find best matching street with district
|
||||||
// if not found, use the one that is assign to this street
|
// if not found, use the one that is assign to this street
|
||||||
similarStreets: for (StreetAndDistrict ld : sameStreets) {
|
for (StreetAndDistrict ld : sameStreets) {
|
||||||
//try to find the closes nodes to each other!
|
//try to find the closes nodes to each other!
|
||||||
if (streetNodes != null) {
|
if (streetNodes != null) {
|
||||||
for (Node n1 : streetNodes.get(street)) {
|
for (Node n1 : thisWayNodes) {
|
||||||
for (Node n2 : streetNodes.get(ld.getStreet())) {
|
for (Node n2 : streetNodes.get(ld.getStreet())) {
|
||||||
if (MapUtils.getDistance(n1.getLatLon(), n2.getLatLon()) < 400) {
|
if (MapUtils.getDistance(n1.getLatLon(), n2.getLatLon()) < 400) {
|
||||||
result = ld.getDistrict();
|
streetNodes.get(ld.getStreet()).addAll(thisWayNodes);
|
||||||
break similarStreets;
|
return ld;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (MapUtils.getDistance(ld.getStreet().getLocation(), street.getLocation()) < 400) {
|
if (MapUtils.getDistance(ld.getStreet().getLocation(), street.getLocation()) < 400) {
|
||||||
result = ld.getDistrict();
|
streetNodes.get(ld.getStreet()).addAll(thisWayNodes);
|
||||||
break;
|
return ld;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sameStreets.add(new StreetAndDistrict(street, result));
|
StreetAndDistrict ld = new StreetAndDistrict(street, result);
|
||||||
return result;
|
street.setName(streetName + result);
|
||||||
|
street.setEnName(streetEnName + result);
|
||||||
|
streetNodes.put(street, thisWayNodes);
|
||||||
|
sameStreets.add(ld);
|
||||||
|
return ld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,6 @@ public class IndexCreator {
|
||||||
private boolean indexRouting /*= true*/;
|
private boolean indexRouting /*= true*/;
|
||||||
|
|
||||||
private boolean normalizeStreets = true; // true by default
|
private boolean normalizeStreets = true; // true by default
|
||||||
private boolean saveAddressWays = true; // true by default
|
|
||||||
private int zoomWaySmothness = 2;
|
private int zoomWaySmothness = 2;
|
||||||
|
|
||||||
private String regionName;
|
private String regionName;
|
||||||
|
@ -122,10 +121,6 @@ public class IndexCreator {
|
||||||
this.indexTransport = indexTransport;
|
this.indexTransport = indexTransport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSaveAddressWays(boolean saveAddressWays) {
|
|
||||||
this.saveAddressWays = saveAddressWays;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNormalizeStreets(boolean normalizeStreets) {
|
public void setNormalizeStreets(boolean normalizeStreets) {
|
||||||
this.normalizeStreets = normalizeStreets;
|
this.normalizeStreets = normalizeStreets;
|
||||||
}
|
}
|
||||||
|
@ -478,7 +473,7 @@ public class IndexCreator {
|
||||||
normalizeDefaultSuffixes = DataExtractionSettings.getSettings().getDefaultSuffixesToNormalizeStreets();
|
normalizeDefaultSuffixes = DataExtractionSettings.getSettings().getDefaultSuffixesToNormalizeStreets();
|
||||||
normalizeSuffixes = DataExtractionSettings.getSettings().getSuffixesToNormalizeStreets();
|
normalizeSuffixes = DataExtractionSettings.getSettings().getSuffixesToNormalizeStreets();
|
||||||
}
|
}
|
||||||
indexAddressCreator.initSettings(normalizeStreets, normalizeDefaultSuffixes, normalizeSuffixes, saveAddressWays, cityAdminLevel);
|
indexAddressCreator.initSettings(normalizeStreets, normalizeDefaultSuffixes, normalizeSuffixes, cityAdminLevel);
|
||||||
|
|
||||||
// Main generation method
|
// Main generation method
|
||||||
try {
|
try {
|
||||||
|
@ -745,7 +740,7 @@ public class IndexCreator {
|
||||||
public static void main(String[] args) throws IOException, SAXException, SQLException, InterruptedException {
|
public static void main(String[] args) throws IOException, SAXException, SQLException, InterruptedException {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
IndexCreator creator = new IndexCreator(new File("/home/victor/projects/OsmAnd/data/osm-gen/")); //$NON-NLS-1$
|
IndexCreator creator = new IndexCreator(new File("/home/victor/projects/OsmAnd/data/osm-gen/")); //$NON-NLS-1$
|
||||||
creator.setIndexMap(true);
|
creator.setIndexMap(false);
|
||||||
creator.setIndexAddress(true);
|
creator.setIndexAddress(true);
|
||||||
creator.setIndexPOI(true);
|
creator.setIndexPOI(true);
|
||||||
creator.setIndexTransport(false);
|
creator.setIndexTransport(false);
|
||||||
|
|
Loading…
Reference in a new issue