use of uk.me.parabola.mkgmap.general.MapPoint 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.MapPoint in project mkgmap by openstreetmap.
the class OverviewBuilder method readPoints.
/**
* Read the points from the .img file and add them to the overview map.
* We read from the least detailed level (apart from the empty one).
*
* @param mapReader Map reader on the detailed .img file.
*/
private void readPoints(MapReader mapReader) {
Area bounds = overviewSource.getBounds();
Zoom[] levels = mapReader.getLevels();
for (int l = 1; l < levels.length; l++) {
int min = levels[l].getLevel();
int res = levels[l].getResolution();
List<Point> pointList = mapReader.pointsForLevel(min, MapReader.WITH_EXT_TYPE_DATA);
for (Point point : pointList) {
if (log.isDebugEnabled())
log.debug("got point", point);
if (bounds.contains(point.getLocation()) == false) {
if (log.isDebugEnabled())
log.debug(point, "dropped, is outside of tile boundary");
continue;
}
MapPoint mp = new MapPoint();
mp.setType(point.getType());
if (point.getLabel() != null) {
mp.setName(point.getLabel().getText());
}
mp.setMaxResolution(res);
mp.setMinResolution(res);
mp.setLocation(point.getLocation());
overviewSource.addPoint(mp);
}
}
}
use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.
the class StyledConverter method checkDuplicatePOI.
/**
* Check if we already have added a point with the same type + name and equal location.
* @param mp
* @return
*/
private boolean checkDuplicatePOI(MapPoint mp) {
Map<String, MapPoint> typeMap = pointMap.get(mp.getType());
if (typeMap == null) {
typeMap = new HashMap<>();
pointMap.put(mp.getType(), typeMap);
}
MapPoint old = typeMap.get(mp.getName());
if (old == null) {
typeMap.put(mp.getName(), mp);
} else {
if (old.getLocation().equals(mp.getLocation()))
return true;
}
return false;
}
use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.
the class Locator method findNearbyCityByName.
public MapPoint findNearbyCityByName(MapPoint p) {
if (p.getCity() == null)
return null;
Collection<MapPoint> nextCityList = cityMap.get(p.getCity());
if (nextCityList.isEmpty()) {
return null;
}
MapPoint near = null;
double minDist = Double.MAX_VALUE;
for (MapPoint nextCity : nextCityList) {
double dist = p.getLocation().distance(nextCity.getLocation());
if (dist < minDist) {
minDist = dist;
near = nextCity;
}
}
if (// Wrong hit more the 30 km away ?
minDist <= MAX_CITY_DIST)
return near;
else
return null;
}
use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.
the class MapArea method addSize.
/**
* Add an estimate of the size that will be required to hold this element
* if it should be displayed at the given resolution. We also keep track
* of the number of <i>active</i> elements here ie elements that will be
* shown because they are at a resolution at least as great as the resolution
* of the area.
*
* @param el The element containing the minimum resolution that it will be
* displayed at.
* @param kind What kind of element this is KIND_POINT etc.
*/
private void addSize(MapElement el, int kind) {
int res = el.getMinResolution();
if (res > areaResolution || res > MAX_RESOLUTION)
return;
++splittableCount;
int numPoints;
int numElements;
switch(kind) {
case POINT_KIND:
case XT_POINT_KIND:
// Points are predictably less than 10 bytes.
sizes[kind] += 9;
if (!el.hasExtendedType()) {
if (((MapPoint) el).isCity())
nActiveIndPoints++;
else
nActivePoints++;
}
break;
case LINE_KIND:
case XT_LINE_KIND:
// Estimate the size taken by lines and shapes as a constant plus
// a factor based on the number of points.
numPoints = PredictFilterPoints.predictedMaxNumPoints(((MapLine) el).getPoints(), areaResolution, // assume MapBuilder.doRoads is true. subDiv.getZoom().getLevel() == 0 is maximum resolution
((MapLine) el).isRoad() && areaResolution == MAX_RESOLUTION);
if (numPoints <= 1 && !((MapLine) el).isRoad())
return;
numElements = 1 + ((numPoints - 1) / LineSplitterFilter.MAX_POINTS_IN_LINE);
// very pessimistic, typically less than 2 bytes are needed for one point
sizes[kind] += numElements * 11 + numPoints * 4;
if (!el.hasExtendedType())
nActiveLines += numElements;
break;
case SHAPE_KIND:
case XT_SHAPE_KIND:
// see canSplit() above
++splittableCount;
// Estimate the size taken by lines and shapes as a constant plus
// a factor based on the number of points.
numPoints = PredictFilterPoints.predictedMaxNumPoints(((MapShape) el).getPoints(), areaResolution, false);
if (numPoints <= 3)
return;
numElements = 1 + ((numPoints - 1) / PolygonSplitterFilter.MAX_POINT_IN_ELEMENT);
// very pessimistic, typically less than 2 bytes are needed for one point
sizes[kind] += numElements * 11 + numPoints * 4;
if (!el.hasExtendedType())
nActiveShapes += numElements;
break;
default:
log.error("should not be here");
assert false;
break;
}
}
Aggregations