use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.
the class Mdr25 method sortCities.
/**
* Cities are sorted by country and then by the mdr5 city record number.
* @param list The complete list of cities from mdr5.
*/
public void sortCities(List<Mdr5Record> list) {
Sort sort = getConfig().getSort();
List<SortKey<Mdr5Record>> keys = new ArrayList<SortKey<Mdr5Record>>();
for (Mdr5Record c : list) {
SortKey<Mdr5Record> key = sort.createSortKey(c, c.getMdrCountry().getName(), c.getGlobalCityIndex());
keys.add(key);
}
Collections.sort(keys);
String lastName = null;
Mdr5Record lastCity = null;
int record = 0;
for (SortKey<Mdr5Record> key : keys) {
Mdr5Record city = key.getObject();
if (lastCity == null || (!city.getName().equals(lastCity.getName()) || !(city.getRegionName().equals(lastCity.getRegionName())))) {
record++;
// Record in the 29 index if there is one for this record
Mdr14Record mdrCountry = city.getMdrCountry();
Mdr29Record mdr29 = mdrCountry.getMdr29();
String name = mdr29.getName();
assert mdrCountry.getName().equals(name);
if (!name.equals(lastName)) {
mdr29.setMdr25(record);
lastName = name;
}
cities.add(city);
lastCity = city;
}
}
}
use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.
the class Mdr26 method sortMdr28.
public void sortMdr28(List<Mdr28Record> in) {
Sort sort = getConfig().getSort();
List<SortKey<Mdr28Record>> sortList = new ArrayList<SortKey<Mdr28Record>>();
int record = 0;
for (Mdr28Record mdr28 : in) {
SortKey<Mdr28Record> key = sort.createSortKey(mdr28, mdr28.getMdr14().getName(), ++record);
sortList.add(key);
}
Collections.sort(sortList);
addToIndex(sortList);
}
use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.
the class Mdr27 method sortCities.
/**
* Cities are sorted by region and then by the mdr5 city record number.
* @param list The complete list of cities from mdr5.
*/
public void sortCities(List<Mdr5Record> list) {
Sort sort = getConfig().getSort();
List<SortKey<Mdr5Record>> keys = new ArrayList<SortKey<Mdr5Record>>();
for (Mdr5Record c : list) {
Mdr13Record mdrRegion = c.getMdrRegion();
if (mdrRegion != null) {
SortKey<Mdr5Record> key = sort.createSortKey(c, mdrRegion.getName(), c.getGlobalCityIndex());
keys.add(key);
}
}
Collections.sort(keys);
String lastName = null;
int record = 0;
for (SortKey<Mdr5Record> key : keys) {
record++;
Mdr5Record city = key.getObject();
Mdr13Record mdrRegion = city.getMdrRegion();
Mdr28Record mdr28 = mdrRegion.getMdr28();
String name = mdr28.getName();
if (!name.equals(lastName)) {
mdr28.setMdr27(record);
lastName = name;
}
cities.add(city);
}
}
use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.
the class SrtTextReader method main.
/**
* Read in a sort description text file and create a SRT from it.
* @param args First arg is the text input file, the second is the name of the output file. The defaults are
* in.txt and out.srt.
*/
public static void main(String[] args) throws IOException {
String infile = "in.txt";
if (args.length > 0)
infile = args[0];
String outfile = "out.srt";
if (args.length > 1)
outfile = args[1];
try {
Files.delete(Paths.get(outfile, ""));
} catch (Exception e) {
}
ImgChannel chan = new FileImgChannel(outfile, "rw");
SRTFile sf = new SRTFile(chan);
SrtTextReader tr = new SrtTextReader(infile);
Sort sort1 = tr.getSort();
sf.setSort(sort1);
sf.write();
sf.close();
chan.close();
}
use of uk.me.parabola.imgfmt.app.srt.Sort in project mkgmap by openstreetmap.
the class SrtTextReader method sortForCodepage.
/**
* Find and read in the default sort description for the given codepage.
*/
public static Sort sortForCodepage(int codepage) {
String name = "sort/cp" + codepage + ".txt";
InputStream is = Sort.class.getClassLoader().getResourceAsStream(name);
if (is == null) {
if (codepage == 1252)
throw new ExitException("No sort description for code-page 1252 available");
Sort defaultSort = SrtTextReader.sortForCodepage(1252);
defaultSort.setCodepage(codepage);
defaultSort.setDescription("Default sort");
return defaultSort;
}
try {
InputStreamReader r = new InputStreamReader(is, "utf-8");
SrtTextReader sr = new SrtTextReader(r);
return sr.getSort();
} catch (IOException e) {
return SrtTextReader.sortForCodepage(codepage);
}
}
Aggregations