use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.
the class Mdr7 method preWriteImpl.
/**
* Since we change the number of records by removing some after sorting,
* we sort and de-duplicate here.
* This is a performance critical part of the index creation process
* as it requires a lot of heap to store the sort keys.
*/
protected void preWriteImpl() {
LargeListSorter<Mdr7Record> partialSorter = new LargeListSorter<Mdr7Record>(sort) {
@Override
protected SortKey<Mdr7Record> makeKey(Mdr7Record r, Sort sort, Map<String, byte[]> cache) {
// first sort by partial name only
return sort.createSortKey(r, r.getPartialName(), 0, cache);
}
};
ArrayList<Mdr7Record> sorted = new ArrayList<>(allStreets);
allStreets.clear();
partialSorter.sort(sorted);
// list is now sorted by partial name only, we have to group by name and map index now
String lastPartial = null;
List<Mdr7Record> samePartial = new ArrayList<>();
Collator collator = sort.getCollator();
collator.setStrength(Collator.SECONDARY);
for (int i = 0; i < sorted.size(); i++) {
Mdr7Record r = sorted.get(i);
String partial = r.getPartialName();
if (lastPartial == null || collator.compare(partial, lastPartial) != 0) {
groupByNameAndMap(samePartial);
samePartial.clear();
}
samePartial.add(r);
lastPartial = partial;
}
groupByNameAndMap(samePartial);
allStreets.trimToSize();
streets.trimToSize();
return;
}
use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.
the class FileInfo method getSort.
public Sort getSort() {
Sort sort = SrtTextReader.sortForCodepage(codePage);
if (sort == null)
sort = args.getSort();
sort.setSortOrderId(sortOrderId);
return sort;
}
use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.
the class FileCopier method addSrtFile.
/**
* Add the sort file for the given family id.
*/
private void addSrtFile(int familyId, FileInfo info) {
Sort prevSort = sortMap.get(familyId);
Sort sort = info.getSort();
if (prevSort == null) {
if (info.getKind() == FileKind.IMG_KIND) {
sortMap.put(familyId, sort);
}
} else {
if (prevSort.getCodepage() != sort.getCodepage())
System.err.printf("WARNING: input file '%s' has a different code page (%d rather than %d)\n", info.getFilename(), sort.getCodepage(), prevSort.getCodepage());
if (info.hasSortOrder() && prevSort.getSortOrderId() != sort.getSortOrderId())
System.err.printf("WARNING: input file '%s' has a different sort order (%x rather than %x\n", info.getFilename(), sort.getSortOrderId(), prevSort.getSortOrderId());
}
}
use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.
the class FileCopier method writeSrtFile.
/**
* Write the SRT file.
*
* @param imgFs The filesystem to create the SRT file in.
* @throws FileNotWritableException If it cannot be created.
*/
private void writeSrtFile(FileSystem imgFs) throws FileNotWritableException {
for (Map.Entry<Integer, Sort> ent : sortMap.entrySet()) {
Sort sort = ent.getValue();
int familyId = ent.getKey();
if (sort.getId1() == 0 && sort.getId2() == 0)
return;
try {
ImgChannel channel = imgFs.create(String.format("%08d.SRT", familyId));
SRTFile srtFile = new SRTFile(channel);
srtFile.setSort(sort);
srtFile.write();
// Do not close srtFile here
} catch (FileExistsException e) {
// well it shouldn't exist!
log.error("could not create SRT file as it exists already");
throw new FileNotWritableException("already existed", e);
}
}
}
use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.
the class OverviewBuilder method writeOverviewMap.
/**
* Write out the overview map.
*/
private void writeOverviewMap() {
if (overviewSource.mapLevels() == null)
return;
MapBuilder mb = new MapBuilder();
mb.setEnableLineCleanFilters(false);
FileSystemParam params = new FileSystemParam();
params.setMapDescription(areaName);
mb.setCopyrights(creMsgList(copyrightMsgs));
mb.setMapInfo(creMsgList(licenseInfos));
try {
if (codepage == null) {
// should not happen
codepage = 0;
}
Sort sort = SrtTextReader.sortForCodepage(codepage);
Map map = Map.createMap(overviewMapname, outputDir, params, overviewMapnumber, sort);
if (!demProps.isEmpty()) {
map.config(demProps);
mb.config(demProps);
}
if (encodingType != null) {
map.getLblFile().setEncoder(encodingType, codepage);
}
mb.makeMap(map, overviewSource);
map.close();
} catch (FileExistsException e) {
throw new ExitException("Could not create overview map", e);
} catch (FileNotWritableException e) {
throw new ExitException("Could not write to overview map", e);
}
}
Aggregations