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;
}
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;
}
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);
}
}
}
}
}
}
}
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;
}
}
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;
}
Aggregations