prepare renderer staff

git-svn-id: https://osmand.googlecode.com/svn/trunk@410 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-07-28 21:14:43 +00:00
parent 3920d390f4
commit 351d28408a
8 changed files with 124 additions and 22 deletions

View file

@ -8,20 +8,17 @@ package com.osmand;
*/ */
public class ToDoConstants { public class ToDoConstants {
// TODO // TODO
// 77. Implement upload gps track onto osm server (? not implemented yet on OSM?) // 78. Add ruler to the main tile view (100m, 200m,...)
// 78. Add ruler to the main tile view
// 80. Export/import favorite points // 80. Export/import favorite points
// 81. Add some objects to POI to help navigation ( // 81. Add some objects to POI to help navigation (
// highway (?), traffic_calming (?), barrier(?), military(?-), landuse (?), office(?), man_made(?), power(?). // highway (?), traffic_calming (?), barrier(?), military(?-), landuse (?), office(?), man_made(?), power(?).
// 82. Add overzoom +2 for Mapnik // 82. Add overzoom +2 for Mapnik
// 83. Add monitoring service to internet (?) // 83. Add monitoring service to send locations to internet (?)
// Improvements // Improvements
// 5. Download with wget // ! Download with wget
// 6. progress while map is loading // ! progress while map is loading
// Not clear if it is really needed // Not clear if it is really needed
// 69. Add phone information to POI // 69. Add phone information to POI
@ -47,6 +44,8 @@ public class ToDoConstants {
// DONE ANDROID : // DONE ANDROID :
// 64. Traffic information - yandex traffic // 64. Traffic information - yandex traffic
// 79. Download any WMS layer and add to swing version (add tile manager ${x}, ${y}, ${z} to swing and to android) // 79. Download any WMS layer and add to swing version (add tile manager ${x}, ${y}, ${z} to swing and to android)
// 77. Implement upload gps track onto osm server (? not implemented yet on OSM?) -
// not really needed, because gps tracks should be prepared before loading to OSM (OSM is not ready for it)
// DONE SWING // DONE SWING

View file

@ -7,6 +7,7 @@ public class IndexConstants {
public final static int TRANSPORT_TABLE_VERSION = 0; public final static int TRANSPORT_TABLE_VERSION = 0;
public final static int POI_TABLE_VERSION = 0; public final static int POI_TABLE_VERSION = 0;
public final static int ADDRESS_TABLE_VERSION = 1; public final static int ADDRESS_TABLE_VERSION = 1;
public final static int MAP_TABLE_VERSION = 0;
public static final String POI_INDEX_DIR = "POI/"; //$NON-NLS-1$ public static final String POI_INDEX_DIR = "POI/"; //$NON-NLS-1$
public static final String ADDRESS_INDEX_DIR = "Address/"; //$NON-NLS-1$ public static final String ADDRESS_INDEX_DIR = "Address/"; //$NON-NLS-1$
@ -15,10 +16,13 @@ public class IndexConstants {
public static final String POI_INDEX_EXT = ".poi.odb"; //$NON-NLS-1$ public static final String POI_INDEX_EXT = ".poi.odb"; //$NON-NLS-1$
public static final String ADDRESS_INDEX_EXT = ".addr.odb"; //$NON-NLS-1$ public static final String ADDRESS_INDEX_EXT = ".addr.odb"; //$NON-NLS-1$
public static final String TRANSPORT_INDEX_EXT = ".trans.odb"; //$NON-NLS-1$ public static final String TRANSPORT_INDEX_EXT = ".trans.odb"; //$NON-NLS-1$
public static final String MAP_INDEX_EXT = ".map.odb"; //$NON-NLS-1$
public static final String POI_INDEX_EXT_ZIP = ".poi.zip"; //$NON-NLS-1$ public static final String POI_INDEX_EXT_ZIP = ".poi.zip"; //$NON-NLS-1$
public static final String ADDRESS_INDEX_EXT_ZIP = ".addr.zip"; //$NON-NLS-1$ public static final String ADDRESS_INDEX_EXT_ZIP = ".addr.zip"; //$NON-NLS-1$
public static final String TRANSPORT_INDEX_EXT_ZIP = ".trans.zip"; //$NON-NLS-1$ public static final String TRANSPORT_INDEX_EXT_ZIP = ".trans.zip"; //$NON-NLS-1$
public static final String MAP_INDEX_EXT_ZIP = ".map.zip"; //$NON-NLS-1$
public interface IndexColumn { public interface IndexColumn {
public boolean isIndex(); public boolean isIndex();

View file

@ -42,6 +42,7 @@ import com.osmand.data.Street;
import com.osmand.data.TransportRoute; import com.osmand.data.TransportRoute;
import com.osmand.data.TransportStop; import com.osmand.data.TransportStop;
import com.osmand.data.City.CityType; import com.osmand.data.City.CityType;
import com.osmand.data.index.IndexConstants;
import com.osmand.impl.ConsoleProgressImplementation; import com.osmand.impl.ConsoleProgressImplementation;
import com.osmand.osm.Entity; import com.osmand.osm.Entity;
import com.osmand.osm.LatLon; import com.osmand.osm.LatLon;
@ -93,7 +94,8 @@ public class DataExtraction {
private static final Log log = LogFactory.getLog(DataExtraction.class); private static final Log log = LogFactory.getLog(DataExtraction.class);
public static final int BATCH_SIZE = 5000; public static final int BATCH_SIZE = 5000;
public static final String NODES_DB = "nodes.db"; public static final String TEMP_NODES_DB = "nodes"+IndexConstants.MAP_INDEX_EXT;
private final boolean loadAllObjects; private final boolean loadAllObjects;
private final boolean normalizeStreets; private final boolean normalizeStreets;
@ -132,15 +134,27 @@ public class DataExtraction {
private Connection conn; private Connection conn;
private boolean preloadRelationAndWaysIntoDB = false; private boolean preloadRelationAndWaysIntoDB = false;
private boolean createWholeOsmDB = false;
int currentCountNode = 0; int currentCountNode = 0;
private PreparedStatement prepNode; private PreparedStatement prepNode;
int currentRelationsCount = 0; int currentRelationsCount = 0;
private PreparedStatement prepRelations; private PreparedStatement prepRelations;
int currentWaysCount = 0; int currentWaysCount = 0;
private PreparedStatement prepWays; private PreparedStatement prepWays;
int currentTagsCount = 0;
private PreparedStatement prepTags;
private final String regionName;
private File dbFile;
public DataExtractionOsmFilter(String regionName) {
this.regionName = regionName;
}
public DataExtractionOsmFilter() { public DataExtractionOsmFilter() {
createWholeOsmDB = false;
this.regionName = null;
} }
public ArrayList<Node> getPlaces() { public ArrayList<Node> getPlaces() {
@ -170,31 +184,39 @@ public class DataExtraction {
log.error("Illegal configuration", e); log.error("Illegal configuration", e);
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
if(createWholeOsmDB){
File file = new File(workingDir, NODES_DB); dbFile = new File(workingDir, regionName+IndexConstants.MAP_INDEX_EXT);
} else {
dbFile = new File(workingDir, TEMP_NODES_DB);
}
// to save space // to save space
if(file.exists()){ if(dbFile.exists()){
file.delete(); dbFile.delete();
} }
// creating nodes db to fast access for all nodes // creating nodes db to fast access for all nodes
conn = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath()); conn = DriverManager.getConnection("jdbc:sqlite:" + dbFile.getAbsolutePath());
// prepare tables // prepare tables
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.executeUpdate("drop table if exists node;"); stat.executeUpdate("drop table if exists node;");
stat.executeUpdate("create table node (id long, latitude double, longitude double);"); stat.executeUpdate("create table node (id long, latitude double, longitude double);");
stat.executeUpdate("create index IdIndex ON node (id);"); stat.executeUpdate("create index IdIndex ON node (id, latitude, longitude);");
stat.executeUpdate("drop table if exists ways;"); stat.executeUpdate("drop table if exists ways;");
stat.executeUpdate("create table ways (id long, node long);"); stat.executeUpdate("create table ways (id long, node long);");
stat.executeUpdate("create index IdWIndex ON ways (id);"); stat.executeUpdate("create index IdWIndex ON ways (id, node);");
stat.executeUpdate("drop table if exists relations;"); stat.executeUpdate("drop table if exists relations;");
stat.executeUpdate("create table relations (id long, member long, type byte, role text);"); stat.executeUpdate("create table relations (id long, member long, type byte, role text);");
stat.executeUpdate("create index IdRIndex ON relations (id);"); stat.executeUpdate("create index IdRIndex ON relations (id, member, type);");
stat.executeUpdate("drop table if exists tags;");
stat.executeUpdate("create table tags (id long, type byte, key, value);");
stat.executeUpdate("create index IdTIndex ON tags (id, type);");
stat.execute("PRAGMA user_version = " + IndexConstants.MAP_TABLE_VERSION); //$NON-NLS-1$
stat.close(); stat.close();
prepNode = conn.prepareStatement("insert into node values (?, ?, ?);"); prepNode = conn.prepareStatement("insert into node values (?, ?, ?);");
prepWays = conn.prepareStatement("insert into ways values (?, ?);"); prepWays = conn.prepareStatement("insert into ways values (?, ?);");
prepRelations = conn.prepareStatement("insert into relations values (?, ?, ?, ?);"); prepRelations = conn.prepareStatement("insert into relations values (?, ?, ?, ?);");
prepTags = conn.prepareStatement("insert into tags values (?, ?, ?, ?);");
preloadRelationAndWaysIntoDB = indexTransport; preloadRelationAndWaysIntoDB = indexTransport;
conn.setAutoCommit(false); conn.setAutoCommit(false);
} }
@ -212,6 +234,10 @@ public class DataExtraction {
prepRelations.executeBatch(); prepRelations.executeBatch();
} }
prepRelations.close(); prepRelations.close();
if (currentTagsCount > 0) {
prepTags.executeBatch();
}
prepTags.close();
conn.setAutoCommit(true); conn.setAutoCommit(true);
final PreparedStatement pselectNode = conn.prepareStatement("select * from node where id = ?"); final PreparedStatement pselectNode = conn.prepareStatement("select * from node where id = ?");
@ -281,7 +307,9 @@ public class DataExtraction {
if (conn != null) { if (conn != null) {
try { try {
conn.close(); conn.close();
new File(workingDir, NODES_DB).delete(); if(!createWholeOsmDB){
dbFile.delete();
}
} catch (SQLException e) { } catch (SQLException e) {
} }
} }
@ -351,7 +379,7 @@ public class DataExtraction {
prepNode.executeBatch(); prepNode.executeBatch();
currentCountNode = 0; currentCountNode = 0;
} }
} else if(preloadRelationAndWaysIntoDB) { } else if(preloadRelationAndWaysIntoDB || createWholeOsmDB) {
if (e instanceof Way) { if (e instanceof Way) {
for(Long i : ((Way)e).getNodeIds()){ for(Long i : ((Way)e).getNodeIds()){
currentWaysCount ++; currentWaysCount ++;
@ -378,6 +406,20 @@ public class DataExtraction {
} }
} }
} }
if(createWholeOsmDB){
for(Entry<String,String> i : e.getTags().entrySet()){
currentTagsCount ++;
prepTags.setLong(1, e.getId());
prepTags.setLong(2, EntityType.valueOf(e).ordinal());
prepTags.setString(3, i.getKey());
prepTags.setString(4, i.getValue());
prepTags.addBatch();
}
if (currentTagsCount >= BATCH_SIZE) {
prepTags.executeBatch();
currentTagsCount = 0;
}
}
} catch (SQLException ex) { } catch (SQLException ex) {
log.error("Could not save in db", ex); log.error("Could not save in db", ex);
} }
@ -390,6 +432,9 @@ public class DataExtraction {
public Region readCountry(String path, IProgress progress, IOsmStorageFilter addFilter) throws IOException, SAXException, SQLException{ public Region readCountry(String path, IProgress progress, IOsmStorageFilter addFilter) throws IOException, SAXException, SQLException{
File f = new File(path); File f = new File(path);
InputStream stream = new FileInputStream(f); InputStream stream = new FileInputStream(f);
int i = f.getName().indexOf('.');
String regionName = Algoritms.capitalizeFirstLetterAndLowercase(f.getName().substring(0, i));
InputStream streamFile = stream; InputStream streamFile = stream;
long st = System.currentTimeMillis(); long st = System.currentTimeMillis();
if (path.endsWith(".bz2")) { if (path.endsWith(".bz2")) {
@ -409,7 +454,7 @@ public class DataExtraction {
storage.getFilters().add(addFilter); storage.getFilters().add(addFilter);
} }
DataExtractionOsmFilter filter = new DataExtractionOsmFilter(); DataExtractionOsmFilter filter = new DataExtractionOsmFilter(regionName);
// data to load & index // data to load & index
final ArrayList<Node> places = filter.getPlaces(); final ArrayList<Node> places = filter.getPlaces();
final ArrayList<Entity> buildings = filter.getBuildings(); final ArrayList<Entity> buildings = filter.getBuildings();
@ -444,8 +489,8 @@ public class DataExtraction {
// 1. Initialize region // 1. Initialize region
Region country = new Region(); Region country = new Region();
int i = f.getName().indexOf('.');
country.setName(Algoritms.capitalizeFirstLetterAndLowercase(f.getName().substring(0, i))); country.setName(regionName);
country.setStorage(storage); country.setStorage(storage);
// 2. Reading amenities // 2. Reading amenities

View file

@ -27,6 +27,8 @@ amenity_type_transportation = Transportation
indexing_address = Indexing address indexing_address = Indexing address
indexing_map = Indexing map
indexing_poi = Indexing POI indexing_poi = Indexing POI
indexing_transport = Indexing transport indexing_transport = Indexing transport

View file

@ -19,7 +19,7 @@ amenity_type_shop = Einkaufen
amenity_type_sport = Sport amenity_type_sport = Sport
amenity_type_sustenance = Ernährung amenity_type_sustenance = Ern\u00E4hrung
amenity_type_tourism = Tourismus amenity_type_tourism = Tourismus
@ -27,6 +27,8 @@ amenity_type_transportation = Nahverkehr
indexing_address = Indexing address indexing_address = Indexing address
indexing_map = Indexing map
indexing_poi = Indexing POI indexing_poi = Indexing POI
indexing_transport = Indexing transport indexing_transport = Indexing transport

View file

@ -27,6 +27,8 @@ amenity_type_transportation = \u0422\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u
indexing_address = \u0418\u043D\u0434\u0435\u043A\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044F \u0430\u0434\u0440\u0435\u0441 indexing_address = \u0418\u043D\u0434\u0435\u043A\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044F \u0430\u0434\u0440\u0435\u0441
indexing_map = \u0418\u043D\u0434\u0435\u043A\u0441\u0438\u0440\u0443\u044E\u0442\u0441\u044F \u043A\u0430\u0440\u0442\u044B
indexing_poi = \u0418\u043D\u0434\u0435\u043A\u0441\u0438\u0440\u0443\u044E\u0442\u0441\u044F POI indexing_poi = \u0418\u043D\u0434\u0435\u043A\u0441\u0438\u0440\u0443\u044E\u0442\u0441\u044F POI
indexing_transport = \u0418\u043D\u0434\u0435\u043A\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044F \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442 indexing_transport = \u0418\u043D\u0434\u0435\u043A\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044F \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442

View file

@ -27,6 +27,7 @@ import com.osmand.data.preparation.MapTileDownloader.IMapDownloaderCallback;
import com.osmand.map.ITileSource; import com.osmand.map.ITileSource;
import com.osmand.osm.LatLon; import com.osmand.osm.LatLon;
import com.osmand.osm.MapUtils; import com.osmand.osm.MapUtils;
import com.osmand.render.RenderMapsRepositories;
import com.osmand.views.POIMapLayer; import com.osmand.views.POIMapLayer;
/** /**
@ -41,6 +42,7 @@ public class ResourceManager {
public static final String APP_DIR = "osmand/"; //$NON-NLS-1$ public static final String APP_DIR = "osmand/"; //$NON-NLS-1$
public static final String POI_PATH = APP_DIR + IndexConstants.POI_INDEX_DIR; public static final String POI_PATH = APP_DIR + IndexConstants.POI_INDEX_DIR;
public static final String MAPS_PATH = APP_DIR;
public static final String ADDRESS_PATH = APP_DIR + IndexConstants.ADDRESS_INDEX_DIR; public static final String ADDRESS_PATH = APP_DIR + IndexConstants.ADDRESS_INDEX_DIR;
public static final String TRANSPORT_PATH = APP_DIR + IndexConstants.TRANSPORT_INDEX_DIR; public static final String TRANSPORT_PATH = APP_DIR + IndexConstants.TRANSPORT_INDEX_DIR;
public static final String TILES_PATH = APP_DIR+"tiles/"; //$NON-NLS-1$ public static final String TILES_PATH = APP_DIR+"tiles/"; //$NON-NLS-1$
@ -77,6 +79,8 @@ public class ResourceManager {
protected Map<String, TransportIndexRepository> transportRepositories = new LinkedHashMap<String, TransportIndexRepository>(); protected Map<String, TransportIndexRepository> transportRepositories = new LinkedHashMap<String, TransportIndexRepository>();
protected RenderMapsRepositories renderer = new RenderMapsRepositories();
public AsyncLoadingThread asyncLoadingTiles = new AsyncLoadingThread(); public AsyncLoadingThread asyncLoadingTiles = new AsyncLoadingThread();
@ -305,6 +309,25 @@ public class ResourceManager {
warnings.addAll(indexingPoi(progress)); warnings.addAll(indexingPoi(progress));
warnings.addAll(indexingAddresses(progress)); warnings.addAll(indexingAddresses(progress));
warnings.addAll(indexingTransport(progress)); warnings.addAll(indexingTransport(progress));
warnings.addAll(indexingMaps(progress));
return warnings;
}
public List<String> indexingMaps(final IProgress progress) {
File file = new File(Environment.getExternalStorageDirectory(), MAPS_PATH);
List<String> warnings = new ArrayList<String>();
renderer.clearAllResources();
if (file.exists() && file.canRead()) {
for (File f : file.listFiles()) {
if (f.getName().endsWith(IndexConstants.MAP_INDEX_EXT)) {
progress.startTask(Messages.getMessage("indexing_map") + f.getName(), -1); //$NON-NLS-1$
boolean initialized = renderer.initializeNewResource(progress, f);
if (!initialized) {
warnings.add(MessageFormat.format(Messages.getMessage("version_index_is_not_supported"), f.getName())); //$NON-NLS-1$
}
}
}
}
return warnings; return warnings;
} }
@ -500,6 +523,7 @@ public class ResourceManager {
public synchronized void close(){ public synchronized void close(){
imagesOnFS.clear(); imagesOnFS.clear();
renderer.clearAllResources();
closeAmenities(); closeAmenities();
closeAddresses(); closeAddresses();
closeTransport(); closeTransport();
@ -515,6 +539,7 @@ public class ResourceManager {
for(RegionAddressRepository r : addressMap.values()){ for(RegionAddressRepository r : addressMap.values()){
r.clearCities(); r.clearCities();
} }
renderer.clearCache();
System.gc(); System.gc();
} }

View file

@ -0,0 +1,23 @@
package com.osmand.render;
import java.io.File;
import com.osmand.IProgress;
public class RenderMapsRepositories {
public boolean initializeNewResource(final IProgress progress, File file) {
return true;
}
public void clearAllResources(){
// TODO
}
public void clearCache() {
}
}