fix issue 184

git-svn-id: https://osmand.googlecode.com/svn/trunk@730 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-11-30 19:53:19 +00:00
parent 01a584e43a
commit 62b34f70a2
4 changed files with 49 additions and 5 deletions

View file

@ -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<String, Street> streets = new TreeMap<String, Street>(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();
}

View file

@ -66,7 +66,7 @@ public class DataIndexReader {
}
public List<Street> readStreetsBuildings(PreparedStatement streetBuildingsStat, City city, List<Street> 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<Street> readStreetsBuildings(PreparedStatement streetBuildingsStat, City city, List<Street> streets,
PreparedStatement waynodesStat, Map<Street, List<Node>> streetNodes) throws SQLException {
PreparedStatement waynodesStat, Map<Street, List<Node>> streetNodes, List<City> citySuburbs) throws SQLException {
Map<Long, Street> visitedStreets = new LinkedHashMap<Long, Street>();
//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<Street> streets, PreparedStatement waynodesStat,
Map<Street, List<Node>> streetNodes,
Map<Long, Street> 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{

View file

@ -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<String, Set<Street>> postcodes = new TreeMap<String, Set<Street>>();
boolean writeCities = true;
// collect suburbs with is in value
List<City> suburbs = new ArrayList<City>();
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<City> listSuburbs = null;
for (City suburb : suburbs) {
if (suburb.getIsInValue().contains(c.getName().toLowerCase())) {
if(listSuburbs == null){
listSuburbs = new ArrayList<City>();
}
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<Street, List<Node>>();
}
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$

View file

@ -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$