Search in sources :

Example 1 with Zip

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : Zip(uk.me.parabola.imgfmt.app.lbl.Zip) CityInfo(uk.me.parabola.mkgmap.general.CityInfo) MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) City(uk.me.parabola.imgfmt.app.lbl.City) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) Point(uk.me.parabola.imgfmt.app.trergn.Point) Numbers(uk.me.parabola.imgfmt.app.net.Numbers) ZipCodeInfo(uk.me.parabola.mkgmap.general.ZipCodeInfo) LBLFile(uk.me.parabola.imgfmt.app.lbl.LBLFile)

Example 2 with Zip

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);
        }
    }
}
Also used : Zip(uk.me.parabola.imgfmt.app.lbl.Zip) BitWriter(uk.me.parabola.imgfmt.app.BitWriter) City(uk.me.parabola.imgfmt.app.lbl.City) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with Zip

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();
}
Also used : Zip(uk.me.parabola.imgfmt.app.lbl.Zip) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) Label(uk.me.parabola.imgfmt.app.Label) POIRecord(uk.me.parabola.imgfmt.app.lbl.POIRecord) LBLFile(uk.me.parabola.imgfmt.app.lbl.LBLFile)

Aggregations

Zip (uk.me.parabola.imgfmt.app.lbl.Zip)3 City (uk.me.parabola.imgfmt.app.lbl.City)2 LBLFile (uk.me.parabola.imgfmt.app.lbl.LBLFile)2 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 BitWriter (uk.me.parabola.imgfmt.app.BitWriter)1 Label (uk.me.parabola.imgfmt.app.Label)1 POIRecord (uk.me.parabola.imgfmt.app.lbl.POIRecord)1 Numbers (uk.me.parabola.imgfmt.app.net.Numbers)1 Point (uk.me.parabola.imgfmt.app.trergn.Point)1 CityInfo (uk.me.parabola.mkgmap.general.CityInfo)1 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)1 MapLine (uk.me.parabola.mkgmap.general.MapLine)1 MapRoad (uk.me.parabola.mkgmap.general.MapRoad)1 ZipCodeInfo (uk.me.parabola.mkgmap.general.ZipCodeInfo)1