Search in sources :

Example 1 with ZipCodeInfo

use of uk.me.parabola.mkgmap.general.ZipCodeInfo in project mkgmap by openstreetmap.

the class HousenumberIvl method getInterpolatedHouses.

public List<HousenumberMatch> getInterpolatedHouses() {
    List<HousenumberMatch> houses = new ArrayList<>();
    if (ignoreForInterpolation || start == end || steps <= 0)
        return houses;
    List<Coord> interpolatedPoints = getInterpolatedPoints();
    int usedStep = (start < end) ? step : -step;
    int hn = start;
    boolean distanceWarningIssued = false;
    CityInfo ci = knownHouses[0].getCityInfo();
    ZipCodeInfo zip = knownHouses[0].getZipCode();
    if (ci != null && ci.equals(knownHouses[1].getCityInfo()) == false)
        log.warn("addr:interpolation way connects houses in different cities", streetName, this, "using city", ci, "for all interpolated adresses");
    if (zip != null && zip.equals(knownHouses[1].getZipCode()) == false)
        log.warn("addr:interpolation way connects houses with differnt zip codes", streetName, this, "using zip code", zip, "for all interpolated adresses");
    for (Coord co : interpolatedPoints) {
        hn += usedStep;
        Node generated = new Node(interpolationWay.getId(), co);
        generated.setFakeId();
        generated.addTag(streetTagKey, streetName);
        String number = String.valueOf(hn);
        generated.addTag(housenumberTagKey, number);
        // TODO: maybe add check that city info and zip code of both houses is equal ?
        // what if not ?
        HousenumberElem houseElem = new HousenumberElem(generated, ci);
        houseElem.setHousenumber(hn);
        houseElem.setZipCode(zip);
        houseElem.setStreet(streetName);
        houseElem.setSign(number);
        HousenumberMatch house = new HousenumberMatch(houseElem);
        if (roadForInterpolatedHouses != null) {
            HousenumberGenerator.findClosestRoadSegment(house, roadForInterpolatedHouses);
            if (house.getRoad() == null || house.getDistance() > MAX_INTERPOLATION_DISTANCE_TO_ROAD) {
                if (distanceWarningIssued == false) {
                    log.warn("interpolated house is not close to expected road", this, house);
                    distanceWarningIssued = true;
                }
                continue;
            }
            house.calcRoadSide();
        }
        house.setInterpolated(true);
        houses.add(house);
    }
    if (log.isDebugEnabled()) {
        String addrInterpolationMethod = interpolationWay.getTag(addrInterpolationTagKey);
        if (hasMultipleRoads == false)
            log.debug(this, "generated", addrInterpolationMethod, "interpolated number(s) for", knownHouses[0].getRoad());
        else
            log.debug(this, "generated", addrInterpolationMethod, "interpolated number(s) for", streetName);
    }
    return houses;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) CityInfo(uk.me.parabola.mkgmap.general.CityInfo) ZipCodeInfo(uk.me.parabola.mkgmap.general.ZipCodeInfo) Node(uk.me.parabola.mkgmap.reader.osm.Node) ArrayList(java.util.ArrayList)

Example 2 with ZipCodeInfo

use of uk.me.parabola.mkgmap.general.ZipCodeInfo 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 3 with ZipCodeInfo

use of uk.me.parabola.mkgmap.general.ZipCodeInfo in project mkgmap by openstreetmap.

the class ExtNumbers method fillNumbers.

/**
 * Apply the given house numbers to the numbers object.
 * @param left {@code true} the left side of the street; {@code false} the right side of the street
 */
