use of uk.me.parabola.mkgmap.general.MapLine in project mkgmap by openstreetmap.
the class MapBuilder method normalizeCountries.
/**
* Process the country names of all elements and normalize them
* so that one consistent country name is used for the same country
* instead of different spellings.
* @param src the source of elements
*/
private void normalizeCountries(MapDataSource src) {
for (MapPoint p : src.getPoints()) {
String countryStr = p.getCountry();
if (countryStr != null) {
countryStr = locator.normalizeCountry(countryStr);
p.setCountry(countryStr);
}
}
for (MapLine l : src.getLines()) {
String countryStr = l.getCountry();
if (countryStr != null) {
countryStr = locator.normalizeCountry(countryStr);
l.setCountry(countryStr);
}
}
// shapes do not have address information
// untag the following lines if this is wrong
// for (MapShape s : src.getShapes()) {
// String countryStr = s.getCountry();
// if (countryStr != null) {
// countryStr = locator.normalizeCountry(countryStr);
// s.setCountry(countryStr);
// }
// }
}
use of uk.me.parabola.mkgmap.general.MapLine in project mkgmap by openstreetmap.
the class MapBuilder method makeSubdivision.
/**
* Make an individual subdivision for the map. To do this we need a link
* to its parent and the zoom level that we are working at.
*
* @param map The map to add this subdivision into.
* @param parent The parent division.
* @param ma The area of the map that we are fitting into this division.
* @param z The zoom level.
* @return The new subdivsion.
*/
private Subdivision makeSubdivision(Map map, Subdivision parent, MapArea ma, Zoom z) {
List<MapPoint> points = ma.getPoints();
List<MapLine> lines = ma.getLines();
List<MapShape> shapes = ma.getShapes();
Subdivision div = map.createSubdivision(parent, ma.getFullBounds(), z);
if (ma.hasPoints())
div.setHasPoints(true);
if (ma.hasIndPoints())
div.setHasIndPoints(true);
if (ma.hasLines())
div.setHasPolylines(true);
if (ma.hasShapes())
div.setHasPolygons(true);
div.startDivision();
processPoints(map, div, points);
processLines(map, div, lines);
processShapes(map, div, shapes);
div.endDivision();
return div;
}
use of uk.me.parabola.mkgmap.general.MapLine in project mkgmap by openstreetmap.
the class MapBuilder method processLines.
/**
* Step through the lines, filter, simplify if necessary, and create a map
* line which is then added to the map.
*
* Note that the location and resolution of map elements is relative to the
* subdivision that they occur in.
*
* @param map The map to add points to.
* @param div The subdivision that the lines belong to.
* @param lines The lines to be added.
*/
private void processLines(Map map, Subdivision div, List<MapLine> lines) {
// Signal that we are beginning to draw the lines.
div.startLines();
int res = div.getResolution();
FilterConfig config = new FilterConfig();
config.setResolution(res);
config.setLevel(div.getZoom().getLevel());
config.setRoutable(doRoads);
// Maybe more efficient if merging before creating subdivisions.
if (mergeLines) {
LineMergeFilter merger = new LineMergeFilter();
lines = merger.merge(lines, res);
}
LayerFilterChain filters = new LayerFilterChain(config);
if (enableLineCleanFilters && (res < 24)) {
filters.addFilter(new RoundCoordsFilter());
filters.addFilter(new SizeFilter(MIN_SIZE_LINE));
if (reducePointError > 0)
filters.addFilter(new DouglasPeuckerFilter(reducePointError));
}
filters.addFilter(new LineSplitterFilter());
filters.addFilter(new RemoveEmpty());
filters.addFilter(new RemoveObsoletePointsFilter());
filters.addFilter(new LinePreparerFilter(div));
filters.addFilter(new LineAddFilter(div, map, doRoads));
for (MapLine line : lines) {
if (line.getMinResolution() > res)
continue;
filters.startFilter(line);
}
}
use of uk.me.parabola.mkgmap.general.MapLine 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.MapLine in project mkgmap by openstreetmap.
the class RemoveObsoletePointsFilter method doFilter.
/**
* @param element A map element that will be a line or a polygon.
* @param next This is used to pass the possibly transformed element onward.
*/
public void doFilter(MapElement element, MapFilterChain next) {
MapLine line = (MapLine) element;
List<Coord> points = line.getPoints();
int numPoints = points.size();
if (numPoints <= 1) {
return;
}
int requiredPoints = (line instanceof MapShape) ? 4 : 2;
List<Coord> newPoints = new ArrayList<Coord>(numPoints);
while (true) {
boolean removedSpike = false;
numPoints = points.size();
Coord lastP = points.get(0);
newPoints.add(lastP);
for (int i = 1; i < numPoints; i++) {
Coord newP = points.get(i);
int last = newPoints.size() - 1;
lastP = newPoints.get(last);
if (lastP.equals(newP)) {
// coordinates to the last point or is preserved
if (checkPreserved && line.isRoad()) {
if (newP.preserved() == false)
continue;
else if (lastP.preserved() == false) {
// replace last
newPoints.set(last, newP);
}
} else
continue;
}
if (newPoints.size() > 1) {
switch(Utils.isStraight(newPoints.get(last - 1), lastP, newP)) {
case Utils.STRICTLY_STRAIGHT:
if (checkPreserved && lastP.preserved() && line.isRoad()) {
// keep it
} else {
log.debug("found three consecutive points on strictly straight line");
newPoints.set(last, newP);
continue;
}
break;
case Utils.STRAIGHT_SPIKE:
if (line instanceof MapShape) {
log.debug("removing spike");
newPoints.remove(last);
removedSpike = true;
if (newPoints.get(last - 1).equals(newP))
continue;
}
break;
default:
break;
}
}
newPoints.add(newP);
}
if (!removedSpike || newPoints.size() < requiredPoints)
break;
points = newPoints;
newPoints = new ArrayList<Coord>(points.size());
}
if (line instanceof MapShape) {
// in a shape are identical.
while (newPoints.size() > 3) {
int nPoints = newPoints.size();
switch(Utils.isStraight(newPoints.get(newPoints.size() - 2), newPoints.get(0), newPoints.get(1))) {
case Utils.STRAIGHT_SPIKE:
newPoints.remove(0);
newPoints.set(newPoints.size() - 1, newPoints.get(0));
if (newPoints.get(newPoints.size() - 2).equals(newPoints.get(newPoints.size() - 1)))
newPoints.remove(newPoints.size() - 1);
break;
case Utils.STRICTLY_STRAIGHT:
newPoints.remove(newPoints.size() - 1);
newPoints.set(0, newPoints.get(newPoints.size() - 1));
break;
}
if (nPoints == newPoints.size())
break;
}
}
if (newPoints.size() != line.getPoints().size()) {
if (line instanceof MapShape && newPoints.size() <= 3 || newPoints.size() <= 1)
return;
MapLine newLine = line.copy();
newLine.setPoints(newPoints);
next.doFilter(newLine);
} else {
// no need to create new object
next.doFilter(line);
}
}
Aggregations