Search in sources :

Example 16 with Sort

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

the class MapMaker method setOptions.

/**
 * Set options from the command line.
 *
 * @param map The map to modify.
 * @param args The command line arguments.
 */
private void setOptions(Map map, CommandArgs args) {
    map.config(args.getProperties());
    String s = args.getCharset();
    if (s != null)
        map.setLabelCharset(s, args.isForceUpper());
    Sort sort = args.getSort();
    map.setSort(sort);
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort)

Example 17 with Sort

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

the class LBLHeader method readFileHeader.

/**
 * Read the rest of the header.  Specific to the given file.  It is guaranteed
 * that the file position will be set to the correct place before this is
 * called.
 *
 * @param reader The header is read from here.
 */
protected void readFileHeader(ImgFileReader reader) {
    labelStart = reader.getInt();
    labelSize = reader.getInt();
    offsetMultiplier = 1 << reader.get();
    encodingType = reader.get();
    // Read the places part of the header.
    placeHeader.readFileHeader(reader);
    int codepage = reader.getChar();
    int id1 = reader.getChar();
    int id2 = reader.getChar();
    int descOff = reader.getInt();
    int descLen = reader.getInt();
    reader.position(descOff);
    byte[] bytes = reader.get(descLen);
    String description;
    try {
        description = new String(bytes, "ascii");
    } catch (UnsupportedEncodingException e) {
        description = "Unknown";
    }
    sort = new Sort();
    sort.setCodepage(codepage);
    sort.setId1(id1);
    sort.setId2(id2);
    sort.setDescription(description);
    // more to do but not needed yet...  Just set position
    reader.position(labelStart);
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) Sort(uk.me.parabola.imgfmt.app.srt.Sort)

Example 18 with Sort

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

the class MDRFile method addMap.

/**
 * Add a map to the index.  You must add the map, then all of the items
 * that belong to it, before adding the next map.
 * @param mapName The numeric name of the map.
 * @param codePage The code page of the map.
 */
public void addMap(int mapName, int codePage) {
    currentMap++;
    mdr1.addMap(mapName, currentMap);
    Sort sort = mdrHeader.getSort();
    if (sort.getCodepage() != codePage)
        System.err.println("WARNING: input files have different code pages");
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort)

Example 19 with Sort

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

the class Mdr11 method preWriteImpl.

/**
 * Sort and fill in the mdr10 information.
 *
 * The POI index contains individual references to POI by subdiv and index, so they are not
 * de-duplicated in the index in the same way that streets and cities are.
 */
protected void preWriteImpl() {
    pois.trimToSize();
    Sort sort = getConfig().getSort();
    LargeListSorter<Mdr11Record> sorter = new LargeListSorter<Mdr11Record>(sort) {

        @Override
        protected SortKey<Mdr11Record> makeKey(Mdr11Record r, Sort sort, Map<String, byte[]> cache) {
            return sort.createSortKey(r, r.getName(), r.getMapIndex(), cache);
        }
    };
    // System.out.println("sorting " + pois.size() + " pois by name");
    sorter.sort(pois);
    for (Mdr11Record poi : pois) {
        mdr10.addPoiType(poi);
    }
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort) Map(java.util.Map)

Example 20 with Sort

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

the class PrefixIndex method createFromList.

/**
 * We can create an index for any type that has a name.
 * @param list A list of items that have a name.
 */
public void createFromList(List<? extends NamedRecord> list, boolean grouped) {
    maxIndex = list.size();
    // Prefixes are equal based on the primary unaccented character, so
    // we need to use the collator to test for equality and not equals().
    Sort sort = getConfig().getSort();
    Sort.SrtCollator collator = (SrtCollator) sort.getCollator();
    collator.setStrength(Collator.PRIMARY);
    String lastCountryName = null;
    char[] lastPrefix = "".toCharArray();
    // record number of the input list
    int inRecord = 0;
    // record number of the index
    int outRecord = 0;
    int lastMdr22SortPos = -1;
    for (NamedRecord r : list) {
        inRecord++;
        String name;
        if (r instanceof Mdr7Record) {
            name = ((Mdr7Record) r).getPartialName();
            if (grouped) {
                int mdr22SortPos = ((Mdr7Record) r).getCity().getMdr22SortPos();
                if (mdr22SortPos != lastMdr22SortPos)
                    lastPrefix = "".toCharArray();
                lastMdr22SortPos = mdr22SortPos;
            }
        } else
            name = r.getName();
        char[] prefix = sort.getPrefix(name, prefixLength);
        int cmp = collator.compareOneStrengthWithLength(prefix, lastPrefix, Collator.PRIMARY, prefixLength);
        if (cmp > 0) {
            outRecord++;
            Mdr8Record ind = new Mdr8Record();
            ind.setPrefix(prefix);
            ind.setRecordNumber(inRecord);
            index.add(ind);
            lastPrefix = prefix;
            if (grouped) {
                // Peek into the real type to support the mdr17 feature of indexes sorted on country.
                Mdr5Record city = ((Mdr7Record) r).getCity();
                if (city != null) {
                    String countryName = city.getCountryName();
                    if (!countryName.equals(lastCountryName)) {
                        city.getMdrCountry().getMdr29().setMdr17(outRecord);
                        lastCountryName = countryName;
                    }
                }
            }
        }
    }
}
Also used : SrtCollator(uk.me.parabola.imgfmt.app.srt.Sort.SrtCollator) Sort(uk.me.parabola.imgfmt.app.srt.Sort) SrtCollator(uk.me.parabola.imgfmt.app.srt.Sort.SrtCollator)

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