private void fillNumbers(boolean left) {
    NumberStyle style = NumberStyle.NONE;
    List<HousenumberMatch> houses = getHouses(left);
    if (houses.isEmpty() == false) {
        Set<CityInfo> cityInfos = new HashSet<>();
        Set<ZipCodeInfo> zipCodes = new HashSet<>();
        // get the sublist of house numbers
        boolean even = false;
        boolean odd = false;
        boolean inOrder = true;
        boolean inc = false;
        boolean dec = false;
        HousenumberMatch highest, lowest;
        lowest = highest = houses.get(0);
        Int2IntOpenHashMap distinctNumbers = new Int2IntOpenHashMap();
        int numHouses = houses.size();
        HousenumberMatch pred = null;
        for (int i = 0; i < numHouses; i++) {
            HousenumberMatch house = houses.get(i);
            if (house.getCityInfo() != null && house.getCityInfo().isEmpty() == false)
                cityInfos.add(house.getCityInfo());
            if (house.getZipCode() != null && house.getZipCode().getZipCode() != null)
                zipCodes.add(house.getZipCode());
            int num = house.getHousenumber();
            if (!hasGaps)
                distinctNumbers.put(num, 1);
            if (num > highest.getHousenumber())
                highest = house;
            if (num < lowest.getHousenumber())
                lowest = house;
            if (num % 2 == 0) {
                even = true;
            } else {
                odd = true;
            }
            if (pred != null) {
                int diff = num - pred.getHousenumber();
                if (diff > 0)
                    inc = true;
                else if (diff < 0)
                    dec = true;
            }
            pred = house;
        }
        if (even && odd) {
            style = NumberStyle.BOTH;
        } else if (even) {
            style = NumberStyle.EVEN;
        } else {
            style = NumberStyle.ODD;
        }
        int highestNum = highest.getHousenumber();
        int lowestNum = lowest.getHousenumber();
        int start = houses.get(0).getHousenumber();
        int end = houses.get(numHouses - 1).getHousenumber();
        // from low to high
        boolean increasing = false;
        if (dec & inc)
            inOrder = false;
        if (start == end && highestNum - lowestNum != 0) {
            if (prev != null) {
                int lastEnd = prev.getNumbers().getEnd(left);
                if (lastEnd <= lowestNum)
                    increasing = true;
            } else if (next != null) {
                int nextStart = next.getNumbers().getStart(left);
                if (highestNum < nextStart)
                    increasing = true;
            } else {
                increasing = true;
            }
        } else if (start != highestNum && start != lowestNum || end != highestNum && end != lowestNum) {
            inOrder = false;
            if (start <= end)
                increasing = true;
        } else if (start < end) {
            increasing = true;
        }
        if (increasing) {
            start = lowestNum;
            end = highestNum;
        } else {
            start = highestNum;
            end = lowestNum;
        }
        if (!hasGaps) {
            int step = (style == NumberStyle.BOTH) ? 1 : 2;
            for (int n = lowestNum + step; n < highestNum; n += step) {
                if (distinctNumbers.containsKey(n))
                    continue;
                hasGaps = true;
                break;
            }
        }
        RoadSide rs = (left) ? leftSide : rightSide;
        numbers.setNumbers(left, style, start, end);
        rs.multipleCities = (cityInfos.size() > 1);
        rs.multipleZipCodes = (zipCodes.size() > 1);
        if (cityInfos.size() == 1) {
            CityInfo ci = cityInfos.iterator().next();
            if (ci.isEmpty() == false) {
                if (ci.equals(housenumberRoad.getRoadCityInfo()) == false)
                    numbers.setCityInfo(left, ci);
            }
        }
        if (zipCodes.size() == 1) {
            ZipCodeInfo zipCodeInfo = zipCodes.iterator().next();
            if (zipCodeInfo.getZipCode() != null) {
                if (zipCodeInfo.equals(housenumberRoad.getRoadZipCode()) == false) {
                    // we found a zip code and the road doesn't yet have one, use it for the whole road
                    if (housenumberRoad.getRoadZipCode() == null) {
                        housenumberRoad.setZipCodeInfo(zipCodeInfo);
                    } else
                        numbers.setZipCode(left, zipCodeInfo);
                }
            }
        }
        rs.notInOrder = !inOrder;
    }
}
Also used : CityInfo(uk.me.parabola.mkgmap.general.CityInfo) NumberStyle(uk.me.parabola.imgfmt.app.net.NumberStyle) ZipCodeInfo(uk.me.parabola.mkgmap.general.ZipCodeInfo) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) HashSet(java.util.HashSet)

