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