use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.
the class MapBuilder method processPOIs.
private void processPOIs(Map map, MapDataSource src) {
LBLFile lbl = map.getLblFile();
boolean checkedForPoiDispFlag = false;
for (MapPoint p : src.getPoints()) {
// special handling for highway exits
if (p.isExit()) {
processExit(map, (MapExitPoint) p);
} else // * all POIs except roads in case the no-poi-address option is set
if (!p.isCity() && !p.hasExtendedType() && poiAddresses) {
String countryStr = p.getCountry();
String regionStr = p.getRegion();
String zipStr = p.getZip();
String cityStr = p.getCity();
if (locationAutofill.contains("nearest") && (countryStr == null || regionStr == null || (zipStr == null && cityStr == null))) {
MapPoint nextCity = locator.findNearbyCityByName(p);
if (nextCity == null)
nextCity = locator.findNextPoint(p);
if (nextCity != null) {
if (countryStr == null)
countryStr = nextCity.getCountry();
if (regionStr == null)
regionStr = nextCity.getRegion();
if (zipStr == null) {
String cityZipStr = nextCity.getZip();
if (cityZipStr != null && cityZipStr.indexOf(',') < 0)
zipStr = cityZipStr;
}
if (cityStr == null)
cityStr = nextCity.getCity();
}
}
if (countryStr != null && !checkedForPoiDispFlag) {
// Different countries require different address notation
poiDisplayFlags = locator.getPOIDispFlag(countryStr);
checkedForPoiDispFlag = true;
}
POIRecord r = lbl.createPOI(p.getName());
if (cityStr != null || regionStr != null || countryStr != null) {
r.setCity(calcCity(lbl, cityStr, regionStr, countryStr));
}
if (zipStr != null) {
Zip zip = lbl.createZip(zipStr);
r.setZip(zip);
}
if (p.getStreet() != null) {
Label streetName = lbl.newLabel(p.getStreet());
r.setStreetName(streetName);
}
String houseNumber = p.getHouseNumber();
if (houseNumber != null && !houseNumber.isEmpty()) {
if (!r.setSimpleStreetNumber(houseNumber))
r.setComplexStreetNumber(lbl.newLabel(houseNumber));
}
String phone = p.getPhone();
if (phone != null && !phone.isEmpty()) {
if (!r.setSimplePhoneNumber(phone))
r.setComplexPhoneNumber(lbl.newLabel(phone));
}
poimap.put(p, r);
}
}
lbl.allPOIsDone();
}
use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.
the class MapBuilder method processPoints.
/**
* Step through the points, filter and create a map point 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 points belong to.
* @param points The points to be added.
*/
private void processPoints(Map map, Subdivision div, List<MapPoint> points) {
LBLFile lbl = map.getLblFile();
div.startPoints();
int res = div.getResolution();
boolean haveIndPoints = false;
int pointIndex = 1;
// points (not 1)
for (MapPoint point : points) {
if (point.isCity() && point.getMinResolution() <= res) {
++pointIndex;
haveIndPoints = true;
}
}
for (MapPoint point : points) {
if (point.isCity() || point.getMinResolution() > res)
continue;
String name = point.getName();
Point p = div.createPoint(name);
p.setType(point.getType());
if (point.hasExtendedType()) {
ExtTypeAttributes eta = point.getExtTypeAttributes();
if (eta != null) {
eta.processLabels(lbl);
p.setExtTypeAttributes(eta);
}
}
Coord coord = point.getLocation();
try {
p.setLatitude(coord.getLatitude());
p.setLongitude(coord.getLongitude());
} catch (AssertionError ae) {
log.error("Problem with point of type 0x" + Integer.toHexString(point.getType()) + " at " + coord.toOSMURL());
log.error(" Subdivision shift is " + div.getShift() + " and its centre is at " + div.getCenter().toOSMURL());
log.error(" " + ae.getMessage());
continue;
}
POIRecord r = poimap.get(point);
if (r != null)
p.setPOIRecord(r);
map.addMapObject(p);
if (!point.hasExtendedType()) {
if (name != null && div.getZoom().getLevel() == 0) {
if (pointIndex > 255)
log.error("Too many POIs at location " + div.getCenter().toOSMURL() + " - " + name + " will be ignored");
else if (point.isExit()) {
Exit e = ((MapExitPoint) point).getExit();
if (e != null)
e.getHighway().addExitPoint(name, pointIndex, div);
} else if (makePOIIndex)
lbl.createPOIIndex(name, pointIndex, div, point.getType());
}
++pointIndex;
}
}
if (haveIndPoints) {
div.startIndPoints();
// reset to 1
pointIndex = 1;
for (MapPoint point : points) {
if (!point.isCity() || point.getMinResolution() > res)
continue;
String name = point.getName();
Point p = div.createPoint(name);
p.setType(point.getType());
Coord coord = point.getLocation();
try {
p.setLatitude(coord.getLatitude());
p.setLongitude(coord.getLongitude());
} catch (AssertionError ae) {
log.error("Problem with point of type 0x" + Integer.toHexString(point.getType()) + " at " + coord.toOSMURL());
log.error(" Subdivision shift is " + div.getShift() + " and its centre is at " + div.getCenter().toOSMURL());
log.error(" " + ae.getMessage());
continue;
}
map.addMapObject(p);
if (name != null && div.getZoom().getLevel() == 0) {
// retrieve the City created earlier for this
// point and store the point info in it
City c = cityMap.get(point);
if (pointIndex > 255) {
System.err.println("Can't set city point index for " + name + " (too many indexed points in division)\n");
} else {
c.setPointIndex((byte) pointIndex);
c.setSubdivision(div);
}
}
++pointIndex;
}
}
}
use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.
the class PolishMapDataSource method sectionStart.
/**
* Record that we are starting a new section.
* Section names are enclosed in square brackets. Inside the section there
* are a number of lines with the key=value format.
*
* @param line The raw line from the input file.
*/
private void sectionStart(String line) {
String name = line.substring(1, line.length() - 1).trim();
log.debug("section name", name);
extraAttributes = null;
if (name.equalsIgnoreCase("IMG ID")) {
section = S_IMG_ID;
} else if (name.equalsIgnoreCase("POI") || name.equals("RGN10") || name.equals("RGN20")) {
point = new MapPoint();
section = S_POINT;
} else if (name.equalsIgnoreCase("POLYLINE") || name.equals("RGN40")) {
polyline = new MapLine();
roadHelper.clear();
section = S_POLYLINE;
} else if (name.equalsIgnoreCase("POLYGON") || name.equals("RGN80")) {
shape = new MapShape();
section = S_POLYGON;
} else if (name.equalsIgnoreCase("Restrict")) {
restriction = new PolishTurnRestriction();
section = S_RESTRICTION;
} else
System.out.println("Ignoring unrecognised section: " + name);
}
use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.
the class TestPoints method drawTestMap.
/**
* We draw points, lines and polygons separately. They should be in
* order from west to east of the generated map, starting in the bottom
* left hand corner (SW).
*
* @param mapper Collector for the generated points etc.
* @param startLat The S coord.
* @param startLong The W coord.
*/
private void drawTestMap(MapCollector mapper, double startLat, double startLong) {
String s = props.getProperty("npoints");
int npoints = 10;
if (s != null)
npoints = Integer.valueOf(s);
for (int x = 0; x < npoints; x++) {
for (int y = 0; y < npoints; y++) {
MapPoint point = new MapPoint();
double baseLat = startLat + y * ELEMENT_SPACING;
double baseLong = startLong + x * ELEMENT_SPACING;
point.setMinResolution(24 - (x & 0x7));
point.setName("P " + (x * npoints + y));
point.setLocation(new Coord(baseLat, baseLong));
point.setType((0x2c << 8) + (y & 0xf));
mapper.addPoint(point);
// XXX shouldn't be needed.
mapper.addToBounds(point.getLocation());
}
}
// some.
for (int x = 0; x < npoints; x++) {
for (int y = 0; y < npoints; y++) {
int type = x * 16 + y;
type &= 0xf;
MapLine line = new MapLine();
line.setMinResolution(10);
line.setName("0x" + Integer.toHexString(type));
double baseLat = startLat + y * ELEMENT_SPACING;
double baseLong = startLong + x * ELEMENT_SPACING;
List<Coord> coords = new ArrayList<Coord>();
for (int i = 0; i < 5; i++) {
Coord co = new Coord(baseLat + i * ELEMENT_SIZE, baseLong + i * ELEMENT_SIZE);
coords.add(co);
mapper.addToBounds(co);
}
line.setType(type);
line.setPoints(coords);
mapper.addLine(line);
}
}
}
use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.
the class KdTreeTest method TestFindNextPoint.
@Test
public void TestFindNextPoint() {
KdTree<MapPoint> t = new KdTree<>();
int[][] test = { { 70, 20 }, { 50, 40 }, { 90, 60 }, { 20, 30 }, { 40, 70 }, { 80, 10 }, { -10, 20 }, { -30, -40 } };
Coord[] testCoords = new Coord[test.length];
for (int i = 0; i < test.length; i++) {
MapPoint p = new MapPoint();
testCoords[i] = new Coord(test[i][0], test[i][1]);
p.setLocation(testCoords[i]);
t.add(p);
}
// compare naive search result with kd--tree result
MapPoint toFind = new MapPoint();
for (int x = -100; x < 100; x++) {
for (int y = -100; y < 100; y++) {
Coord co = new Coord(x, y);
double minDist = Double.MAX_VALUE;
for (int i = 0; i < testCoords.length; i++) {
Double dist = testCoords[i].distanceInDegreesSquared(co);
if (dist < minDist) {
minDist = dist;
}
}
toFind.setLocation(co);
MapPoint next = (MapPoint) t.findNextPoint(toFind);
double dist = next.getLocation().distanceInDegreesSquared(co);
double delta = Math.abs(dist - minDist);
// if this test fails because
assertFalse("delta should be 0.0: " + delta, delta != 0.0);
}
}
}
Aggregations