use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class PrecompSeaMerger method convertToWays.
private List<Way> convertToWays(Area a, String naturalTag) {
List<List<Coord>> pointLists = Java2DConverter.areaToShapes(a);
List<Way> ways = new ArrayList<Way>(pointLists.size());
for (List<Coord> points : pointLists) {
Way w = new Way(FakeIdGenerator.makeFakeId(), points);
w.addTag("natural", naturalTag);
w.setClosedInOSM(true);
ways.add(w);
}
return ways;
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class OsmHandler method addCoordToWay.
/**
* Add a coordinate point to the way.
* @param way The Way.
* @param id The coordinate id.
*/
protected void addCoordToWay(Way way, long id) {
lastNodeRef = id;
if (firstNodeRef == 0)
firstNodeRef = id;
Coord co = saver.getCoord(id);
if (co != null) {
hooks.onCoordAddedToWay(way, id, co);
co = saver.getCoord(id);
way.addPoint(co);
} else {
missingNodeRef = true;
}
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class POIGeneratorHook method addPOItoLine.
private int addPOItoLine(Way line) {
Node startNode = createPOI(line, line.getPoints().get(0), LINE2POI_TAG);
startNode.addTag(LINE2POI_TYPE_TAG, "start");
saver.addNode(startNode);
Node endNode = createPOI(line, line.getPoints().get(line.getPoints().size() - 1), LINE2POI_TAG);
endNode.addTag(LINE2POI_TYPE_TAG, "end");
saver.addNode(endNode);
int noPOIs = 2;
Coord lastPoint = line.getPoints().get(0);
if (line.getPoints().size() > 2) {
for (Coord inPoint : line.getPoints().subList(1, line.getPoints().size() - 1)) {
if (inPoint.equals(lastPoint)) {
continue;
}
lastPoint = inPoint;
Node innerNode = createPOI(line, inPoint, LINE2POI_TAG);
innerNode.addTag(LINE2POI_TYPE_TAG, "inner");
saver.addNode(innerNode);
noPOIs++;
}
}
// calculate the middle of the line
Coord prevC = null;
double sumDist = 0.0;
ArrayList<Double> dists = new ArrayList<Double>(line.getPoints().size() - 1);
for (Coord c : line.getPoints()) {
if (prevC != null) {
double dist = prevC.distance(c);
dists.add(dist);
sumDist += dist;
}
prevC = c;
}
Coord midPoint = null;
double remMidDist = sumDist / 2;
for (int midPos = 0; midPos < dists.size(); midPos++) {
double nextDist = dists.get(midPos);
if (remMidDist <= nextDist) {
double frac = remMidDist / nextDist;
midPoint = line.getPoints().get(midPos).makeBetweenPoint(line.getPoints().get(midPos + 1), frac);
break;
}
remMidDist -= nextDist;
}
if (midPoint != null) {
Node midNode = createPOI(line, midPoint, LINE2POI_TAG);
midNode.addTag(LINE2POI_TYPE_TAG, "mid");
saver.addNode(midNode);
noPOIs++;
}
return noPOIs;
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class Way method getCofG.
/**
* calculate weighted centre of way, using high precision
* @return
*/
public Coord getCofG() {
int numPoints = points.size();
if (numPoints < 1)
return null;
double lat = 0;
double lon = 0;
if (hasIdenticalEndPoints())
numPoints--;
for (int i = 0; i < numPoints; i++) {
Coord p = points.get(i);
lat += (double) p.getHighPrecLat() / numPoints;
lon += (double) p.getHighPrecLon() / numPoints;
}
return Coord.makeHighPrecCoord((int) Math.round(lat), (int) Math.round(lon));
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class Way method clockwise.
// returns true if the way is a closed polygon with a clockwise
// direction
public static boolean clockwise(List<Coord> points) {
if (points.size() < 3 || !points.get(0).equals(points.get(points.size() - 1)))
return false;
if (points.get(0).highPrecEquals(points.get(points.size() - 1)) == false) {
log.error("Way.clockwise was called for way that is not closed in high precision");
}
long area = 0;
Coord p1 = points.get(0);
for (int i = 1; i < points.size(); ++i) {
Coord p2 = points.get(i);
area += ((long) p1.getHighPrecLon() * p2.getHighPrecLat() - (long) p2.getHighPrecLon() * p1.getHighPrecLat());
p1 = p2;
}
// empty linear areas are defined as clockwise
return area <= 0;
}
Aggregations