use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class RoadHelper method makeRoad.
public MapRoad makeRoad(MapLine l) {
assert roadId != 0;
if (log.isDebugEnabled())
log.debug("finishing road id " + roadId);
MapRoad road = new MapRoad(roadId, roadId, l);
// Set parameters.
road.setRoadClass(roadClass);
road.setSpeed(speed);
if (oneway)
road.setOneway();
if (toll)
road.setToll();
road.setAccess(mkgmapAccess);
if (numbers != null && !numbers.isEmpty()) {
convertNodesForHouseNumbers(road);
road.setNumbers(numbers);
}
List<Coord> points = road.getPoints();
for (NodeIndex ni : nodes) {
int n = ni.index;
if (log.isDebugEnabled())
log.debug("road has " + points.size() + " points");
Coord coord = points.get(n);
long id = coord.getId();
if (id == 0) {
CoordNode node = nodeCoords.get((long) ni.nodeId);
if (node == null) {
node = new CoordNode(coord, ni.nodeId, ni.boundary);
nodeCoords.put((long) ni.nodeId, node);
}
points.set(n, node);
} else if (id != ni.nodeId) {
log.warn("Inconsistant node ids");
}
}
return road;
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class BoundaryFile2Gpx method saveEmptyAreas.
/**
* Create gpx files for areas which contain no information for a given
* admin level.
* @param admLevel reasonable values are 2..11
*/
public void saveEmptyAreas(int admLevel) {
Area tileArea = Java2DConverter.createBoundsArea(BoundaryUtil.getBbox(boundaryFileName));
Area coveredArea = bqt.getCoveredArea(admLevel);
tileArea.subtract(coveredArea);
String levelId = "admin_level";
if (admLevel < 12)
levelId += admLevel;
else
levelId += "notset";
if (tileArea.isEmpty()) {
System.out.println(levelId + " is covered completely.");
} else {
String gpxBasename = "gpx/" + boundaryFileName + "/uncovered/" + levelId + "/";
List<List<Coord>> emptyPolys = Java2DConverter.areaToShapes(tileArea);
Collections.reverse(emptyPolys);
int i = 0;
for (List<Coord> emptyPart : emptyPolys) {
String attr = Way.clockwise(emptyPart) ? "o" : "i";
GpxCreator.createGpx(gpxBasename + i + "_" + attr, emptyPart);
i++;
}
}
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class BoundaryQuadTree method get.
/**
* Return location relevant Tags for the point defined by Coord
* @param co the point
* @return a reference to the internal Tags or null if the point was not found.
* The returned Tags must not be modified by the caller.
*/
public Tags get(Coord co) {
Tags res = root.get(co);
if (res == null && bbox.contains(co.getLongitude(), co.getLatitude())) {
// we did not find the point, probably it lies on a boundary and
// the clauses regarding insideness of areas make it "invisible"
// try again a few other nearby points
Coord neighbour1 = new Coord(co.getLatitude() - 1, co.getLongitude());
Coord neighbour2 = new Coord(co.getLatitude(), co.getLongitude() - 1);
Coord neighbour3 = new Coord(co.getLatitude() + 1, co.getLongitude());
Coord neighbour4 = new Coord(co.getLatitude(), co.getLongitude() + 1);
res = root.get(neighbour1);
if (res == null)
res = root.get(neighbour2);
if (res == null)
res = root.get(neighbour3);
if (res == null)
res = root.get(neighbour4);
}
return res;
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class BoundaryRelation method connectUnclosedWays.
protected boolean connectUnclosedWays(List<JoinedWay> allWays) {
List<JoinedWay> unclosed = new ArrayList<>();
for (JoinedWay w : allWays) {
if (w.hasIdenticalEndPoints() == false) {
unclosed.add(w);
}
}
// try to connect ways lying outside or on the bbox
if (unclosed.size() >= 2) {
log.debug("Checking", unclosed.size(), "unclosed ways for connections outside the bbox");
Map<Coord, JoinedWay> outOfBboxPoints = new IdentityHashMap<>();
// check all ways for endpoints outside or on the bbox
for (JoinedWay w : unclosed) {
Coord c1 = w.getPoints().get(0);
Coord c2 = w.getPoints().get(w.getPoints().size() - 1);
outOfBboxPoints.put(c1, w);
outOfBboxPoints.put(c2, w);
}
if (outOfBboxPoints.size() < 2) {
log.debug(outOfBboxPoints.size(), "point outside the bbox. No connection possible.");
return false;
}
List<ConnectionData> coordPairs = new ArrayList<>();
ArrayList<Coord> coords = new ArrayList<>(outOfBboxPoints.keySet());
for (int i = 0; i < coords.size(); i++) {
for (int j = i + 1; j < coords.size(); j++) {
ConnectionData cd = new ConnectionData();
cd.c1 = coords.get(i);
cd.c2 = coords.get(j);
cd.w1 = outOfBboxPoints.get(cd.c1);
cd.w2 = outOfBboxPoints.get(cd.c2);
cd.distance = cd.c1.distance(cd.c2);
coordPairs.add(cd);
}
}
if (coordPairs.isEmpty()) {
log.debug("All potential connections cross the bbox. No connection possible.");
return false;
} else {
// retrieve the connection with the minimum distance
ConnectionData minCon = Collections.min(coordPairs, new Comparator<ConnectionData>() {
public int compare(ConnectionData o1, ConnectionData o2) {
return Double.compare(o1.distance, o2.distance);
}
});
if (minCon.distance < getMaxCloseDist()) {
if (minCon.w1 == minCon.w2) {
log.debug("Close a gap in way", minCon.w1);
if (minCon.imC != null)
minCon.w1.getPoints().add(minCon.imC);
minCon.w1.closeWayArtificially();
} else {
log.debug("Connect", minCon.w1, "with", minCon.w2);
if (minCon.w1.getPoints().get(0) == minCon.c1) {
Collections.reverse(minCon.w1.getPoints());
}
if (minCon.w2.getPoints().get(0) != minCon.c2) {
Collections.reverse(minCon.w2.getPoints());
}
minCon.w1.getPoints().addAll(minCon.w2.getPoints());
minCon.w1.addWay(minCon.w2);
allWays.remove(minCon.w2);
}
return true;
}
}
}
return false;
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class LinkDestinationHook method retrieveWays.
/**
* Fills the internal lists
*/
private void retrieveWays() {
// collect all ways tagged with highway
for (Way w : saver.getWays().values()) {
if (w.getPoints().size() < 2) {
// ignore one-node or zero-node ways
continue;
}
String highwayTag = w.getTag("highway");
if (highwayTag != null && highwayTypes.contains(highwayTag)) {
// the points of the way are kept so that it is easy to get
// the adjacent ways for a given _link way
String directedDestination = null;
String directedDestinationLanes = null;
String directionSuffix = null;
List<Coord> points;
if (isOnewayInDirection(w)) {
// oneway => don't need the last point because the
// way cannot be driven standing at the last point
points = w.getPoints().subList(0, w.getPoints().size() - 1);
directedDestination = w.getTag("destination:forward");
directedDestinationLanes = w.getTag("destination:lanes:forward");
directionSuffix = "forward";
} else if (isOnewayOppositeDirection(w)) {
// reverse oneway => don't need the first point because the
// way cannot be driven standing at the first point
points = w.getPoints().subList(1, w.getPoints().size());
directedDestination = w.getTag("destination:backward");
directedDestinationLanes = w.getTag("destination:lanes:backward");
directionSuffix = "backward";
} else {
points = w.getPoints();
}
for (Coord c : points) {
Set<Way> ways = adjacentWays.get(c);
if (ways == null) {
ways = new HashSet<Way>(4);
adjacentWays.put(c, ways);
}
ways.add(w);
}
registerPointsOfWay(w);
// put it the list of ways that have to be processed
if (linkTypes.contains(highwayTag)) {
String destSourceTagKey = "destination";
String destinationTag = w.getTag("destination");
if (destinationTag == null) {
// destination is not set
// => check if destination:lanes is without any lane specific information (no |)
destSourceTagKey = "destination:lanes";
String destLanesTag = w.getTag(destSourceTagKey);
if (destLanesTag == null && directedDestinationLanes != null) {
destLanesTag = directedDestinationLanes;
destSourceTagKey += ":" + directionSuffix;
}
if (destLanesTag != null && destLanesTag.contains("|") == false) {
// the destination:lanes tag contains no | => no lane specific information
// use this tag as destination tag
destinationTag = destLanesTag;
}
if (destinationTag == null && directedDestination != null) {
// use the destination:forward or :backward value
destinationTag = directedDestination;
destSourceTagKey = "destination:" + directionSuffix;
}
if (destinationTag == null) {
// try to use the destination:street value
destSourceTagKey = "destination:street";
destinationTag = w.getTag(destSourceTagKey);
}
}
if (destinationTag != null) {
w.addTag("mkgmap:dest_hint_work", destinationTag);
if ("destination".equals(destSourceTagKey) == false) {
if (log.isDebugEnabled()) {
if (destSourceTagKey.startsWith("destination:lanes"))
log.debug("Use", destSourceTagKey, "as destination tag because there is one lane information only. Way ", w.getId(), w.toTagString());
else
log.debug("Use", destSourceTagKey, "as destination tag. Way ", w.getId(), w.toTagString());
}
}
destinationLinkWays.put(w.getId(), w);
}
}
}
}
// eventually they must be modified if one of its ways is split
for (Relation rel : saver.getRelations().values()) {
if (rel instanceof RestrictionRelation) {
RestrictionRelation rrel = (RestrictionRelation) rel;
for (Long wayId : rrel.getWayIds()) restrictions.add(wayId, rrel);
}
}
}
Aggregations