Search in sources :

Example 31 with Coord

use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.

the class O5mBinHandler method readRel.

/**
 * read a relation data set
 * @throws IOException
 */
private void readRel() throws IOException {
    lastRelId += readSignedNum64();
    if (bytesToRead == 0)
        // only relId: this is a delete action, we ignore it
        return;
    readVersionTsAuthor();
    if (bytesToRead == 0)
        // only relId + version: this is a delete action, we ignore it
        return;
    GeneralRelation rel = new GeneralRelation(lastRelId);
    long refSize = readUnsignedNum32();
    long stop = bytesToRead - refSize;
    while (bytesToRead > stop) {
        Element el = null;
        long deltaRef = readSignedNum64();
        int refType = readRelRef();
        String role = stringPair[1];
        lastRef[refType] += deltaRef;
        long memId = lastRef[refType];
        if (refType == 0) {
            el = saver.getNode(memId);
            if (el == null) {
                // we didn't make a node for this point earlier,
                // do it now (if it exists)
                Coord co = saver.getCoord(memId);
                if (co != null) {
                    el = new Node(memId, co);
                    saver.addNode((Node) el);
                }
            }
        } else if (refType == 1) {
            el = saver.getWay(memId);
        } else if (refType == 2) {
            el = saver.getRelation(memId);
            if (el == null) {
                saver.deferRelation(memId, rel, role);
            }
        } else {
            assert false;
        }
        if (// ignore non existing ways caused by splitting files
        el != null)
            rel.addElement(role, el);
    }
    boolean tagsIncomplete = readTags(rel);
    rel.setTagsIncomplete(tagsIncomplete);
    saver.addRelation(rel);
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) Element(uk.me.parabola.mkgmap.reader.osm.Element) Node(uk.me.parabola.mkgmap.reader.osm.Node)

Example 32 with Coord

use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.

the class PolishMapDataSource method coordsFromString.

private List<Coord> coordsFromString(String value) {
    String[] ords = value.split("\\) *, *\\(");
    List<Coord> points = new ArrayList<>();
    for (String s : ords) {
        Coord co = makeCoord(s);
        if (log.isDebugEnabled())
            log.debug(" L: ", co);
        mapper.addToBounds(co);
        points.add(co);
    }
    log.debug(points.size() + " points from " + value);
    return points;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) ArrayList(java.util.ArrayList)

Example 33 with Coord

use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.

the class PolishMapDataSource method endSection.

/**
 * At the end of a section, we add what ever element that we have been
 * building to the map.
 */
private void endSection() {
    switch(section) {
        case S_IMG_ID:
            break;
        case S_POINT:
            if (extraAttributes != null && point.hasExtendedType())
                point.setExtTypeAttributes(makeExtTypeAttributes());
            mapper.addToBounds(point.getLocation());
            mapper.addPoint(point);
            break;
        case S_POLYLINE:
            if (points != null) {
                if (roadHelper.isRoad()) {
                    polyline.setPoints(points);
                    mapper.addRoad(roadHelper.makeRoad(polyline));
                } else {
                    if (extraAttributes != null && polyline.hasExtendedType())
                        polyline.setExtTypeAttributes(makeExtTypeAttributes());
                    final int maxPointsInLine = LineSplitterFilter.MAX_POINTS_IN_LINE;
                    if (points.size() > maxPointsInLine) {
                        List<Coord> segPoints = new ArrayList<>(maxPointsInLine);
                        for (Coord p : points) {
                            segPoints.add(p);
                            if (segPoints.size() == maxPointsInLine) {
                                MapLine seg = polyline.copy();
                                seg.setPoints(segPoints);
                                mapper.addLine(seg);
                                segPoints = new ArrayList<>(maxPointsInLine);
                                segPoints.add(p);
                            }
                        }
                        if (!segPoints.isEmpty()) {
                            polyline.setPoints(segPoints);
                            mapper.addLine(polyline);
                        }
                    } else {
                        polyline.setPoints(points);
                        mapper.addLine(polyline);
                    }
                }
            }
            break;
        case S_POLYGON:
            if (points != null) {
                if (points.get(0) != points.get(points.size() - 1)) {
                    // not closed, close it
                    points.add(points.get(0));
                }
                shape.setPoints(points);
                if (extraAttributes != null && shape.hasExtendedType())
                    shape.setExtTypeAttributes(makeExtTypeAttributes());
                mapper.addShape(shape);
            }
            break;
        case S_RESTRICTION:
            restrictionHelper.addRestriction(restriction);
            break;
        case 0:
            // ignored section
            break;
        default:
            log.warn("unexpected default in switch", section);
            break;
    }
    // Clear the section state.
    section = 0;
    endLevel = 0;
    points = null;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapLine(uk.me.parabola.mkgmap.general.MapLine) ArrayList(java.util.ArrayList) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 34 with Coord

use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.

the class PolishMapDataSource method makeCoord.

/**
 * Create a coordinate from a string.  The string will look similar:
 * (2.3454,-0.23), but may not have the leading opening parenthesis.
 * @param value A string representing a lat,long pair.
 * @return The coordinate value.
 */
private Coord makeCoord(String value) {
    String[] fields = value.split("[(,)]");
    int i = 0;
    if (fields[0].isEmpty())
        i = 1;
    Double f1 = Double.valueOf(fields[i]);
    Double f2 = Double.valueOf(fields[i + 1]);
    Coord co = new Coord(f1, f2);
    long key = Utils.coord2Long(co);
    Coord co2 = coordMap.get(key);
    if (co2 != null)
        return co2;
    coordMap.put(key, co);
    return co;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 35 with Coord

use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.

the class PolishMapDataSource method point.

/**
 * This is called for every line within the POI section.  The lines are
 * key value pairs that have already been decoded into name and value.
 * For each name we recognise we set the appropriate property on
 * the <i>point</i>.
 *
 * @param name Parameter name.
 * @param value Its value.
 */
private void point(String name, String value) {
    if (name.equals("Type")) {
        int type = Integer.decode(value);
        point.setType(type);
    } else if (name.equals("SubType")) {
        int subtype = Integer.decode(value);
        int type = point.getType();
        if (type <= 0xff)
            point.setType((type << 8) | subtype);
    } else if (name.startsWith("Data") || name.startsWith("Origin")) {
        Coord co = makeCoord(value);
        setResolution(point, name);
        point.setLocation(co);
    } else {
        if (extraAttributes == null)
            extraAttributes = new HashMap<>();
        extraAttributes.put(name, value);
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) HashMap(java.util.HashMap) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

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