use of net.osmand.obf.preparation.IndexCreatorSettings 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.IndexCreatorSettings 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.IndexCreatorSettings 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.IndexCreatorSettings 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.IndexCreatorSettings in project OsmAnd-tools by osmandapp.
the class BinaryMerger method combineAddressIndex.
private void combineAddressIndex(String name, BinaryMapIndexWriter writer, AddressRegion[] addressRegions, BinaryMapIndexReader[] indexes) throws IOException {
IndexCreatorSettings settings = new IndexCreatorSettings();
Set<String> attributeTagsTableSet = new TreeSet<String>();
for (int i = 0; i != addressRegions.length; i++) {
AddressRegion region = addressRegions[i];
attributeTagsTableSet.addAll(region.getAttributeTagsTable());
}
writer.startWriteAddressIndex(name, attributeTagsTableSet);
List<String> attributeTagsTable = new ArrayList<String>();
attributeTagsTable.addAll(attributeTagsTableSet);
Map<String, Integer> tagRules = new HashMap<String, Integer>();
Map<String, List<MapObject>> namesIndex = new TreeMap<String, List<MapObject>>(Collator.getInstance());
ListIterator<String> it = attributeTagsTable.listIterator();
while (it.hasNext()) {
tagRules.put(it.next(), it.previousIndex());
}
for (int type : BinaryMapAddressReaderAdapter.CITY_TYPES) {
Map<City, BinaryMapIndexReader> cityMap = new HashMap<City, BinaryMapIndexReader>();
Map<Long, City> cityIds = new HashMap<Long, City>();
for (int i = 0; i < addressRegions.length; i++) {
AddressRegion region = addressRegions[i];
final BinaryMapIndexReader index = indexes[i];
for (City city : index.getCities(region, null, type)) {
normalizePostcode(city, extractCountryName(index));
// probably code to merge cities below is not needed (it called mostly for postcodes)
if (cityIds.containsKey(city.getId())) {
index.preloadStreets(city, null);
City city2 = cityIds.get(city.getId());
cityMap.get(city2).preloadStreets(city2, null);
if (city.getStreets().size() > city2.getStreets().size()) {
cityMap.remove(city2);
cityIds.put(city.getId(), city);
cityMap.put(city, index);
}
} else {
cityMap.put(city, index);
cityIds.put(city.getId(), city);
}
}
}
List<City> cities = new ArrayList<City>(cityMap.keySet());
Map<City, List<City>> mergeCityGroup = new HashMap<City, List<City>>();
Collections.sort(cities, MapObject.BY_NAME_COMPARATOR);
mergeCitiesByNameDistance(cities, mergeCityGroup, cityMap, type == BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE);
List<BinaryFileReference> refs = new ArrayList<BinaryFileReference>();
// 1. write cities
writer.startCityBlockIndex(type);
Map<City, Map<Street, List<Node>>> namesakesStreetNodes = new HashMap<City, Map<Street, List<Node>>>();
for (int i = 0; i < cities.size(); i++) {
City city = cities.get(i);
BinaryMapIndexReader rindex = cityMap.get(city);
preloadStreetsAndBuildings(rindex, city, namesakesStreetNodes);
List<City> namesakes = mergeCityGroup.get(city);
if (namesakes != null) {
for (City namesake : namesakes) {
preloadStreetsAndBuildings(cityMap.get(namesake), namesake, namesakesStreetNodes);
city = mergeCities(city, namesake, namesakesStreetNodes);
}
}
int cityType = city.isPostcode() ? -1 : city.getType().ordinal();
BinaryFileReference ref = writer.writeCityHeader(city, cityType, tagRules);
refs.add(ref);
writer.writeCityIndex(city, city.getStreets(), namesakesStreetNodes.get(city), ref, tagRules);
IndexAddressCreator.putNamedMapObject(namesIndex, city, ref.getStartPointer(), settings);
if (!city.isPostcode()) {
for (Street s : city.getStreets()) {
IndexAddressCreator.putNamedMapObject(namesIndex, s, s.getFileOffset(), settings);
}
}
city.getStreets().clear();
namesakesStreetNodes.clear();
}
writer.endCityBlockIndex();
}
writer.writeAddressNameIndex(namesIndex);
writer.endWriteAddressIndex();
}
Aggregations