Search in sources :

Example 11 with Sort

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;
}
Also used : ArrayList(java.util.ArrayList) Sort(uk.me.parabola.imgfmt.app.srt.Sort) Map(java.util.Map) Collator(java.text.Collator)

Example 12 with Sort

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;
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort)

Example 13 with 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());
    }
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort)

Example 14 with Sort

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);
        }
    }
}
Also used : FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) FileNotWritableException(uk.me.parabola.imgfmt.FileNotWritableException) Sort(uk.me.parabola.imgfmt.app.srt.Sort) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Example 15 with Sort

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);
    }
}
Also used : FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) FileNotWritableException(uk.me.parabola.imgfmt.FileNotWritableException) Sort(uk.me.parabola.imgfmt.app.srt.Sort) MapBuilder(uk.me.parabola.mkgmap.build.MapBuilder) Map(uk.me.parabola.imgfmt.app.map.Map) ExitException(uk.me.parabola.imgfmt.ExitException) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Aggregations

Sort (uk.me.parabola.imgfmt.app.srt.Sort)26 SortKey (uk.me.parabola.imgfmt.app.srt.SortKey)12 ArrayList (java.util.ArrayList)9 ExitException (uk.me.parabola.imgfmt.ExitException)4 MultiSortKey (uk.me.parabola.imgfmt.app.srt.MultiSortKey)4 IOException (java.io.IOException)3 Map (java.util.Map)3 FileExistsException (uk.me.parabola.imgfmt.FileExistsException)3 SRTFile (uk.me.parabola.imgfmt.app.srt.SRTFile)3 ImgChannel (uk.me.parabola.imgfmt.fs.ImgChannel)3 CharacterCodingException (java.nio.charset.CharacterCodingException)2 Collator (java.text.Collator)2 FileNotWritableException (uk.me.parabola.imgfmt.FileNotWritableException)2 FileSystemParam (uk.me.parabola.imgfmt.FileSystemParam)2 FileImgChannel (uk.me.parabola.imgfmt.sys.FileImgChannel)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1