implement

git-svn-id: https://osmand.googlecode.com/svn/trunk@71 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-05-20 12:33:51 +00:00
parent f934e9add1
commit 79d2745427
2 changed files with 62 additions and 22 deletions

View file

@ -90,6 +90,14 @@ public class DataExtraction {
public static String writeTestOsmFile = "C:\\1_tmp.osm"; // could be null - wo writing public static String writeTestOsmFile = "C:\\1_tmp.osm"; // could be null - wo writing
private static boolean parseSmallFile = true; private static boolean parseSmallFile = true;
private static boolean parseOSM = true; private static boolean parseOSM = true;
private final boolean loadAllObjects;
private final boolean normalizeStreets;
private final boolean indexAddress;
private final boolean indexPOI;
@ -113,8 +121,9 @@ public class DataExtraction {
} }
// TODO add interested objects
List<Long> interestedObjects = new ArrayList<Long>(); List<Long> interestedObjects = new ArrayList<Long>();
// add interested objects
if (writeTestOsmFile != null) { if (writeTestOsmFile != null) {
OsmStorageWriter writer = new OsmStorageWriter(); OsmStorageWriter writer = new OsmStorageWriter();
OutputStream output = new FileOutputStream(writeTestOsmFile); OutputStream output = new FileOutputStream(writeTestOsmFile);
@ -132,6 +141,21 @@ public class DataExtraction {
System.out.println("USED Memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1e6); System.out.println("USED Memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1e6);
System.out.println("TIME : " + (System.currentTimeMillis() - st)); System.out.println("TIME : " + (System.currentTimeMillis() - st));
} }
public DataExtraction(){
this.indexPOI = true;
this.indexAddress = true;
this.loadAllObjects = false;
this.normalizeStreets = true;
}
public DataExtraction(boolean indexAddress, boolean indexPOI, boolean normalizeStreets, boolean loadAllObjects){
this.indexAddress = indexAddress;
this.indexPOI = indexPOI;
this.normalizeStreets = normalizeStreets;
this.loadAllObjects = loadAllObjects;
}
public Region readCountry(String path, IProgress progress, IOsmStorageFilter addFilter) throws IOException, SAXException{ public Region readCountry(String path, IProgress progress, IOsmStorageFilter addFilter) throws IOException, SAXException{
@ -160,13 +184,15 @@ public class DataExtraction {
IOsmStorageFilter filter = new IOsmStorageFilter(){ IOsmStorageFilter filter = new IOsmStorageFilter(){
@Override @Override
public boolean acceptEntityToLoad(OsmBaseStorage storage, Entity e) { public boolean acceptEntityToLoad(OsmBaseStorage storage, Entity e) {
if ("yes".equals(e.getTag(OSMTagKey.BUILDING))) { if (indexAddress) {
if (e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER) != null && e.getTag(OSMTagKey.ADDR_STREET) != null) { if ("yes".equals(e.getTag(OSMTagKey.BUILDING))) {
buildings.add(e); if (e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER) != null && e.getTag(OSMTagKey.ADDR_STREET) != null) {
return true; buildings.add(e);
return true;
}
} }
} }
if(Amenity.isAmenity(e)){ if (indexPOI && Amenity.isAmenity(e)) {
amenities.add(new Amenity((Node) e)); amenities.add(new Amenity((Node) e));
return true; return true;
} }
@ -174,11 +200,13 @@ public class DataExtraction {
places.add((Node) e); places.add((Node) e);
return true; return true;
} }
if (e instanceof Way && OSMSettings.wayForCar(e.getTag(OSMTagKey.HIGHWAY))) { if (indexAddress) {
ways.add((Way) e); if (e instanceof Way && OSMSettings.wayForCar(e.getTag(OSMTagKey.HIGHWAY))) {
return true; ways.add((Way) e);
return true;
}
} }
return e instanceof Node; return (e instanceof Node && indexAddress) || loadAllObjects;
} }
}; };
@ -200,19 +228,25 @@ public class DataExtraction {
country.setStorage(storage); country.setStorage(storage);
// 2. Reading amenities // 2. Reading amenities
readingAmenities(amenities, country); if(indexPOI){
readingAmenities(amenities, country);
}
// 3. Reading cities // 3. Reading cities
readingCities(places, country); readingCities(places, country);
// 4. Reading streets if (indexAddress) {
readingStreets(progress, ways, country); // 4. Reading streets
readingStreets(progress, ways, country);
// 5. reading buildings
readingBuildings(progress, buildings, country);
}
// 5. reading buildings if(normalizeStreets){
readingBuildings(progress, buildings, country); // 6. normalizing streets
normalizingStreets(progress, country);
// 6. normalizing streets }
normalizingStreets(progress, country);
country.doDataPreparation(); country.doDataPreparation();
return country; return country;
@ -367,9 +401,6 @@ public class DataExtraction {
} }
} }
if (processed) { if (processed) {
if(c.getStreet(name) != s){
System.out.println(name);
}
s.setName(newName); s.setName(newName);
} }
} }

View file

@ -114,6 +114,7 @@ public class OsmExtractionUI implements IMapLocationListener {
private JCheckBox normalizingStreets; private JCheckBox normalizingStreets;
private TreeModelListener treeModelListener; private TreeModelListener treeModelListener;
private JCheckBox zipIndexFiles; private JCheckBox zipIndexFiles;
private JCheckBox loadingAllData;
@ -299,6 +300,7 @@ public class OsmExtractionUI implements IMapLocationListener {
protected void updateButtonsBar() { protected void updateButtonsBar() {
generateDataButton.setEnabled(region != null); generateDataButton.setEnabled(region != null);
normalizingStreets.setVisible(region == null); normalizingStreets.setVisible(region == null);
loadingAllData.setVisible(region == null);
buildAddressIndex.setEnabled(region == null || region.getCitiesCount(null) > 0); buildAddressIndex.setEnabled(region == null || region.getCitiesCount(null) > 0);
buildPoiIndex.setEnabled(region == null || !region.getAmenityManager().isEmpty()); buildPoiIndex.setEnabled(region == null || !region.getAmenityManager().isEmpty());
zipIndexFiles.setVisible(region != null); zipIndexFiles.setVisible(region != null);
@ -334,6 +336,11 @@ public class OsmExtractionUI implements IMapLocationListener {
normalizingStreets.setText("Normalizing streets"); normalizingStreets.setText("Normalizing streets");
panel.add(normalizingStreets); panel.add(normalizingStreets);
normalizingStreets.setSelected(true); normalizingStreets.setSelected(true);
loadingAllData = new JCheckBox();
loadingAllData.setText("Loading all osm data");
panel.add(loadingAllData);
loadingAllData.setSelected(false);
zipIndexFiles = new JCheckBox(); zipIndexFiles = new JCheckBox();
zipIndexFiles.setText("Zip index files"); zipIndexFiles.setText("Zip index files");
@ -621,7 +628,9 @@ public class OsmExtractionUI implements IMapLocationListener {
public void run() { public void run() {
Region res; Region res;
try { try {
res = new DataExtraction().readCountry(f.getAbsolutePath(), dlg, filter); DataExtraction dataExtraction = new DataExtraction(buildAddressIndex.isSelected(), buildPoiIndex.isSelected(),
normalizingStreets.isSelected(), loadingAllData.isSelected());
res = dataExtraction.readCountry(f.getAbsolutePath(), dlg, filter);
} catch (IOException e) { } catch (IOException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
} catch (SAXException e) { } catch (SAXException e) {