use of net.osmand.obf.preparation.IndexCreator in project OsmAnd-tools by osmandapp.
the class DownloadOsmGPX method generateObfFile.
private void generateObfFile(QueryParams qp) throws IOException, SQLException, InterruptedException, XmlPullParserException {
if (qp.obfFile != null) {
IndexCreatorSettings settings = new IndexCreatorSettings();
settings.indexMap = true;
settings.indexAddress = false;
settings.indexPOI = true;
settings.indexTransport = false;
settings.indexRouting = false;
RTree.clearCache();
File folder = new File(qp.obfFile.getParentFile(), "gen");
String fileName = qp.obfFile.getName();
File targetObf = qp.obfFile;
try {
folder.mkdirs();
IndexCreator ic = new IndexCreator(folder, settings);
MapRenderingTypesEncoder types = new MapRenderingTypesEncoder(null, fileName);
ic.setMapFileName(fileName);
IProgress prog = IProgress.EMPTY_PROGRESS;
prog = new ConsoleProgressImplementation();
ic.generateIndexes(qp.osmFile, prog, null, MapZooms.getDefault(), types, null);
new File(folder, ic.getMapFileName()).renameTo(targetObf);
} finally {
Algorithms.removeAllFiles(folder);
}
}
}
use of net.osmand.obf.preparation.IndexCreator in project OsmAnd-tools by osmandapp.
the class OsmExtractionUI method loadCountry.
public void loadCountry(final File f, final IOsmStorageFilter filter) {
try {
// $NON-NLS-1$
final ProgressDialog dlg = new ProgressDialog(frame, Messages.getString("OsmExtractionUI.LOADING_OSM_FILE"));
dlg.setRunnable(new Runnable() {
@Override
public void run() {
File dir = DataExtractionSettings.getSettings().getDefaultWorkingDir();
IndexCreatorSettings settings = new IndexCreatorSettings() {
public String getString(String key) {
return Messages.getString(key);
}
};
settings.indexMap = buildMapIndex.isSelected();
settings.indexAddress = buildAddressIndex.isSelected();
settings.indexPOI = buildPoiIndex.isSelected();
settings.indexTransport = buildTransportIndex.isSelected();
settings.indexRouting = buildRoutingIndex.isSelected();
settings.suppressWarningsForDuplicateIds = DataExtractionSettings.getSettings().isSupressWarningsForDuplicatedId();
settings.houseNameAddAdditionalInfo = DataExtractionSettings.getSettings().isAdditionalInfo();
settings.houseNumberPreferredOverName = DataExtractionSettings.getSettings().isHousenumberPrefered();
try {
settings.zoomWaySmoothness = Integer.parseInt(DataExtractionSettings.getSettings().getLineSmoothness());
} catch (NumberFormatException e) {
}
IndexCreator creator = new IndexCreator(dir, settings);
try {
String fn = DataExtractionSettings.getSettings().getMapRenderingTypesFile();
if (!Algorithms.isEmpty(DataExtractionSettings.getSettings().getPoiTypesFile())) {
MapPoiTypes.setDefault(new MapPoiTypes(DataExtractionSettings.getSettings().getPoiTypesFile()));
}
MapRenderingTypesEncoder types;
types = new MapRenderingTypesEncoder(fn, f.getName());
RTree.clearCache();
creator.generateIndexes(f, dlg, filter, DataExtractionSettings.getSettings().getMapZooms(), types, log);
} catch (IOException e) {
throw new IllegalArgumentException(e);
} catch (XmlPullParserException e) {
throw new IllegalStateException(e);
} catch (SQLException e) {
throw new IllegalStateException(e);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
regionName = creator.getRegionName();
StringBuilder msg = new StringBuilder();
// $NON-NLS-1$ //$NON-NLS-2$
msg.append(Messages.getString("OsmExtractionUI.INDEXES_FOR")).append(regionName).append(" : ");
boolean comma = false;
if (buildMapIndex.isSelected()) {
// $NON-NLS-1$
if (comma)
msg.append(", ");
comma = true;
// $NON-NLS-1$
msg.append(Messages.getString("OsmExtractionUI.MAP"));
}
if (buildPoiIndex.isSelected()) {
// $NON-NLS-1$
if (comma)
msg.append(", ");
comma = true;
// $NON-NLS-1$
msg.append(Messages.getString("OsmExtractionUI.POI"));
}
if (buildAddressIndex.isSelected()) {
// $NON-NLS-1$
if (comma)
msg.append(", ");
comma = true;
// $NON-NLS-1$
msg.append(Messages.getString("OsmExtractionUI.ADDRESS"));
}
if (buildTransportIndex.isSelected()) {
// $NON-NLS-1$
if (comma)
msg.append(", ");
comma = true;
// $NON-NLS-1$
msg.append(Messages.getString("OsmExtractionUI.TRANSPORT"));
}
// $NON-NLS-1$
msg.append(MessageFormat.format(Messages.getString("OsmExtractionUI.WERE_SUCCESFULLY_CREATED"), dir.getAbsolutePath()));
JOptionPane pane = new JOptionPane(msg);
// $NON-NLS-1$
JDialog dialog = pane.createDialog(frame, Messages.getString("OsmExtractionUI.GENERATION_DATA"));
dialog.setVisible(true);
}
});
dlg.run();
// $NON-NLS-1$
frame.setTitle(Messages.getString("OsmExtractionUI.OSMAND_MAP_CREATOR_FILE") + f.getName());
} catch (InterruptedException e1) {
// $NON-NLS-1$
log.error("Interrupted", e1);
} catch (InvocationTargetException e1) {
// $NON-NLS-1$
ExceptionHandler.handle("Exception during operation", e1.getCause());
}
}
use of net.osmand.obf.preparation.IndexCreator in project OsmAnd-tools by osmandapp.
the class OsmGpxWriteContext method writeObf.
public File writeObf(List<File> files, File tmpFolder, String fileName, File targetObf) throws IOException, SQLException, InterruptedException, XmlPullParserException {
startDocument();
for (File gf : files) {
GPXFile f = GPXUtilities.loadGPXFile(gf);
GPXTrackAnalysis analysis = f.getAnalysis(gf.lastModified());
writeTrack(null, null, f, analysis, "GPX");
}
endDocument();
IndexCreatorSettings settings = new IndexCreatorSettings();
settings.indexMap = true;
settings.indexAddress = false;
settings.indexPOI = true;
settings.indexTransport = false;
settings.indexRouting = false;
RTree.clearCache();
try {
tmpFolder.mkdirs();
IndexCreator ic = new IndexCreator(tmpFolder, settings);
MapRenderingTypesEncoder types = new MapRenderingTypesEncoder(null, fileName);
ic.setMapFileName(fileName);
// IProgress.EMPTY_PROGRESS
IProgress prog = IProgress.EMPTY_PROGRESS;
// prog = new ConsoleProgressImplementation();
ic.generateIndexes(qp.osmFile, prog, null, MapZooms.getDefault(), types, null);
new File(tmpFolder, ic.getMapFileName()).renameTo(targetObf);
} finally {
Algorithms.removeAllFiles(tmpFolder);
}
return targetObf;
}
use of net.osmand.obf.preparation.IndexCreator in project OsmAnd-tools by osmandapp.
the class GenerateDailyObf method generateCountry.
public static void generateCountry(String name, File targetObfZip, File[] array, long targetTimestamp, File nodesFile) throws IOException, SQLException, InterruptedException, XmlPullParserException {
boolean exception = true;
try {
RTree.clearCache();
IndexCreatorSettings settings = new IndexCreatorSettings();
settings.indexMap = true;
settings.indexAddress = false;
settings.indexPOI = true;
settings.indexTransport = false;
settings.indexRouting = false;
settings.generateLowLevel = false;
IndexCreator ic = new IndexCreator(targetObfZip.getParentFile(), settings);
ic.setLastModifiedDate(targetTimestamp);
ic.setDialects(DBDialect.SQLITE, DBDialect.SQLITE_IN_MEMORY);
ic.setLastModifiedDate(targetTimestamp);
ic.setRegionName(Algorithms.capitalizeFirstLetterAndLowercase(name));
ic.setNodesDBFile(nodesFile);
ic.setDeleteOsmDB(false);
ic.generateIndexes(array, new ConsoleProgressImplementation(), null, MapZooms.parseZooms("13-14;15-"), new MapRenderingTypesEncoder(name), log, false, true);
File targetFile = new File(targetObfZip.getParentFile(), ic.getMapFileName());
targetFile.setLastModified(targetTimestamp);
FileInputStream fis = new FileInputStream(targetFile);
GZIPOutputStream gzout = new GZIPOutputStream(new FileOutputStream(targetObfZip));
Algorithms.streamCopy(fis, gzout);
fis.close();
gzout.close();
targetObfZip.setLastModified(targetTimestamp);
targetFile.delete();
exception = false;
} finally {
if (exception) {
nodesFile.delete();
nodesFile.deleteOnExit();
}
}
}
use of net.osmand.obf.preparation.IndexCreator in project OsmAnd-tools by osmandapp.
the class TravelGuideCreatorMain method generateTravelGuide.
private void generateTravelGuide(String dir) throws SQLException, IOException, XmlPullParserException, InterruptedException {
File directory = new File(dir);
if (!directory.isDirectory()) {
throw new RuntimeException("Supplied path is not a directory");
}
File[] files = directory.listFiles();
File sqliteFile = new File(directory, TRAVEL_GUIDE_NAME + BINARY_WIKIVOYAGE_MAP_INDEX_EXT);
Connection conn = DBDialect.SQLITE.getDatabaseConnection(sqliteFile.getCanonicalPath(), LOG);
if (conn == null) {
LOG.error("Couldn't establish the database connection");
System.exit(1);
}
Map<String, List<File>> mapping = getFileMapping(files);
WikivoyageDataGenerator dataGenerator = new WikivoyageDataGenerator();
generateTravelSqlite(mapping, conn);
dataGenerator.generateSearchTable(conn);
createPopularArticlesTable(conn);
conn.close();
File osmFile = new File(directory, TRAVEL_GUIDE_NAME + OSM_GZ_EXT);
WikivoyageGenOSM.genWikivoyageOsm(sqliteFile, osmFile, -1);
IndexCreatorSettings settings = new IndexCreatorSettings();
settings.indexPOI = true;
IndexCreator ic = new IndexCreator(directory, settings);
ic.setMapFileName(directory.getName() + BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT);
MapRenderingTypesEncoder types = new MapRenderingTypesEncoder(settings.renderingTypesFile, osmFile.getName());
ic.generateIndexes(osmFile, new ConsoleProgressImplementation(), null, MapZooms.getDefault(), types, LOG);
osmFile.delete();
sqliteFile.delete();
new File("regions.ocbf").delete();
}
Aggregations