use of uk.me.parabola.imgfmt.app.lbl.Zip in project mkgmap by openstreetmap.
the class MapBuilder method processRoads.
private void processRoads(Map map, MapDataSource src) {
LBLFile lbl = map.getLblFile();
MapPoint searchPoint = new MapPoint();
for (MapLine line : src.getLines()) {
if (line.isRoad()) {
String cityName = line.getCity();
String cityCountryName = line.getCountry();
String cityRegionName = line.getRegion();
String zipStr = line.getZip();
if (cityName == null && locationAutofill.contains("nearest")) {
// Get name of next city if untagged
searchPoint.setLocation(line.getLocation());
MapPoint nextCity = locator.findNextPoint(searchPoint);
if (nextCity != null) {
cityName = nextCity.getCity();
// city/region/country fields should match to the found city
cityCountryName = nextCity.getCountry();
cityRegionName = nextCity.getRegion();
// use the zip code only if no zip code is known
if (zipStr == null)
zipStr = nextCity.getZip();
}
}
MapRoad road = (MapRoad) line;
road.resetImgData();
City roadCity = calcCity(lbl, cityName, cityRegionName, cityCountryName);
if (roadCity != null)
road.addRoadCity(roadCity);
if (zipStr != null) {
road.addRoadZip(lbl.createZip(zipStr));
}
List<Numbers> numbers = road.getRoadDef().getNumbersList();
if (numbers != null) {
for (Numbers num : numbers) {
for (int i = 0; i < 2; i++) {
boolean left = (i == 0);
ZipCodeInfo zipInfo = num.getZipCodeInfo(left);
if (zipInfo != null && zipInfo.getZipCode() != null) {
Zip zip = zipInfo.getImgZip();
if (zipInfo.getImgZip() == null) {
zip = lbl.createZip(zipInfo.getZipCode());
zipInfo.setImgZip(zip);
}
if (zip != null)
road.addRoadZip(zip);
}
CityInfo cityInfo = num.getCityInfo(left);
if (cityInfo != null) {
City city = cityInfo.getImgCity();
if (city == null) {
city = calcCity(lbl, cityInfo.getCity(), cityInfo.getRegion(), cityInfo.getCountry());
cityInfo.setImgCity(city);
}
if (city != null)
road.addRoadCity(city);
}
}
}
}
}
}
}
use of uk.me.parabola.imgfmt.app.lbl.Zip in project mkgmap by openstreetmap.
the class RoadDef method writeNet1.
/**
* This is for writing to NET1.
* @param writer A writer that is positioned within NET1.
*/
void writeNet1(ImgFileWriter writer, int numCities, int numZips) {
if (numlabels == 0)
return;
assert numlabels > 0;
Zip zip = getZips().isEmpty() ? null : getZips().get(0);
City city = getCities().isEmpty() ? null : getCities().get(0);
offsetNet1 = writer.position();
NumberPreparer numbers = null;
if (numbersList != null) {
numbers = new NumberPreparer(numbersList, zip, city, numCities, numZips);
if (!numbers.prepare()) {
numbers = null;
log.warn("Invalid housenumbers in", this.toString());
}
}
writeLabels(writer);
if (numbers != null && numbers.getSwapped()) {
// swapped default; left=even, right=odd
netFlags |= 0x20;
}
writer.put((byte) netFlags);
writer.put3(roadLength);
int maxlevel = writeLevelCount(writer);
writeLevelDivs(writer, maxlevel);
if ((netFlags & NET_FLAG_ADDRINFO) != 0) {
nodeCount--;
if (nodeCount + 2 != nnodes) {
log.error("internal error? The nodeCount doesn't match value calculated by RoadNetWork:", this);
}
// lo bits of node count
writer.put((byte) (nodeCount & 0xff));
// top bits of node count
int code = ((nodeCount >> 8) & 0x3);
int len, flag;
ByteArrayOutputStream zipBuf = null, cityBuf = null;
len = (numbers == null) ? 0 : numbers.zipWriter.getBuffer().size();
if (len > 0) {
zipBuf = numbers.zipWriter.getBuffer();
flag = Utils.numberToPointerSize(len) - 1;
} else
flag = (zip == null) ? 3 : 2;
code |= flag << 2;
len = (numbers == null) ? 0 : numbers.cityWriter.getBuffer().size();
if (len > 0) {
cityBuf = numbers.cityWriter.getBuffer();
flag = Utils.numberToPointerSize(len) - 1;
} else
flag = (city == null) ? 3 : 2;
code |= flag << 4;
len = (numbers == null) ? 0 : numbers.fetchBitStream().getLength();
if (len > 0) {
flag = Utils.numberToPointerSize(len) - 1;
} else
flag = 3;
code |= flag << 6;
writer.put((byte) code);
if (zipBuf != null) {
len = zipBuf.size();
writer.putN(Utils.numberToPointerSize(len), len);
writer.put(zipBuf.toByteArray());
} else {
if (zip != null) {
char zipIndex = (char) zip.getIndex();
writer.putN(Utils.numberToPointerSize(numZips), zipIndex);
}
}
if (cityBuf != null) {
len = cityBuf.size();
writer.putN(Utils.numberToPointerSize(len), len);
writer.put(cityBuf.toByteArray());
} else {
if (city != null) {
char cityIndex = (char) city.getIndex();
writer.putN(Utils.numberToPointerSize(numCities), cityIndex);
}
}
if (numbers != null) {
BitWriter bw = numbers.fetchBitStream();
writer.putN(Utils.numberToPointerSize(bw.getLength()), bw.getLength());
writer.put(bw.getBytes(), 0, bw.getLength());
}
}
if (hasNodInfo()) {
// This is the offset of an entry in NOD2
int val = offsetNod2;
if (val < 0x7fff) {
writer.put((byte) 1);
writer.putChar((char) val);
} else {
writer.put((byte) 2);
writer.put3(val);
}
}
}
use of uk.me.parabola.imgfmt.app.lbl.Zip in project mkgmap by openstreetmap.
the class MapBuilder method processPOIs.
private void processPOIs(Map map, MapDataSource src) {
LBLFile lbl = map.getLblFile();
boolean checkedForPoiDispFlag = false;
for (MapPoint p : src.getPoints()) {
// special handling for highway exits
if (p.isExit()) {
processExit(map, (MapExitPoint) p);
} else // * all POIs except roads in case the no-poi-address option is set
if (!p.isCity() && !p.hasExtendedType() && poiAddresses) {
String countryStr = p.getCountry();
String regionStr = p.getRegion();
String zipStr = p.getZip();
String cityStr = p.getCity();
if (locationAutofill.contains("nearest") && (countryStr == null || regionStr == null || (zipStr == null && cityStr == null))) {
MapPoint nextCity = locator.findNearbyCityByName(p);
if (nextCity == null)
nextCity = locator.findNextPoint(p);
if (nextCity != null) {
if (countryStr == null)
countryStr = nextCity.getCountry();
if (regionStr == null)
regionStr = nextCity.getRegion();
if (zipStr == null) {
String cityZipStr = nextCity.getZip();
if (cityZipStr != null && cityZipStr.indexOf(',') < 0)
zipStr = cityZipStr;
}
if (cityStr == null)
cityStr = nextCity.getCity();
}
}
if (countryStr != null && !checkedForPoiDispFlag) {
// Different countries require different address notation
poiDisplayFlags = locator.getPOIDispFlag(countryStr);
checkedForPoiDispFlag = true;
}
POIRecord r = lbl.createPOI(p.getName());
if (cityStr != null || regionStr != null || countryStr != null) {
r.setCity(calcCity(lbl, cityStr, regionStr, countryStr));
}
if (zipStr != null) {
Zip zip = lbl.createZip(zipStr);
r.setZip(zip);
}
if (p.getStreet() != null) {
Label streetName = lbl.newLabel(p.getStreet());
r.setStreetName(streetName);
}
String houseNumber = p.getHouseNumber();
if (houseNumber != null && !houseNumber.isEmpty()) {
if (!r.setSimpleStreetNumber(houseNumber))
r.setComplexStreetNumber(lbl.newLabel(houseNumber));
}
String phone = p.getPhone();
if (phone != null && !phone.isEmpty()) {
if (!r.setSimplePhoneNumber(phone))
r.setComplexPhoneNumber(lbl.newLabel(phone));
}
poimap.put(p, r);
}
}
lbl.allPOIsDone();
}
Aggregations