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);
}
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);
}
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");
}
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);
}
}
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;
}
}
}
}
}
}
Aggregations