add indexing address
git-svn-id: https://osmand.googlecode.com/svn/trunk@63 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
86395f8bc9
commit
1f256f2bfd
9 changed files with 92 additions and 21 deletions
|
@ -38,7 +38,7 @@ public class Region extends MapObject<Entity> {
|
|||
}
|
||||
|
||||
public Region(){
|
||||
this.name = "Region";
|
||||
name = "Region";
|
||||
}
|
||||
|
||||
public OsmBaseStorage getStorage() {
|
||||
|
|
|
@ -35,7 +35,7 @@ import com.osmand.osm.OSMSettings;
|
|||
import com.osmand.osm.Way;
|
||||
import com.osmand.osm.OSMSettings.OSMTagKey;
|
||||
import com.osmand.osm.io.IOsmStorageFilter;
|
||||
import com.osmand.osm.io.OSMStorageWriter;
|
||||
import com.osmand.osm.io.OsmStorageWriter;
|
||||
import com.osmand.osm.io.OsmBaseStorage;
|
||||
|
||||
|
||||
|
@ -115,7 +115,7 @@ public class DataExtraction {
|
|||
// TODO add interested objects
|
||||
List<Long> interestedObjects = new ArrayList<Long>();
|
||||
if (writeTestOsmFile != null) {
|
||||
OSMStorageWriter writer = new OSMStorageWriter();
|
||||
OsmStorageWriter writer = new OsmStorageWriter();
|
||||
OutputStream output = new FileOutputStream(writeTestOsmFile);
|
||||
if (writeTestOsmFile.endsWith(".bz2")) {
|
||||
output.write('B');
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.apache.tools.bzip2.CBZip2OutputStream;
|
|||
|
||||
import com.osmand.data.Amenity;
|
||||
import com.osmand.data.Region;
|
||||
import com.osmand.osm.io.OSMStorageWriter;
|
||||
import com.osmand.osm.io.OsmStorageWriter;
|
||||
|
||||
|
||||
public class DataIndexBuilder {
|
||||
|
@ -64,14 +64,14 @@ public class DataIndexBuilder {
|
|||
}
|
||||
OutputStream output = checkFile("POI/"+region.getName()+".osm");
|
||||
try {
|
||||
OSMStorageWriter writer = new OSMStorageWriter();
|
||||
OsmStorageWriter writer = new OsmStorageWriter();
|
||||
writer.saveStorage(output, region.getStorage(), interestedObjects, false);
|
||||
} finally {
|
||||
output.close();
|
||||
}
|
||||
output = checkFile("POI/"+region.getName()+".osmand");
|
||||
try {
|
||||
OSMStorageWriter writer = new OSMStorageWriter();
|
||||
OsmStorageWriter writer = new OsmStorageWriter();
|
||||
writer.savePOIIndex(output, region);
|
||||
} finally {
|
||||
output.close();
|
||||
|
@ -82,7 +82,7 @@ public class DataIndexBuilder {
|
|||
public DataIndexBuilder buildAddress() throws XMLStreamException, IOException{
|
||||
OutputStream output = checkFile("Address/"+region.getName()+".osmand");
|
||||
try {
|
||||
OSMStorageWriter writer = new OSMStorageWriter();
|
||||
OsmStorageWriter writer = new OsmStorageWriter();
|
||||
writer.saveAddressIndex(output, region);
|
||||
} finally {
|
||||
output.close();
|
||||
|
|
|
@ -61,10 +61,10 @@ public class OsmBaseStorage extends DefaultHandler {
|
|||
public synchronized void parseOSM(InputStream stream, IProgress progress, InputStream streamForProgress) throws IOException, SAXException {
|
||||
this.inputStream = stream;
|
||||
this.progress = progress;
|
||||
this.streamForProgress = streamForProgress;
|
||||
if(streamForProgress == null){
|
||||
streamForProgress = inputStream;
|
||||
}
|
||||
this.streamForProgress = streamForProgress;
|
||||
SAXParser parser = initSaxParser();
|
||||
parseStarted = false;
|
||||
entities.clear();
|
||||
|
@ -144,8 +144,8 @@ public class OsmBaseStorage extends DefaultHandler {
|
|||
if(!parseStarted){
|
||||
initRootElement(uri, localName, name, attributes);
|
||||
}
|
||||
if (currentParsedEntity == null && streamForProgress != null) {
|
||||
if(progress != null && !progress.isIndeterminate()){
|
||||
if (currentParsedEntity == null) {
|
||||
if(progress != null && !progress.isIndeterminate() && streamForProgress != null){
|
||||
try {
|
||||
progress.remaining(streamForProgress.available());
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -93,7 +93,7 @@ public class OSMIndexStorage extends OsmBaseStorage {
|
|||
a.setType(AmenityType.fromString(attributes.getValue(ATTR_TYPE)));
|
||||
a.setSubType(attributes.getValue(ATTR_SUBTYPE));
|
||||
parseMapObject(a, attributes);
|
||||
region.registerAmenity(a);
|
||||
currentParsedStreet.registerBuilding(building);
|
||||
} else {
|
||||
super.startElement(uri, localName, name, attributes);
|
||||
}
|
|
@ -16,7 +16,7 @@ import static com.osmand.osm.io.OsmBaseStorage.ELEM_OSM;
|
|||
import static com.osmand.osm.io.OsmBaseStorage.ELEM_RELATION;
|
||||
import static com.osmand.osm.io.OsmBaseStorage.ELEM_TAG;
|
||||
import static com.osmand.osm.io.OsmBaseStorage.ELEM_WAY;
|
||||
import static com.osmand.osm.io.OSMIndexStorage.*;
|
||||
import static com.osmand.osm.io.OsmIndexStorage.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
|
@ -80,7 +80,7 @@ import com.osmand.osm.LatLon;
|
|||
import com.osmand.osm.MapUtils;
|
||||
import com.osmand.osm.Node;
|
||||
import com.osmand.osm.io.IOsmStorageFilter;
|
||||
import com.osmand.osm.io.OSMStorageWriter;
|
||||
import com.osmand.osm.io.OsmStorageWriter;
|
||||
import com.osmand.osm.io.OsmBoundsFilter;
|
||||
import com.osmand.swing.MapPanel.MapSelectionArea;
|
||||
|
||||
|
@ -601,7 +601,7 @@ public class OsmExtractionUI implements IMapLocationListener {
|
|||
}
|
||||
|
||||
public void saveCountry(final File f){
|
||||
final OSMStorageWriter writer = new OSMStorageWriter();
|
||||
final OsmStorageWriter writer = new OsmStorageWriter();
|
||||
try {
|
||||
final ProgressDialog dlg = new ProgressDialog(frame, "Saving osm file");
|
||||
dlg.setRunnable(new Runnable() {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.osmand;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -9,6 +8,7 @@ import java.util.ArrayList;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.tools.bzip2.CBZip2InputStream;
|
||||
|
@ -20,12 +20,15 @@ import android.os.Environment;
|
|||
|
||||
import com.osmand.data.Amenity;
|
||||
import com.osmand.data.DataTileManager;
|
||||
import com.osmand.data.Region;
|
||||
import com.osmand.data.preparation.MapTileDownloader;
|
||||
import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
||||
import com.osmand.map.ITileSource;
|
||||
import com.osmand.osm.Entity;
|
||||
import com.osmand.osm.LatLon;
|
||||
import com.osmand.osm.Node;
|
||||
import com.osmand.osm.io.OsmBaseStorage;
|
||||
import com.osmand.osm.io.OsmIndexStorage;
|
||||
|
||||
/**
|
||||
* Resource manager is responsible to work with all resources
|
||||
|
@ -38,6 +41,7 @@ import com.osmand.osm.io.OsmBaseStorage;
|
|||
public class ResourceManager {
|
||||
|
||||
private static final String POI_PATH = "osmand/poi/";
|
||||
private static final String ADDRESS_PATH = "osmand/address/";
|
||||
private static final String TILES_PATH = "osmand/tiles/";
|
||||
|
||||
private static final Log log = LogUtil.getLog(ResourceManager.class);
|
||||
|
@ -56,6 +60,8 @@ public class ResourceManager {
|
|||
|
||||
private DataTileManager<Amenity> poiIndex = null;
|
||||
|
||||
private Map<String, Region> addressMap = new TreeMap<String, Region>();
|
||||
|
||||
protected Map<String, Bitmap> cacheOfImages = new LinkedHashMap<String, Bitmap>();
|
||||
|
||||
protected File dirWithTiles ;
|
||||
|
@ -198,14 +204,22 @@ public class ResourceManager {
|
|||
poiIndex = new DataTileManager<Amenity>();
|
||||
if (file.exists() && file.canRead()) {
|
||||
for (File f : file.listFiles()) {
|
||||
if (f.getName().endsWith(".bz2") || f.getName().endsWith(".osm")) {
|
||||
if (f.getName().endsWith(".bz2") || f.getName().endsWith(".osm") || f.getName().endsWith(".osmand")) {
|
||||
long start = System.currentTimeMillis();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Starting index POI " + f.getAbsolutePath());
|
||||
}
|
||||
boolean zipped = f.getName().endsWith(".bz2");
|
||||
InputStream stream = null;
|
||||
try {
|
||||
OsmBaseStorage storage = new OsmBaseStorage();
|
||||
OsmBaseStorage storage;
|
||||
boolean indexStorage = false;
|
||||
if(f.getName().contains(".osmand")){
|
||||
storage = new OsmIndexStorage(new Region());
|
||||
indexStorage = true;
|
||||
} else {
|
||||
storage = new OsmBaseStorage();
|
||||
}
|
||||
stream = new FileInputStream(f);
|
||||
// stream = new BufferedInputStream(stream);
|
||||
InputStream streamForProgress = stream;
|
||||
|
@ -222,13 +236,21 @@ public class ResourceManager {
|
|||
progress.startTask("Indexing poi " + f.getName(), stream.available());
|
||||
}
|
||||
storage.parseOSM(stream, progress, streamForProgress);
|
||||
if(indexStorage){
|
||||
Region region = ((OsmIndexStorage) storage).getRegion();
|
||||
for(Amenity a : region.getAmenityManager().getAllObjects()){
|
||||
LatLon location = a.getLocation();
|
||||
poiIndex.registerObject(location.getLatitude(), location.getLongitude(), a);
|
||||
}
|
||||
} else {
|
||||
for (Entity e : storage.getRegisteredEntities().values()) {
|
||||
if (e instanceof Node && Amenity.isAmenity((Node) e)) {
|
||||
poiIndex.registerObject(((Node) e).getLatitude(), ((Node) e).getLongitude(), new Amenity((Node) e));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Finishing index POI " + f.getAbsolutePath());
|
||||
log.debug("Finishing index POI " + f.getAbsolutePath() + " " +(System.currentTimeMillis() - start)+"ms");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Can't read poi file " + f.getAbsolutePath(), e);
|
||||
|
@ -243,6 +265,54 @@ public class ResourceManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void indexingAddresses(IProgress progress){
|
||||
File file = new File(Environment.getExternalStorageDirectory(), ADDRESS_PATH);
|
||||
if (file.exists() && file.canRead()) {
|
||||
for (File f : file.listFiles()) {
|
||||
if (f.getName().endsWith(".osmand.bz2") || f.getName().endsWith(".osmand")) {
|
||||
long start = System.currentTimeMillis();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Starting index address " + f.getAbsolutePath());
|
||||
}
|
||||
boolean zipped = f.getName().endsWith(".bz2");
|
||||
InputStream stream = null;
|
||||
String name = f.getName().substring(0, f.getName().indexOf('.'));
|
||||
Region region = new Region();
|
||||
region.setName(name);
|
||||
addressMap.put(name, region);
|
||||
try {
|
||||
OsmIndexStorage storage = new OsmIndexStorage(region);
|
||||
stream = new FileInputStream(f);
|
||||
// stream = new BufferedInputStream(stream);
|
||||
InputStream streamForProgress = stream;
|
||||
if (zipped) {
|
||||
if (stream.read() != 'B' || stream.read() != 'Z') {
|
||||
log.error("Can't read index file " + f.getAbsolutePath()
|
||||
+ "The source stream must start with the characters BZ if it is to be read as a BZip2 stream.");
|
||||
continue;
|
||||
} else {
|
||||
stream = new CBZip2InputStream(stream);
|
||||
}
|
||||
}
|
||||
if(progress != null){
|
||||
progress.startTask("Indexing address " + f.getName(), stream.available());
|
||||
}
|
||||
storage.parseOSM(stream, progress, streamForProgress);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Finishing index address " + f.getAbsolutePath() + " " +(System.currentTimeMillis() - start)+"ms");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Can't read index file " + f.getAbsolutePath(), e);
|
||||
} catch (SAXException e) {
|
||||
log.error("Can't read index file " + f.getAbsolutePath(), e);
|
||||
} finally {
|
||||
Algoritms.closeStream(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DataTileManager<Amenity> getPoiIndex() {
|
||||
if(poiIndex == null){
|
||||
indexingPoi(null);
|
||||
|
|
|
@ -77,6 +77,7 @@ public class MainMenuActivity extends Activity {
|
|||
public void run() {
|
||||
try {
|
||||
ResourceManager.getResourceManager().indexingPoi(impl);
|
||||
ResourceManager.getResourceManager().indexingAddresses(impl);
|
||||
} finally {
|
||||
dlg.dismiss();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue