Search in sources :

Example 56 with Coord

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;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Way(uk.me.parabola.mkgmap.reader.osm.Way)

Example 57 with Coord

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;
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord)

Example 58 with Coord

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;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) ArrayList(java.util.ArrayList)

Example 59 with Coord

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));
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord)

Example 60 with Coord

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;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord)

Aggregations

Coord (uk.me.parabola.imgfmt.app.Coord)178 ArrayList (java.util.ArrayList)71 Way (uk.me.parabola.mkgmap.reader.osm.Way)31 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)27 List (java.util.List)23 MapLine (uk.me.parabola.mkgmap.general.MapLine)16 Area (uk.me.parabola.imgfmt.app.Area)15 MapShape (uk.me.parabola.mkgmap.general.MapShape)15 CoordNode (uk.me.parabola.imgfmt.app.CoordNode)13 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)13 Node (uk.me.parabola.mkgmap.reader.osm.Node)13 HashMap (java.util.HashMap)12 IdentityHashMap (java.util.IdentityHashMap)11 Test (org.junit.Test)11 MapRoad (uk.me.parabola.mkgmap.general.MapRoad)9 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)8 Area (java.awt.geom.Area)8 HashSet (java.util.HashSet)8 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5