use of uk.me.parabola.imgfmt.app.Label in project mkgmap by openstreetmap.
the class MapBuilder method processExit.
private void processExit(Map map, MapExitPoint mep) {
LBLFile lbl = map.getLblFile();
String ref = mep.getMotorwayRef();
String OSMId = mep.getOSMId();
if (ref != null) {
Highway hw = highways.get(ref);
if (hw == null)
hw = makeHighway(map, ref);
if (hw == null) {
log.warn("Can't create exit", mep.getName(), "(OSM id", OSMId, ") on unknown highway", ref);
return;
}
String exitName = mep.getName();
String exitTo = mep.getTo();
Exit exit = new Exit(hw);
String facilityDescription = mep.getFacilityDescription();
log.info("Creating", ref, "exit", exitName, "(OSM id", OSMId + ") to", exitTo, "with facility", ((facilityDescription == null) ? "(none)" : facilityDescription));
if (facilityDescription != null) {
// description is TYPE,DIR,FACILITIES,LABEL
// (same as Polish Format)
String[] atts = facilityDescription.split(",");
int type = 0;
if (atts.length > 0)
type = Integer.decode(atts[0]);
char direction = ' ';
if (atts.length > 1) {
direction = atts[1].charAt(0);
if (direction == '\'' && atts[1].length() > 1)
direction = atts[1].charAt(1);
}
int facilities = 0x0;
if (atts.length > 2)
facilities = Integer.decode(atts[2]);
String description = "";
if (atts.length > 3)
description = atts[3];
// FIXME - handle multiple facilities?
boolean last = true;
ExitFacility ef = lbl.createExitFacility(type, direction, facilities, description, last);
exit.addFacility(ef);
}
mep.setExit(exit);
POIRecord r = lbl.createExitPOI(exitName, exit);
if (exitTo != null) {
Label ed = lbl.newLabel(exitTo);
exit.setDescription(ed);
}
poimap.put(mep, r);
// FIXME - set bottom bits of
// type to reflect facilities available?
}
}
use of uk.me.parabola.imgfmt.app.Label in project mkgmap by openstreetmap.
the class MdrBuilder method addPoints.
/**
* Read points from this map and add them to the index.
* @param mr The currently open map.
* @param maps Maps of regions, cities countries etc.
*/
private void addPoints(MapReader mr, AreaMaps maps) {
List<Point> list = mr.pointsForLevel(0, MapReader.WITHOUT_EXT_TYPE_DATA);
for (Point p : list) {
Label label = p.getLabel();
if (p.getNumber() > 256) {
continue;
}
Mdr5Record mdrCity = null;
boolean isCity;
if (p.getType() >= 0x1 && p.getType() <= 0x11) {
// This is itself a city, it gets a reference to its own MDR 5 record.
// and we also use it to set the name of the city.
mdrCity = maps.cities.get((p.getSubdiv().getNumber() << 8) + p.getNumber());
if (mdrCity != null) {
mdrCity.setLblOffset(label.getOffset());
mdrCity.setName(label.getText());
}
isCity = true;
} else {
// This is not a city, but we have information about which city
// it is in. If so then add the mdr5 record number of the city.
POIRecord poi = p.getPOIRecord();
City c = poi.getCity();
if (c != null)
mdrCity = getMdr5FromCity(maps, c);
isCity = false;
}
if (label != null && !label.getText().trim().isEmpty())
mdrFile.addPoint(p, mdrCity, isCity);
}
}
use of uk.me.parabola.imgfmt.app.Label in project mkgmap by openstreetmap.
the class LBLFile method newLabel.
/**
* Add a new label with the given text. Labels are shared, so that identical
* text is always represented by the same label.
*
* @param text The text of the label, it will be in uppercase.
* @return A reference to the created label.
*/
public Label newLabel(String text) {
EncodedText encodedText = textEncoder.encodeText(text);
Label l = labelCache.get(encodedText);
if (l == null) {
l = new Label(encodedText.getChars());
labelCache.put(encodedText, l);
l.setOffset(getNextLabelOffset());
if (encodedText.getLength() > 0)
getWriter().put(encodedText.getCtext(), 0, encodedText.getLength());
alignForNext();
if (l.getOffset() > 0x3fffff)
throw new MapFailedException("Overflow of LBL section");
}
return l;
}
use of uk.me.parabola.imgfmt.app.Label in project mkgmap by openstreetmap.
the class LBLFileReader method readCities.
/**
* Read in the city section and cache the results here. They are needed
* to read in the POI properties section.
*/
private void readCities() {
PlacesHeader placeHeader = header.getPlaceHeader();
int start = placeHeader.getCitiesStart();
int end = placeHeader.getCitiesEnd();
ImgFileReader reader = getReader();
// Since cities are indexed starting from 1, we add a null one at index 0
reader.position(start);
int index = 1;
while (reader.position() < end) {
// First is either a label offset or a point/subdiv combo, we
// don't know until we have read further
int label = reader.getu3();
int info = reader.getChar();
City city;
if ((info & 0x4000) == 0) {
Region region = regions.get(info & 0x3fff);
city = new City(region);
} else {
Country country = countries.get(info & 0x3fff);
city = new City(country);
}
city.setIndex(index);
if ((info & 0x8000) == 0) {
city.setSubdivision(Subdivision.createEmptySubdivision(1));
Label label1 = labels.get(label & 0x3fffff);
city.setLabel(label1);
} else {
// Has subdiv/point index
int pointIndex = label & 0xff;
int subdiv = (label >> 8) & 0xffff;
city.setPointIndex((byte) pointIndex);
city.setSubdivision(Subdivision.createEmptySubdivision(subdiv));
}
cities.add(city);
index++;
}
}
use of uk.me.parabola.imgfmt.app.Label in project mkgmap by openstreetmap.
the class LBLFileReader method readCountries.
/**
* Read a cache the countries. These are used when reading cities.
*/
private void readCountries() {
ImgFileReader reader = getReader();
PlacesHeader placeHeader = header.getPlaceHeader();
// 1 based indexes
countries.add(null);
int start = placeHeader.getCountriesStart();
int end = placeHeader.getCountriesEnd();
reader.position(start);
int index = 1;
while (reader.position() < end) {
int offset = reader.getu3();
Label label = fetchLabel(offset);
if (label != null) {
Country country = new Country(index);
country.setLabel(label);
countries.add(country);
}
index++;
}
}
Aggregations