diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryInspector.java b/DataExtractionOSM/src/net/osmand/binary/BinaryInspector.java index 5d213d2162..9b602124f7 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryInspector.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryInspector.java @@ -46,7 +46,10 @@ public class BinaryInspector { public static void main(String[] args) throws IOException { inspector(args); // 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 } diff --git a/DataExtractionOSM/src/net/osmand/data/index/IndexBatchCreator.java b/DataExtractionOSM/src/net/osmand/data/index/IndexBatchCreator.java index 8444c49367..1123e2eec1 100644 --- a/DataExtractionOSM/src/net/osmand/data/index/IndexBatchCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/index/IndexBatchCreator.java @@ -434,7 +434,6 @@ public class IndexBatchCreator { indexCreator.setIndexMap(indexMap); indexCreator.setLastModifiedDate(f.lastModified()); indexCreator.setNormalizeStreets(true); - indexCreator.setSaveAddressWays(true); indexCreator.setRegionName(rName); if (regionSpecificData != null && regionSpecificData.cityAdminLevel != null) { indexCreator.setCityAdminLevel(regionSpecificData.cityAdminLevel); diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/IndexAddressCreator.java b/DataExtractionOSM/src/net/osmand/data/preparation/IndexAddressCreator.java index ef166ba25e..8ada4bc9de 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/IndexAddressCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/IndexAddressCreator.java @@ -74,7 +74,6 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{ private String[] normalizeDefaultSuffixes; private String[] normalizeSuffixes; - private boolean saveAddressWays; 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; @@ -108,7 +107,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{ public void initSettings(boolean normalizeStreets, String[] normalizeDefaultSuffixes, String[] normalizeSuffixes, - boolean saveAddressWays, String cityAdminLevel) { + String cityAdminLevel) { cities.clear(); cityManager.clear(); postalCodeRelations.clear(); @@ -116,7 +115,6 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{ this.normalizeStreets = normalizeStreets; this.normalizeDefaultSuffixes = normalizeDefaultSuffixes; this.normalizeSuffixes = normalizeSuffixes; - this.saveAddressWays = saveAddressWays; } public void registerCityIfNeeded(Entity e) { @@ -394,7 +392,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{ if (street) { for (Map.Entry r : i.getMemberEntities().entrySet()) { 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()); } } else if ("house".equals(r.getValue())) { //$NON-NLS-1$ @@ -559,7 +557,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{ SimpleStreet foundStreet = streetDAO.findStreet(name, city); 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 - if (MapUtils.getDistance(location, foundStreet.getLocation()) > 500) { + if (MapUtils.getDistance(location, foundStreet.getLocation()) > 900) { //oops, same street name within one city! if (foundStreet.getCityPart() == null) { //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) { // suppose that streets with names are ways for car // 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 (saveAddressWays) { - exist = streetDAO.findStreetNode(e); - } + boolean exist = streetDAO.findStreetNode(e); + + // check that street way is not registered already if (!exist) { ctx.loadEntityData(e); LatLon l = e.getLatLon(); Set 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); } } @@ -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$ //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$ - PreparedStatement waynodesStat = null; - if (saveAddressWays) { - waynodesStat = mapConnection.prepareStatement("SELECT A.id, A.latitude, A.longitude FROM street_node A WHERE A.street = ? "); //$NON-NLS-1$ - } + PreparedStatement 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 List suburbs = new ArrayList(); @@ -934,7 +929,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{ progress.progress(1); } } - Map> streetNodes = waynodesStat == null ? null : new LinkedHashMap>(); + Map> streetNodes = new LinkedHashMap>(); List listSuburbs = null; if (suburbs != null) { for (City suburb : suburbs) { @@ -1024,20 +1019,19 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{ Map> streetNodes, List citySuburbs) throws SQLException { TLongObjectHashMap visitedStreets = new TLongObjectHashMap(); Map> uniqueNames = new HashMap>(); - Map streets = new HashMap(); // 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 if (citySuburbs != null) { for (City suburb : citySuburbs) { - readStreatsByBuildingsForCity(streetBuildingsStat, suburb, streets, waynodesStat, streetNodes, visitedStreets, uniqueNames); + readStreetsByBuildingsForCity(streetBuildingsStat, suburb, waynodesStat, streetNodes, visitedStreets, uniqueNames); } } - return new ArrayList(streets.values()); + return new ArrayList(streetNodes.keySet()); } - private void readStreatsByBuildingsForCity(PreparedStatement streetBuildingsStat, City city, Map streets, + private void readStreetsByBuildingsForCity(PreparedStatement streetBuildingsStat, City city, PreparedStatement waynodesStat, Map> streetNodes, TLongObjectHashMap visitedStreets, Map> uniqueNames) throws SQLException { streetBuildingsStat.setLong(1, city.getId()); @@ -1050,24 +1044,16 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{ street.setLocation(set.getDouble(4), set.getDouble(5)); street.setId(streetId); // load the street nodes - loadStreetNodes(street, waynodesStat, streetNodes); + List thisWayNodes = loadStreetNodes(streetId, waynodesStat); // 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 String defaultDistrict = set.getString(12); - String district = identifyBestDistrict(street, streetName, " (" + defaultDistrict + ")", uniqueNames, streetNodes); - street.setName(streetName + district); - street.setEnName(set.getString(3) + district); - // if for this street there is already same street, add just nodes to the street. - if (!streets.containsKey(street.getName())) { - streets.put(street.getName(), street); - } else { - // add the current streetNodes to the existing street - List firstStreetNodes = streetNodes.get(streets.get(street.getName())); - if (firstStreetNodes != null && streetNodes.get(street) != null) { - firstStreetNodes.addAll(streetNodes.get(street)); - } - } + StreetAndDistrict sandd = identifyBestDistrictAndUpdatename(street, streetName, + set.getString(3), defaultDistrict == null? "" : " (" + defaultDistrict + ")", + uniqueNames, streetNodes, thisWayNodes); + // use already registered + street = sandd.getStreet(); visitedStreets.put(streetId, street); // mark the street as visited } if (set.getObject(6) != null) { @@ -1100,26 +1086,22 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{ } - private void loadStreetNodes(Street street, PreparedStatement waynodesStat, Map> streetNodes) - throws SQLException { - if (waynodesStat != null && streetNodes != null) { - List list = streetNodes.get(street); - if (list == null) { - list = new ArrayList(); - 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(); + private List loadStreetNodes(long streetId, PreparedStatement waynodesStat) throws SQLException { + List list = new ArrayList(); + waynodesStat.setLong(1, streetId); + ResultSet rs = waynodesStat.executeQuery(); + while (rs.next()) { + list.add(new Node(rs.getDouble(2), rs.getDouble(3), rs.getLong(1))); } + rs.close(); + return list; } - private String identifyBestDistrict(final Street street, final String streetName, final String district, - final Map> uniqueNames, Map> streetNodes) { + private StreetAndDistrict identifyBestDistrictAndUpdatename(final Street street, + final String streetName, final String streetEnName, + final String district, final Map> uniqueNames, + Map> streetNodes, List thisWayNodes) { String result = DEBUG_FULL_NAMES ? district : ""; //TODO make it an option List sameStreets = uniqueNames.get(streetName); if (sameStreets == null) { @@ -1129,26 +1111,30 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{ result = district; // not unique, try to find best matching street with district // 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! if (streetNodes != null) { - for (Node n1 : streetNodes.get(street)) { + for (Node n1 : thisWayNodes) { for (Node n2 : streetNodes.get(ld.getStreet())) { if (MapUtils.getDistance(n1.getLatLon(), n2.getLatLon()) < 400) { - result = ld.getDistrict(); - break similarStreets; + streetNodes.get(ld.getStreet()).addAll(thisWayNodes); + return ld; } } } } if (MapUtils.getDistance(ld.getStreet().getLocation(), street.getLocation()) < 400) { - result = ld.getDistrict(); - break; + streetNodes.get(ld.getStreet()).addAll(thisWayNodes); + return ld; } } } - sameStreets.add(new StreetAndDistrict(street, result)); - return result; + StreetAndDistrict ld = new StreetAndDistrict(street, result); + street.setName(streetName + result); + street.setEnName(streetEnName + result); + streetNodes.put(street, thisWayNodes); + sameStreets.add(ld); + return ld; } diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java b/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java index c2083e3070..491f26f201 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java @@ -68,7 +68,6 @@ public class IndexCreator { private boolean indexRouting /*= true*/; private boolean normalizeStreets = true; // true by default - private boolean saveAddressWays = true; // true by default private int zoomWaySmothness = 2; private String regionName; @@ -122,10 +121,6 @@ public class IndexCreator { this.indexTransport = indexTransport; } - public void setSaveAddressWays(boolean saveAddressWays) { - this.saveAddressWays = saveAddressWays; - } - public void setNormalizeStreets(boolean normalizeStreets) { this.normalizeStreets = normalizeStreets; } @@ -478,7 +473,7 @@ public class IndexCreator { normalizeDefaultSuffixes = DataExtractionSettings.getSettings().getDefaultSuffixesToNormalizeStreets(); normalizeSuffixes = DataExtractionSettings.getSettings().getSuffixesToNormalizeStreets(); } - indexAddressCreator.initSettings(normalizeStreets, normalizeDefaultSuffixes, normalizeSuffixes, saveAddressWays, cityAdminLevel); + indexAddressCreator.initSettings(normalizeStreets, normalizeDefaultSuffixes, normalizeSuffixes, cityAdminLevel); // Main generation method try { @@ -745,7 +740,7 @@ public class IndexCreator { public static void main(String[] args) throws IOException, SAXException, SQLException, InterruptedException { long time = System.currentTimeMillis(); 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.setIndexPOI(true); creator.setIndexTransport(false);