Search in sources :

Example 1 with CityInfo

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

the class HousenumberGenerator method createHousenumberRoads.

private List<HousenumberRoad> createHousenumberRoads(MultiHashMap<MapRoad, HousenumberMatch> initialHousesForRoads) {
    List<HousenumberRoad> hnrList = new ArrayList<>();
    for (MapRoad road : allRoads) {
        if (road.isSkipHousenumberProcessing())
            continue;
        List<HousenumberMatch> houses = initialHousesForRoads.get(road);
        if (houses == null || houses.isEmpty())
            continue;
        CityInfo ci = getCityInfos(road.getCity(), road.getRegion(), road.getCountry());
        HousenumberRoad hnr = new HousenumberRoad(road, ci, houses);
        if (road.getZip() != null)
            hnr.setZipCodeInfo(getZipInfos(road.getZip()));
        hnrList.add(hnr);
    }
    return hnrList;
}
Also used : CityInfo(uk.me.parabola.mkgmap.general.CityInfo) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ArrayList(java.util.ArrayList) MapRoad(uk.me.parabola.mkgmap.general.MapRoad)

Example 2 with CityInfo

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

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

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

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

the class HousenumberGenerator method getCityInfos.

private CityInfo getCityInfos(String city, String region, String country) {
    CityInfo ci = new CityInfo(city, region, country);
    CityInfo ciOld = cityInfos.get(ci);
    if (ciOld != null)
        return ciOld;
    // log.debug(ci);
    cityInfos.put(ci, ci);
    return ci;
}
Also used : CityInfo(uk.me.parabola.mkgmap.general.CityInfo)

Aggregations

CityInfo (uk.me.parabola.mkgmap.general.CityInfo)12 ZipCodeInfo (uk.me.parabola.mkgmap.general.ZipCodeInfo)6 ArrayList (java.util.ArrayList)5 LongArrayList (it.unimi.dsi.fastutil.longs.LongArrayList)4 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)3 Coord (uk.me.parabola.imgfmt.app.Coord)3 MapRoad (uk.me.parabola.mkgmap.general.MapRoad)3 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)2 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Numbers (uk.me.parabola.imgfmt.app.net.Numbers)2 MultiHashMap (uk.me.parabola.util.MultiHashMap)2 List (java.util.List)1 TreeMap (java.util.TreeMap)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