fix issue 244

git-svn-id: https://osmand.googlecode.com/svn/trunk@764 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-12-06 07:52:28 +00:00
parent 799be831de
commit 22519e0650
4 changed files with 139 additions and 77 deletions

View file

@ -7,20 +7,25 @@ package net.osmand;
*/
public class ToDoConstants {
// TODO max 105
// TODO max 107
// !!! ROUTING
// ! New UI
// TODO remove old indexes
// TODO remove zoomlevel from index
// For 0.5 release
// 97. For voice navigation consider current speed of vehicle. Especially when speed > 50 pronounce more than 200 m
// 104. Add activity to show current loaded indexes and information about them
// 97. For voice navigation consider current speed of vehicle. Especially when speed > 50 pronounce more than 200 m
// 105. Route mode fast/short (Issue)
// 92. Support poi index with standard map index and unify POI categories (unify done +)
// Outside base 0.5 release
// 86. Allow to add/edit custom tags to POI objects (Issue)
// 92. Support poi index with standard map index and unify POI categories (unify done +)
// 96. Introduce settings for MPH, imperial units
// 96. Introduce settings for MPH, imperial units (Issue)
// _19. colors for road trunk and motorway
// _12. Fix : find proper location for streets ! centralize them (when create index)?
///////////////////////////// UNKNOWN STATE ////////////////////
// Unscheduled (complex)
@ -34,6 +39,7 @@ public class ToDoConstants {
/////////////////////////// DONE //////////////////////////////
// DONE ANDROID :
// 106. Download region from android device (select minzoom/maxzoom)
// DONE SWING

View file

@ -1,17 +1,8 @@
package net.osmand.data.index;
import static net.osmand.data.index.IndexConstants.ADDRESS_INDEX_EXT;
import static net.osmand.data.index.IndexConstants.ADDRESS_INDEX_EXT_ZIP;
import static net.osmand.data.index.IndexConstants.ADDRESS_TABLE_VERSION;
import static net.osmand.data.index.IndexConstants.BINARY_MAP_INDEX_EXT;
import static net.osmand.data.index.IndexConstants.BINARY_MAP_INDEX_EXT_ZIP;
import static net.osmand.data.index.IndexConstants.BINARY_MAP_VERSION;
import static net.osmand.data.index.IndexConstants.POI_INDEX_EXT;
import static net.osmand.data.index.IndexConstants.POI_INDEX_EXT_ZIP;
import static net.osmand.data.index.IndexConstants.POI_TABLE_VERSION;
import static net.osmand.data.index.IndexConstants.TRANSPORT_INDEX_EXT;
import static net.osmand.data.index.IndexConstants.TRANSPORT_INDEX_EXT_ZIP;
import static net.osmand.data.index.IndexConstants.TRANSPORT_TABLE_VERSION;
import static net.osmand.data.index.IndexConstants.VOICE_INDEX_EXT_ZIP;
import static net.osmand.data.index.IndexConstants.VOICE_VERSION;
@ -45,35 +36,27 @@ public class DownloaderIndexFromGoogleCode {
*/
public static void main(String[] args) throws URISyntaxException, IOException {
Map<String, String> files = DownloaderIndexFromGoogleCode.getIndexFiles(new LinkedHashMap<String, String>(),
ADDRESS_TABLE_VERSION + ADDRESS_INDEX_EXT,
ADDRESS_TABLE_VERSION + ADDRESS_INDEX_EXT_ZIP,
POI_TABLE_VERSION + POI_INDEX_EXT,
POI_TABLE_VERSION + POI_INDEX_EXT_ZIP,
TRANSPORT_TABLE_VERSION + TRANSPORT_INDEX_EXT,
TRANSPORT_TABLE_VERSION + TRANSPORT_INDEX_EXT_ZIP,
BINARY_MAP_VERSION + BINARY_MAP_INDEX_EXT,
BINARY_MAP_VERSION + BINARY_MAP_INDEX_EXT_ZIP,
VOICE_VERSION + VOICE_INDEX_EXT_ZIP);
for(String s : files.keySet()){
System.out.println(s + " " + files.get(s)); //$NON-NLS-1$
}
// IndexConstants.TRANSPORT_TABLE_VERSION + "" }); //$NON-NLS-1$
// Map<String, String> indexFiles = DownloaderIndexFromGoogleCode.getIndexFiles(
// new String[] { IndexConstants.VOICE_INDEX_EXT_ZIP},
// new String[] { IndexConstants.VOICE_VERSION + "", }, //$NON-NLS-1$
// new TreeMap<String, String>());
// System.out.println(indexFiles);
String odb = ""; //$NON-NLS-1$
// String odb = ""; //$NON-NLS-1$
// put your cookies and personal information for delete
String cookieHSID = ""; //$NON-NLS-1$
String cookieSID = ""; //$NON-NLS-1$
String pagegen = ""; //$NON-NLS-1$
String token = ""; //$NON-NLS-1$
deleteFileFromGoogleDownloads(odb, token, pagegen, cookieHSID,cookieSID);
// String cookieHSID = ""; //$NON-NLS-1$
// String cookieSID = ""; //$NON-NLS-1$
// String pagegen = ""; //$NON-NLS-1$
// String token = ""; //$NON-NLS-1$
//
// for(String odb : indexFiles.keySet()){
// System.out.println("DELETING " + odb);
// deleteFileFromGoogleDownloads(odb, token, pagegen, cookieHSID,cookieSID);
// }
// System.out.println("DELETED " + indexFiles.size());
}
@ -82,9 +65,9 @@ public class DownloaderIndexFromGoogleCode {
BufferedReader reader = null;
int num = 400;
int start = 0;
int size = -1;
while (size != files.size()) {
size = files.size();
boolean downloadNext = true;
while (downloadNext) {
downloadNext = false;
try {
URL url = new URL(
"http://code.google.com/p/osmand/downloads/list?num=" + num + "&start=" + start); //$NON-NLS-1$ //$NON-NLS-2$
@ -93,7 +76,9 @@ public class DownloaderIndexFromGoogleCode {
String s = null;
String prevFile = null;
while ((s = reader.readLine()) != null) {
if (s.indexOf("files") != -1 || s.indexOf("{") != -1) { //$NON-NLS-1$ //$NON-NLS-2$
boolean hrefDownload = s.indexOf("files") != -1;
if (hrefDownload || s.indexOf("{") != -1) { //$NON-NLS-1$ //$NON-NLS-2$
downloadNext |= hrefDownload;
for (String extension : ext) {
prevFile = getIndexFiles(files, s, prevFile, extension);
}

View file

@ -1,11 +1,15 @@
package net.osmand.data.index;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.URL;
import java.text.MessageFormat;
@ -77,6 +81,7 @@ public class IndexBatchCreator {
String cookieSID = "";
String pagegen = "";
String token = "";
private String wget;
public static void main(String[] args) {
@ -113,8 +118,9 @@ public class IndexBatchCreator {
System.out.println("XML configuration file could not be read from " + name);
e.printStackTrace();
log.error("XML configuration file could not be read from " + name, e);
} finally {
safeClose(stream, "Error closing stream for " + name);
}
}
public void runBatch(Document doc){
@ -127,6 +133,7 @@ public class IndexBatchCreator {
generateIndexes = Boolean.parseBoolean(process.getAttribute("generateIndexes"));
uploadIndexes = Boolean.parseBoolean(process.getAttribute("uploadIndexes"));
deleteFilesAfterUploading = Boolean.parseBoolean(process.getAttribute("deleteFilesAfterUploading"));
wget = process.getAttribute("wget");
indexPOI = Boolean.parseBoolean(process.getAttribute("indexPOI"));
indexMap = Boolean.parseBoolean(process.getAttribute("indexMap"));
@ -211,7 +218,7 @@ public class IndexBatchCreator {
Set<String> alreadyUploadedFiles = new LinkedHashSet<String>();
Set<String> alreadyGeneratedFiles = new LinkedHashSet<String>();
if(downloadFiles){
downloadFiles(countriesToDownload, alreadyGeneratedFiles, alreadyUploadedFiles);
downloadFilesAndGenerateIndex(countriesToDownload, alreadyGeneratedFiles, alreadyUploadedFiles);
}
if(generateIndexes){
generatedIndexes(alreadyGeneratedFiles, alreadyUploadedFiles);
@ -223,7 +230,7 @@ public class IndexBatchCreator {
protected void downloadFiles(List<RegionCountries> countriesToDownload, Set<String> alreadyGeneratedFiles, Set<String> alreadyUploadedFiles){
protected void downloadFilesAndGenerateIndex(List<RegionCountries> countriesToDownload, Set<String> alreadyGeneratedFiles, Set<String> alreadyUploadedFiles){
// clean before downloading
// for(File f : osmDirFiles.listFiles()){
// log.info("Delete old file " + f.getName()); //$NON-NLS-1$
@ -237,32 +244,84 @@ public class IndexBatchCreator {
for(String name : regionCountries.regionNames){
name = name.toLowerCase();
String url = MessageFormat.format(site, name);
downloadFile(url, prefix+name, suffix,alreadyGeneratedFiles, alreadyUploadedFiles);
String country = prefix+name;
File toSave = downloadFile(url, country, suffix, alreadyGeneratedFiles, alreadyUploadedFiles);
if (toSave != null && generateIndexes) {
generateIndex(toSave, country, alreadyGeneratedFiles, alreadyUploadedFiles);
}
}
}
System.out.println("DOWNLOADING FILES FINISHED");
}
private final static int DOWNLOAD_DEBUG = 1 << 20;
private final static int MB = 1 << 20;
private final static int BUFFER_SIZE = 1 << 15;
protected void downloadFile(String url, String country, String suffix, Set<String> alreadyGeneratedFiles, Set<String> alreadyUploadedFiles) {
byte[] buffer = new byte[BUFFER_SIZE];
int count = 0;
int downloaded = 0;
int mbDownloaded = 0;
protected File downloadFile(String url, String country, String suffix, Set<String> alreadyGeneratedFiles, Set<String> alreadyUploadedFiles) {
String ext = ".osm";
if(url.endsWith(".osm.bz2")){
ext = ".osm.bz2";
} else if(url.endsWith(".osm.pbf")){
ext = ".osm.pbf";
}
File toSave = new File(osmDirFiles, country + suffix + ext);
File toIndex = null;
File saveTo = new File(osmDirFiles, country + suffix + ext);
if (wget == null || wget.trim().length() == 0) {
toIndex = internalDownload(url, country, saveTo);
} else {
toIndex = wgetDownload(url, country, saveTo);
}
return toIndex;
}
private File wgetDownload(String url, String country, File toSave)
{
BufferedReader wgetOutput = null;
OutputStream wgetInput = null;
Process wgetProc = null;
try {
log.info("Executing " + wget + " " + url + " -O "+ toSave.getCanonicalPath()); //$NON-NLS-1$//$NON-NLS-2$ $NON-NLS-3$
ProcessBuilder exec = new ProcessBuilder(wget, "--read-timeout=5", "--progress=dot:binary", url, "-O", //$NON-NLS-1$//$NON-NLS-2$ $NON-NLS-3$
toSave.getCanonicalPath());
exec.redirectErrorStream(true);
wgetProc = exec.start();
wgetOutput = new BufferedReader(new InputStreamReader(wgetProc.getInputStream()));
String line;
while ((line = wgetOutput.readLine()) != null) {
log.info("wget output:" + line); //$NON-NLS-1$
}
int exitValue = wgetProc.waitFor();
wgetProc = null;
if (exitValue != 0) {
log.error("Wget exited with error code: " + exitValue); //$NON-NLS-1$
} else {
return toSave;
}
} catch (IOException e) {
log.error("Input/output exception " + toSave.getName() + " downloading from " + url + "using wget: " + wget, e); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-3$
} catch (InterruptedException e) {
log.error("Interrupted exception " + toSave.getName() + " downloading from " + url + "using wget: " + wget, e); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-3$
} finally {
safeClose(wgetOutput, ""); //$NON-NLS-1$
safeClose(wgetInput, ""); //$NON-NLS-1$
if (wgetProc != null) {
wgetProc.destroy();
}
}
return null;
}
private final static int DOWNLOAD_DEBUG = 1 << 20;
private final static int MB = 1 << 20;
private final static int BUFFER_SIZE = 1 << 15;
private File internalDownload(String url, String country, File toSave) {
int count = 0;
int downloaded = 0;
int mbDownloaded = 0;
byte[] buffer = new byte[BUFFER_SIZE];
OutputStream ostream = null;
InputStream stream = null;
try {
ostream = new FileOutputStream(toSave);
stream = new URL(url).openStream();
log.info("Downloading country " + country + " from " + url); //$NON-NLS-1$//$NON-NLS-2$
FileOutputStream ostream = new FileOutputStream(toSave);
InputStream stream = new URL(url).openStream();
while ((count = stream.read(buffer)) != -1) {
ostream.write(buffer, 0, count);
downloaded += count;
@ -272,13 +331,24 @@ public class IndexBatchCreator {
log.info(mbDownloaded +" megabytes downloaded of " + toSave.getName());
}
}
ostream.close();
stream.close();
generateIndex(toSave, country, alreadyGeneratedFiles, alreadyUploadedFiles);
return toSave;
} catch (IOException e) {
log.error("Input/output exception " + toSave.getName() + " downloading from " + url, e); //$NON-NLS-1$ //$NON-NLS-2$
} finally {
safeClose(ostream, "Input/output exception " + toSave.getName() + " to close stream "); //$NON-NLS-1$ //$NON-NLS-2$
safeClose(stream, "Input/output exception " + url + " to close stream "); //$NON-NLS-1$ //$NON-NLS-2$
}
return null;
}
private static void safeClose(Closeable ostream, String message) {
if (ostream != null) {
try {
ostream.close();
} catch (Exception e) {
log.error(message, e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
protected void generatedIndexes(Set<String> alreadyGeneratedFiles, Set<String> alreadyUploadedFiles) {

View file

@ -23,6 +23,7 @@
downloadOsmFiles="true" generateIndexes="true" uploadIndexes="true"
deleteFilesAfterUploading="true" indexPOI="true" indexMap="true"
indexTransport="true" indexAddress="true" mapZooms="" renderingTypesFile="">
<!-- add wget="C:/Program Files/GNUWin32/bin/wget.exe" to process, to use wget for download -->
<!-- Countries to download from osm server -->
<!-- EUROPE -->
@ -195,20 +196,20 @@
<!-- SOUTH AMERICA -->
<regions siteToDownload="http://downloads.cloudmade.com/south_america/{0}/{0}.osm.bz2" region_prefix="" skip="true"
region_suffix="_SA">
<region name="argentina" esize=""/>
<region name="bolivia" esize=""/>
<region name="brazil" esize=""/>
<region name="chile" esize=""/>
<region name="colombia" esize=""/>
<region name="ecuador" esize=""/>
<region name="falkland_islands" esize=""/>
<region name="french_guiana" esize=""/>
<region name="guyana" esize=""/>
<region name="paraguay" esize=""/>
<region name="peru" esize=""/>
<region name="suriname" esize=""/>
<region name="uruguay" esize=""/>
<region name="venezuela" esize=""/>
<region name="argentina" esize="22"/>
<region name="bolivia" esize="5"/>
<region name="brazil" esize="68"/>
<region name="chile" esize="30"/>
<region name="colombia" esize="30"/>
<region name="ecuador" esize="15"/>
<region name="falkland_islands" esize="1"/>
<region name="french_guiana" esize="3"/>
<region name="guyana" esize="2"/>
<region name="paraguay" esize="3"/>
<region name="peru" esize="10"/>
<region name="suriname" esize="1"/>
<region name="uruguay" esize="9"/>
<region name="venezuela" esize="11"/>
</regions>
@ -271,14 +272,14 @@
<region name="alaska" esize=""/>
<region name="arizona" esize=""/>
<region name="arkansas" esize=""/>
<region name="california" esize=""/>
<region name="california" esize=""/> <!-- !big! -->
<region name="colorado" esize=""/>
<region name="connecticut" esize=""/>
<region name="delaware" esize=""/>
<region name="district_of_columbia" esize=""/>
<region name="florida" esize=""/>
<region name="georgia" esize=""/>
<region name="guantanamo_bay" esize=""/>
<region name="guantanamo_bay" esize=""/> <!-- ??? -->
<region name="hawaii" esize=""/>
<region name="idaho" esize=""/>
<region name="illinois" esize=""/>
@ -311,10 +312,10 @@
<region name="south_carolina" esize=""/>
<region name="south_dakota" esize=""/>
<region name="tennessee" esize=""/>
<region name="texas" esize=""/>
<region name="texas" esize=""/> <!-- !big! -->
<region name="utah" esize=""/>
<region name="vermont" esize=""/>
<region name="virginia" esize=""/>
<region name="virginia" esize=""/> <!-- !big! -->
<region name="washington" esize=""/>
<region name="west_virginia" esize=""/>
<region name="wisconsin" esize=""/>
@ -323,7 +324,7 @@
<!-- Canada -->
<regions siteToDownload="http://downloads.cloudmade.com/north_america/canada/{0}/{0}.osm.bz2" region_prefix="Canada_" skip="true" region_suffix="_NorthAmerica">
<region name="alberta" esize=""/>
<region name="alberta" esize="36"/>
<region name="british_columbia" esize=""/>
<region name="manitoba" esize=""/>
<region name="new_brunswick" esize=""/>