Example 4 with ZipCodeInfo

use of uk.me.parabola.mkgmap.general.ZipCodeInfo in project mkgmap by openstreetmap.

the class HousenumberGenerator method parseElement.

private HousenumberElem parseElement(Element el, String sign) {
    String city = el.getTag(cityTagKey);
    String region = el.getTag(regionTagKey);
    String country = el.getTag(countryTagKey);
    CityInfo ci = getCityInfos(city, region, country);
    HousenumberElem house = new HousenumberElem(el, ci);
    if (house.getLocation() == null) {
        // there has been a report that indicates match.getLocation() == null
        // could not reproduce so far but catching it here with some additional
        // information. (WanMil)
        log.error("OSM element seems to have no point.");
        log.error("Element: " + el.toBrowseURL() + " " + el);
        log.error("Please report on the mkgmap mailing list.");
        log.error("Continue creating the map. This should be possible without a problem.");
        return null;
    }
    house.setSign(sign);
    Integer hn = parseHousenumber(sign);
    if (hn == null) {
        if (log.isDebugEnabled())
            log.debug("No housenumber (", el.toBrowseURL(), "): ", sign);
        return null;
    }
    if (hn < 0 || hn > 1_000_000) {
        log.warn("Number looks wrong, is ignored", house.getSign(), hn, "element", el.toBrowseURL());
        return null;
    }
    house.setHousenumber(hn);
    house.setStreet(getStreetname(el));
    house.setPlace(el.getTag(addrPlaceTagKey));
    String zipStr = el.getTag(postalCodeTagKey);
    ZipCodeInfo zip = getZipInfos(zipStr);
    house.setZipCode(zip);
    return house;
}
Also used : CityInfo(uk.me.parabola.mkgmap.general.CityInfo) ZipCodeInfo(uk.me.parabola.mkgmap.general.ZipCodeInfo)

Example 5 with ZipCodeInfo

use of uk.me.parabola.mkgmap.general.ZipCodeInfo in project mkgmap by openstreetmap.

the class HousenumberGenerator method getZipInfos.

private ZipCodeInfo getZipInfos(String zipStr) {
    ZipCodeInfo zip = new ZipCodeInfo(zipStr);
    ZipCodeInfo zipOld = zipInfos.get(zip);
    if (zipOld != null)
        return zipOld;
    zipInfos.put(zip, zip);
    return zip;
}
Also used : ZipCodeInfo(uk.me.parabola.mkgmap.general.ZipCodeInfo)

Aggregations

ZipCodeInfo (uk.me.parabola.mkgmap.general.ZipCodeInfo)7 CityInfo (uk.me.parabola.mkgmap.general.CityInfo)6 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Coord (uk.me.parabola.imgfmt.app.Coord)1 City (uk.me.parabola.imgfmt.app.lbl.City)1 LBLFile (uk.me.parabola.imgfmt.app.lbl.LBLFile)1 Zip (uk.me.parabola.imgfmt.app.lbl.Zip)1 NumberStyle (uk.me.parabola.imgfmt.app.net.NumberStyle)1 Numbers (uk.me.parabola.imgfmt.app.net.Numbers)1 Point (uk.me.parabola.imgfmt.app.trergn.Point)1 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)1 MapLine (uk.me.parabola.mkgmap.general.MapLine)1 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)1 MapRoad (uk.me.parabola.mkgmap.general.MapRoad)1 Node (uk.me.parabola.mkgmap.reader.osm.Node)1