From 62b34f70a2ec2db43663689de04eb3a7aa1a4c13 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 30 Nov 2010 19:53:19 +0000 Subject: [PATCH] fix issue 184 git-svn-id: https://osmand.googlecode.com/svn/trunk@730 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/net/osmand/data/City.java | 8 +++++++ .../osmand/data/index/DataIndexReader.java | 23 ++++++++++++++++--- .../osmand/data/preparation/IndexCreator.java | 22 ++++++++++++++++-- .../src/net/osmand/osm/OSMSettings.java | 1 + 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/data/City.java b/DataExtractionOSM/src/net/osmand/data/City.java index 269971696c..80ab19704a 100644 --- a/DataExtractionOSM/src/net/osmand/data/City.java +++ b/DataExtractionOSM/src/net/osmand/data/City.java @@ -4,6 +4,7 @@ import java.text.Collator; import java.util.ArrayList; import java.util.Collection; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import net.osmand.Algoritms; @@ -48,16 +49,23 @@ public class City extends MapObject { private CityType type = null; // Be attentive ! Working with street names ignoring case private Map streets = new TreeMap(Collator.getInstance()); + private String isin = null; public City(Node el){ super(el); type = CityType.valueFromString(el.getTag(OSMTagKey.PLACE)); + isin = el.getTag(OSMTagKey.IS_IN); + isin = isin != null ? isin.toLowerCase() : null; } public City(CityType type){ this.type = type; } + public String getIsInValue() { + return isin; + } + public boolean isEmptyWithStreets(){ return streets.isEmpty(); } diff --git a/DataExtractionOSM/src/net/osmand/data/index/DataIndexReader.java b/DataExtractionOSM/src/net/osmand/data/index/DataIndexReader.java index 92a4fcc5f5..35cb11abcf 100644 --- a/DataExtractionOSM/src/net/osmand/data/index/DataIndexReader.java +++ b/DataExtractionOSM/src/net/osmand/data/index/DataIndexReader.java @@ -66,7 +66,7 @@ public class DataIndexReader { } public List readStreetsBuildings(PreparedStatement streetBuildingsStat, City city, List streets) throws SQLException { - return readStreetsBuildings(streetBuildingsStat, city, streets, null, null); + return readStreetsBuildings(streetBuildingsStat, city, streets, null, null, null); } public PreparedStatement getStreetsWayNodesPreparedStatement(Connection c) throws SQLException{ @@ -74,8 +74,26 @@ public class DataIndexReader { } public List readStreetsBuildings(PreparedStatement streetBuildingsStat, City city, List streets, - PreparedStatement waynodesStat, Map> streetNodes) throws SQLException { + PreparedStatement waynodesStat, Map> streetNodes, List citySuburbs) throws SQLException { Map visitedStreets = new LinkedHashMap(); + //read streets for city + readStreatsByBuildingsForCity(streetBuildingsStat, city, streets, + waynodesStat, streetNodes, visitedStreets); + //read streets for suburbs of the city + if (citySuburbs != null) { + for (City suburb : citySuburbs) { + readStreatsByBuildingsForCity(streetBuildingsStat, suburb, streets, waynodesStat, streetNodes, visitedStreets); + } + } + return streets; + } + + + private void readStreatsByBuildingsForCity( + PreparedStatement streetBuildingsStat, City city, + List streets, PreparedStatement waynodesStat, + Map> streetNodes, + Map visitedStreets) throws SQLException { streetBuildingsStat.setLong(1, city.getId()); ResultSet set = streetBuildingsStat.executeQuery(); while (set.next()) { @@ -112,7 +130,6 @@ public class DataIndexReader { } set.close(); - return streets; } public PreparedStatement getStreetsPreparedStatement(Connection c) throws SQLException{ diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java b/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java index ddf7acedb1..6d740a3fa2 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java @@ -2,6 +2,7 @@ package net.osmand.data.preparation; import java.awt.geom.Line2D; import java.awt.geom.Point2D; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -1907,11 +1908,28 @@ public class IndexCreator { Map> postcodes = new TreeMap>(); boolean writeCities = true; + + // collect suburbs with is in value + List suburbs = new ArrayList(); + for(City s : cities){ + if(s.getType() == CityType.SUBURB && s.getIsInValue() != null){ + suburbs.add(s); + } + } // write cities and after villages writer.startCityIndexes(false); for (int i = 0; i < cities.size(); i++) { City c = cities.get(i); + List listSuburbs = null; + for (City suburb : suburbs) { + if (suburb.getIsInValue().contains(c.getName().toLowerCase())) { + if(listSuburbs == null){ + listSuburbs = new ArrayList(); + } + listSuburbs.add(suburb); + } + } if (writeCities) { progress.progress(1); } else if ((cities.size() - i) % 100 == 0) { @@ -1929,7 +1947,7 @@ public class IndexCreator { streetNodes = new LinkedHashMap>(); } long time = System.currentTimeMillis(); - reader.readStreetsBuildings(streetstat, c, streets, waynodesStat, streetNodes); + reader.readStreetsBuildings(streetstat, c, streets, waynodesStat, streetNodes, listSuburbs); long f = System.currentTimeMillis() - time; writer.writeCityIndex(c, streets, streetNodes); int bCount = 0; @@ -2605,7 +2623,7 @@ public class IndexCreator { private NewDataExtractionOsmFilter extractOsmToNodesDB(File readFile, IProgress progress, IOsmStorageFilter addFilter) throws FileNotFoundException, IOException, SQLException, SAXException { boolean pbfFile = false; - InputStream stream = new FileInputStream(readFile); + InputStream stream = new BufferedInputStream(new FileInputStream(readFile), 8192*4);; InputStream streamFile = stream; long st = System.currentTimeMillis(); if (readFile.getName().endsWith(".bz2")) { //$NON-NLS-1$ diff --git a/DataExtractionOSM/src/net/osmand/osm/OSMSettings.java b/DataExtractionOSM/src/net/osmand/osm/OSMSettings.java index 3455e95803..3c7bec87d8 100644 --- a/DataExtractionOSM/src/net/osmand/osm/OSMSettings.java +++ b/DataExtractionOSM/src/net/osmand/osm/OSMSettings.java @@ -34,6 +34,7 @@ public class OSMSettings { ADDRESS_TYPE("address:type"), //$NON-NLS-1$ ADDRESS_HOUSE("address:house"), //$NON-NLS-1$ TYPE("type"), //$NON-NLS-1$ + IS_IN("is_in"), //$NON-NLS-1$ // POI AMENITY("amenity"), //$NON-NLS-1$