Search in sources :

Example 21 with Sort

use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.

the class Mdr23 method sortRegions.

/**
 * Takes the region list and sorts it according to the name.
 * @param list Original region list.
 */
public void sortRegions(List<Mdr13Record> list) {
    Sort sort = getConfig().getSort();
    List<SortKey<Mdr13Record>> keys = MdrUtils.sortList(sort, list);
    Collections.sort(keys);
    String lastName = null;
    int lastMapIndex = 0;
    int record = 0;
    for (SortKey<Mdr13Record> key : keys) {
        Mdr13Record reg = key.getObject();
        // Only add if different name or map
        String name = reg.getName();
        if (reg.getMapIndex() != lastMapIndex || !name.equals(lastName)) {
            record++;
            reg.getMdr28().setMdr23(record);
            regions.add(reg);
            lastName = name;
            lastMapIndex = reg.getMapIndex();
        }
    }
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey)

Example 22 with Sort

use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.

the class Mdr24 method sortCountries.

/**
 * Sort the countries by name. Duplicates are kept.
 * @param list The full list of countries.
 */
public void sortCountries(List<Mdr14Record> list) {
    Sort sort = getConfig().getSort();
    List<SortKey<Mdr14Record>> keys = MdrUtils.sortList(sort, list);
    Collections.sort(keys);
    String lastName = null;
    int lastMapIndex = 0;
    int record = 0;
    for (SortKey<Mdr14Record> key : keys) {
        Mdr14Record c = key.getObject();
        // If this is a new name, then we prepare a mdr29 record for it.
        String name = c.getName();
        if (lastMapIndex != c.getMapIndex() || !name.equals(lastName)) {
            record++;
            c.getMdr29().setMdr24(record);
            countries.add(c);
            lastName = name;
            lastMapIndex = c.getMapIndex();
        }
    }
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey)

Example 23 with Sort

use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.

the class Mdr28 method buildFromRegions.

public void buildFromRegions(List<Mdr13Record> regions) {
    Sort sort = getConfig().getSort();
    List<SortKey<Mdr13Record>> keys = MdrUtils.sortList(sort, regions);
    int record = 0;
    Mdr28Record mdr28 = null;
    String lastName = null;
    for (SortKey<Mdr13Record> key : keys) {
        Mdr13Record region = key.getObject();
        String name = region.getName();
        if (!name.equals(lastName)) {
            record++;
            mdr28 = new Mdr28Record();
            mdr28.setIndex(record);
            mdr28.setName(name);
            mdr28.setStrOffset(region.getStrOffset());
            mdr28.setMdr14(region.getMdr14());
            index.add(mdr28);
            lastName = name;
        }
        assert mdr28 != null;
        region.setMdr28(mdr28);
    }
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey)

Example 24 with Sort

use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.

the class Mdr29 method buildFromCountries.

public void buildFromCountries(List<Mdr14Record> countries) {
    Sort sort = getConfig().getSort();
    List<SortKey<Mdr14Record>> keys = MdrUtils.sortList(sort, countries);
    // Sorted by name, for every new name we allocate a new 29 record and set the same one in every
    // country with the same name.
    String lastName = null;
    Mdr29Record mdr29 = null;
    for (SortKey<Mdr14Record> key : keys) {
        Mdr14Record country = key.getObject();
        String name = country.getName();
        if (!name.equals(lastName)) {
            mdr29 = new Mdr29Record();
            mdr29.setName(name);
            mdr29.setStrOffset(country.getStrOff());
            index.add(mdr29);
            lastName = name;
        }
        assert mdr29 != null;
        country.setMdr29(mdr29);
    }
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey)

Example 25 with Sort

use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.

the class MdrBuilder method init.

/**
 * Create the mdr file and initialise.
 * It has a name that is based on the overview-mapname option, as does
 * the associated MDX file.
 *
 * @param args The command line arguments.
 */
public void init(CommandArgs args) {
    String name = args.get("overview-mapname", "osmmap");
    String outputDir = args.getOutputDir();
    outputName = Utils.joinPath(outputDir, name + "_mdr.img");
    ImgChannel mdrChan;
    try {
        // Create the .img file system/archive
        FileSystemParam params = new FileSystemParam();
        tmpName = File.createTempFile("mdr", null, new File(outputDir));
        tmpName.deleteOnExit();
        imgfs = ImgFS.createFs(tmpName.getPath(), params);
        // Create the MDR file within the .img
        mdrChan = imgfs.create(name.toUpperCase(Locale.ENGLISH) + ".MDR");
    } catch (IOException e) {
        throw new ExitException("Could not create global index file");
    }
    // Create the sort description
    Sort sort = SrtTextReader.sortForCodepage(args.getCodePage());
    // Set the options that we are using for the mdr.
    MdrConfig config = new MdrConfig();
    config.setHeaderLen(568);
    config.setWritable(true);
    config.setForDevice(false);
    config.setOutputDir(outputDir);
    config.setSort(sort);
    config.setIndexOptions(args);
    // Wrap the MDR channel with the MDRFile object
    mdrFile = new MDRFile(mdrChan, config);
    try {
        ImgChannel srtChan = imgfs.create(name.toUpperCase(Locale.ENGLISH) + ".SRT");
        SRTFile srtFile = new SRTFile(srtChan);
        srtFile.setSort(sort);
        srtFile.write();
    // Do not close srtFile here
    } catch (FileExistsException e) {
        throw new ExitException("Could not create SRT file within index file");
    }
}
Also used : ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) MdrConfig(uk.me.parabola.imgfmt.app.mdr.MdrConfig) Sort(uk.me.parabola.imgfmt.app.srt.Sort) MDRFile(uk.me.parabola.imgfmt.app.mdr.MDRFile) IOException(java.io.IOException) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) File(java.io.File) MDRFile(uk.me.parabola.imgfmt.app.mdr.MDRFile) 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