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

@ -91,6 +91,14 @@ public class DataExtraction {
private static boolean parseSmallFile = 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>();
// add interested objects
if (writeTestOsmFile != null) {
OsmStorageWriter writer = new OsmStorageWriter();
OutputStream output = new FileOutputStream(writeTestOsmFile);
@ -133,6 +142,21 @@ public class DataExtraction {
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{
File f = new File(path);
@ -160,13 +184,15 @@ public class DataExtraction {
IOsmStorageFilter filter = new IOsmStorageFilter(){
@Override
public boolean acceptEntityToLoad(OsmBaseStorage storage, Entity e) {
if (indexAddress) {
if ("yes".equals(e.getTag(OSMTagKey.BUILDING))) {
if (e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER) != null && e.getTag(OSMTagKey.ADDR_STREET) != null) {
buildings.add(e);
return true;
}
}
if(Amenity.isAmenity(e)){
}
if (indexPOI && Amenity.isAmenity(e)) {
amenities.add(new Amenity((Node) e));
return true;
}
@ -174,11 +200,13 @@ public class DataExtraction {
places.add((Node) e);
return true;
}
if (indexAddress) {
if (e instanceof Way && OSMSettings.wayForCar(e.getTag(OSMTagKey.HIGHWAY))) {
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);
// 2. Reading amenities
if(indexPOI){
readingAmenities(amenities, country);
}
// 3. Reading cities
readingCities(places, country);
if (indexAddress) {
// 4. Reading streets
readingStreets(progress, ways, country);
// 5. reading buildings
readingBuildings(progress, buildings, country);
}
if(normalizeStreets){
// 6. normalizing streets
normalizingStreets(progress, country);
}
country.doDataPreparation();
return country;
@ -367,9 +401,6 @@ public class DataExtraction {
}
}
if (processed) {
if(c.getStreet(name) != s){
System.out.println(name);
}
s.setName(newName);
}
}

View file

@ -114,6 +114,7 @@ public class OsmExtractionUI implements IMapLocationListener {
private JCheckBox normalizingStreets;
private TreeModelListener treeModelListener;
private JCheckBox zipIndexFiles;
private JCheckBox loadingAllData;
@ -299,6 +300,7 @@ public class OsmExtractionUI implements IMapLocationListener {
protected void updateButtonsBar() {
generateDataButton.setEnabled(region != null);
normalizingStreets.setVisible(region == null);
loadingAllData.setVisible(region == null);
buildAddressIndex.setEnabled(region == null || region.getCitiesCount(null) > 0);
buildPoiIndex.setEnabled(region == null || !region.getAmenityManager().isEmpty());
zipIndexFiles.setVisible(region != null);
@ -335,6 +337,11 @@ public class OsmExtractionUI implements IMapLocationListener {
panel.add(normalizingStreets);
normalizingStreets.setSelected(true);
loadingAllData = new JCheckBox();
loadingAllData.setText("Loading all osm data");
panel.add(loadingAllData);
loadingAllData.setSelected(false);
zipIndexFiles = new JCheckBox();
zipIndexFiles.setText("Zip index files");
panel.add(zipIndexFiles);
@ -621,7 +628,9 @@ public class OsmExtractionUI implements IMapLocationListener {
public void run() {
Region res;
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) {
throw new IllegalArgumentException(e);
} catch (SAXException e) {