use of net.osmand.data.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();
IndexCreator creator = new IndexCreator(dir);
try {
creator.setIndexAddress(buildAddressIndex.isSelected());
creator.setIndexPOI(buildPoiIndex.isSelected());
creator.setIndexTransport(buildTransportIndex.isSelected());
creator.setIndexMap(buildMapIndex.isSelected());
creator.setIndexRouting(buildRoutingIndex.isSelected());
creator.setCityAdminLevel(DataExtractionSettings.getSettings().getCityAdminLevel());
String fn = DataExtractionSettings.getSettings().getMapRenderingTypesFile();
MapRenderingTypesEncoder types;
types = new MapRenderingTypesEncoder(fn, f.getName());
RTree.clearCache();
int smoothness = 0;
try {
smoothness = Integer.parseInt(DataExtractionSettings.getSettings().getLineSmoothness());
} catch (NumberFormatException e) {
}
creator.setZoomWaySmoothness(smoothness);
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.data.preparation.IndexCreator in project OsmAnd-tools by osmandapp.
the class WikipediaByCountryDivider method generateObf.
private static void generateObf(File osmBz2, File obf) throws IOException, SQLException, InterruptedException, XmlPullParserException {
IndexPoiCreator.ZIP_LONG_STRINGS = true;
// be independent of previous results
RTree.clearCache();
// $NON-NLS-1$
IndexCreator creator = new IndexCreator(obf.getParentFile());
new File(obf.getParentFile(), IndexCreator.TEMP_NODES_DB).delete();
creator.setIndexMap(false);
creator.setIndexAddress(false);
creator.setIndexPOI(true);
creator.setIndexTransport(false);
creator.setIndexRouting(false);
creator.setMapFileName(obf.getName());
creator.generateIndexes(osmBz2, new ConsoleProgressImplementation(1), null, MapZooms.getDefault(), new MapRenderingTypesEncoder(obf.getName()), log);
}
use of net.osmand.data.preparation.IndexCreator in project OsmAnd-tools by osmandapp.
the class CountryOcbfGeneration method createFile.
private void createFile(CountryRegion global, Map<String, Set<TranslateEntity>> translates, Map<String, File> polygonFiles, String targetObf, String targetOsmXml) throws IOException, SQLException, InterruptedException, XmlPullParserException {
File osm = new File(targetOsmXml);
XmlSerializer serializer = new org.kxml2.io.KXmlSerializer();
FileOutputStream fous = new FileOutputStream(osm);
serializer.setOutput(fous, "UTF-8");
serializer.startDocument("UTF-8", true);
serializer.startTag(null, "osm");
serializer.attribute(null, "version", "0.6");
serializer.attribute(null, "generator", "OsmAnd");
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
for (CountryRegion r : global.children) {
r.parent = null;
processRegion(r, translates, polygonFiles, targetObf, targetOsmXml, "", serializer);
}
serializer.endDocument();
serializer.flush();
fous.close();
// $NON-NLS-1$
IndexCreator creator = new IndexCreator(new File(targetObf).getParentFile());
creator.setMapFileName(new File(targetObf).getName());
creator.setIndexMap(true);
creator.setIndexAddress(false);
creator.setIndexPOI(false);
creator.setIndexTransport(false);
creator.setIndexRouting(false);
MapZooms zooms = MapZooms.parseZooms("5-6");
creator.generateIndexes(osm, new ConsoleProgressImplementation(1), null, zooms, new MapRenderingTypesEncoder("regions"), log);
}
use of net.osmand.data.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();
IndexCreator ic = new IndexCreator(targetObfZip.getParentFile());
ic.setIndexAddress(false);
ic.setIndexPOI(true);
ic.setIndexRouting(true);
ic.setIndexMap(true);
ic.setLastModifiedDate(targetTimestamp);
ic.setGenerateLowLevelIndexes(false);
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.data.preparation.IndexCreator in project wikivoyage-listings by baturin.
the class OBF method createObf.
public static void createObf(String outputFilename, String workingDir, String mapFile) throws IOException, SAXException, SQLException, InterruptedException {
IndexCreator creator = new IndexCreator(new File(workingDir));
creator.setMapFileName(mapFile);
creator.setIndexPOI(true);
creator.generateIndexes(new File(outputFilename), IProgress.EMPTY_PROGRESS, null, null, null, null);
}
Aggregations