Search in sources :

Example 1 with Tags

use of uk.me.parabola.mkgmap.reader.osm.Tags in project mkgmap by openstreetmap.

the class StyledConverter method parseStyleOption.

/**
 * Handle style option parameter. Create tags which are added to each element
 * before style processing starts. Cross-check usage of the options with the style.
 * @param styleOption the user option
 * @return Tags instance created from the option.
 */
private Tags parseStyleOption(String styleOption) {
    Tags styleTags = new Tags();
    if (styleOption != null) {
        // expected: --style-option=car;farms=more;admin5=10
        String[] tags = styleOption.split(";");
        for (String t : tags) {
            String[] pair = t.split("=");
            String optionKey = pair[0];
            String tagKey = STYLE_OPTION_PREF + optionKey;
            if (!style.getUsedTags().contains(tagKey)) {
                System.err.println("Warning: Option style-options sets tag not used in style: '" + optionKey + "' (gives " + tagKey + ")");
            } else {
                String val = (pair.length == 1) ? "true" : pair[1];
                String old = styleTags.put(tagKey, val);
                if (old != null)
                    log.error("duplicate tag key", optionKey, "in style option", styleOption);
            }
        }
    }
    // flag options used in style but not specified in --style-option
    if (style.getUsedTags() != null) {
        for (String s : style.getUsedTags()) {
            if (s != null && s.startsWith(STYLE_OPTION_PREF)) {
                if (styleTags.get(s) == null) {
                    System.err.println("Warning: Option style-options doesn't specify '" + s.replaceFirst(STYLE_OPTION_PREF, "") + "' (for " + s + ")");
                }
            }
        }
    }
    return styleTags;
}
Also used : Tags(uk.me.parabola.mkgmap.reader.osm.Tags)

Example 2 with Tags

use of uk.me.parabola.mkgmap.reader.osm.Tags in project mkgmap by openstreetmap.

the class BoundaryUtil method mergePostalCodes.

/**
 * Merges boundaries with the same postal code.
 * @param boundaries a list of boundaries
 * @return the boundary list with postal code areas merged
 */
private static List<Boundary> mergePostalCodes(List<Boundary> boundaries) {
    List<Boundary> mergedList = new ArrayList<>(boundaries.size());
    MultiHashMap<String, Boundary> equalPostalCodes = new MultiHashMap<>();
    for (Boundary boundary : boundaries) {
        String postalCode = getPostalCode(boundary.getTags());
        if (postalCode == null) {
            // no postal code boundary
            mergedList.add(boundary);
        } else {
            // postal code boundary => merge it later
            equalPostalCodes.add(postalCode, boundary);
        }
    }
    for (Entry<String, List<Boundary>> postCodeBoundary : equalPostalCodes.entrySet()) {
        if (postCodeBoundary.getValue().size() == 1) {
            // nothing to merge
            mergedList.addAll(postCodeBoundary.getValue());
            continue;
        }
        // there are more than 2 boundaries with the same post code
        // => merge them
        Area newPostCodeArea = new Area();
        for (Boundary b : postCodeBoundary.getValue()) {
            newPostCodeArea.add(b.getArea());
            // remove the post code tags from the original boundary
            if (b.getTags().get("postal_code") != null) {
                b.getTags().remove("postal_code");
            } else if ("postal_code".equals(b.getTags().get("boundary"))) {
                b.getTags().remove("boundary");
                b.getTags().remove("name");
            }
            // check if the boundary contains other boundary information
            if (isAdministrativeBoundary(b)) {
                mergedList.add(b);
            } else {
                log.info("Boundary", b.getId(), b.getTags(), "contains no more boundary tags. Skipping it.");
            }
        }
        Tags postalCodeTags = new Tags();
        postalCodeTags.put("postal_code", postCodeBoundary.getKey());
        Boundary postalCodeBoundary = new Boundary(newPostCodeArea, postalCodeTags, "p" + postCodeBoundary.getKey());
        log.info("Merged", postCodeBoundary.getValue().size(), "postal code boundaries for postal code", postCodeBoundary.getKey());
        mergedList.add(postalCodeBoundary);
    }
    return mergedList;
}
Also used : Area(java.awt.geom.Area) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MultiHashMap(uk.me.parabola.util.MultiHashMap) Tags(uk.me.parabola.mkgmap.reader.osm.Tags)

Example 3 with Tags

use of uk.me.parabola.mkgmap.reader.osm.Tags in project mkgmap by openstreetmap.

the class BoundaryUtil method readStreamRawFormat.

/**
 * Read boundary info saved in RAW_DATA_FORMAT
 * (written by 1st pass of preparer)
 * @param inpStream the already opened DataInputStream
 * @param fname the related file name of the *.bnd file
 * @param bbox a bounding box. Data outside of this box is ignored.
 * @return
 * @throws IOException
 */
private static List<Boundary> readStreamRawFormat(DataInputStream inpStream, String fname, uk.me.parabola.imgfmt.app.Area bbox) throws IOException {
    List<Boundary> boundaryList = new ArrayList<>();
    try {
        while (true) {
            int minLat = inpStream.readInt();
            int minLong = inpStream.readInt();
            int maxLat = inpStream.readInt();
            int maxLong = inpStream.readInt();
            if (log.isDebugEnabled())
                log.debug("Next boundary. Lat min:", minLat, "max:", maxLat, "Long min:", minLong, "max:", maxLong);
            uk.me.parabola.imgfmt.app.Area rBbox = new uk.me.parabola.imgfmt.app.Area(minLat, minLong, maxLat, maxLong);
            int bSize = inpStream.readInt();
            log.debug("Size:", bSize);
            if (bbox == null || bbox.intersects(rBbox)) {
                log.debug("Bbox intersects. Load the boundary");
                String id = inpStream.readUTF();
                Tags tags = new Tags();
                int noOfTags = inpStream.readInt();
                for (int i = 0; i < noOfTags; i++) {
                    String name = inpStream.readUTF();
                    String value = inpStream.readUTF();
                    tags.put(name, value.intern());
                }
                Area area = readAreaAsPath(inpStream);
                if (area != null) {
                    Boundary boundary = new Boundary(area, tags, id);
                    boundaryList.add(boundary);
                } else {
                    log.warn("Boundary " + tags + " does not contain any valid area in file " + fname);
                }
            } else {
                log.debug("Bbox does not intersect. Skip", bSize);
                inpStream.skipBytes(bSize);
            }
        }
    } catch (EOFException exp) {
    // it's always thrown at the end of the file
    // log.error("Got EOF at the end of the file");
    }
    return boundaryList;
}
Also used : ArrayList(java.util.ArrayList) Area(java.awt.geom.Area) EOFException(java.io.EOFException) Tags(uk.me.parabola.mkgmap.reader.osm.Tags)

Example 4 with Tags

use of uk.me.parabola.mkgmap.reader.osm.Tags in project mkgmap by openstreetmap.

the class BoundaryFile2Gpx method saveAsGpx.

/**
 * create gpx files for all boundaries contained in one *.bnd file
 */
public void saveAsGpx() {
    System.out.println("Start converting " + boundaryFileName);
    Map<String, Tags> bTags = bqt.getTagsMap();
    Map<String, List<Area>> areas = bqt.getAreas();
    // verify data: remove boundary ids that have no related areas
    Iterator<Entry<String, Tags>> tagIter = bTags.entrySet().iterator();
    while (tagIter.hasNext()) {
        Entry<String, Tags> entry = tagIter.next();
        List<Area> aList = areas.get(entry.getKey());
        if (aList == null || aList.isEmpty()) {
            System.err.println("no area info for " + entry.getKey());
            tagIter.remove();
            continue;
        }
    }
    for (int adminlevel = 2; adminlevel < 12; adminlevel++) {
        boolean found = false;
        for (Entry<String, Tags> entry : bTags.entrySet()) {
            String admLevel = entry.getValue().get("admin_level");
            if (admLevel != null && admLevel.equals(String.valueOf(adminlevel))) {
                found = true;
                break;
            }
        }
        if (found == false) {
            System.out.println("No boundary with admin_level=" + adminlevel + " found.");
            continue;
        }
        for (Entry<String, Tags> entry : bTags.entrySet()) {
            // get the admin_level tag
            String admLevel = entry.getValue().get("admin_level");
            if (admLevel == null) {
                admLevel = "notset";
            }
            String bId = entry.getKey();
            String gpxBasename = "gpx/" + boundaryFileName + "/covered/admin_level=" + admLevel + "/" + admLevel + "_" + bId + "_";
            Path2D.Double path = new Path2D.Double();
            List<Area> aList = areas.get(bId);
            for (Area area : aList) {
                path.append(area, false);
            }
            int i = 0;
            List<BoundaryElement> bElements = BoundaryUtil.splitToElements(new Area(path), bId);
            for (BoundaryElement be : bElements) {
                String gpxFile = gpxBasename;
                if (be.isOuter()) {
                    gpxFile += "o_" + i;
                } else {
                    gpxFile = "i_" + i;
                }
                GpxCreator.createGpx(gpxFile, be.getPoints());
                i++;
            }
        }
        saveEmptyAreas(adminlevel);
    }
    System.out.println("Finished " + boundaryFileName);
}
Also used : Path2D(java.awt.geom.Path2D) Entry(java.util.Map.Entry) Area(java.awt.geom.Area) ArrayList(java.util.ArrayList) List(java.util.List) Tags(uk.me.parabola.mkgmap.reader.osm.Tags)

Example 5 with Tags

use of uk.me.parabola.mkgmap.reader.osm.Tags in project mkgmap by openstreetmap.

the class BoundaryLister method main.

/**
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    String boundsdir = args[0];
    String outDirName = boundsdir;
    if (args.length >= 2)
        outDirName = args[1];
    File outDir = new File(outDirName);
    if (outDir.exists()) {
        if (outDir.isDirectory() == false) {
            System.err.println("target is not a directory, output is written to bounds.txt");
            outDir = new File(".");
        }
    }
    List<String> bndFileNames = BoundaryUtil.getBoundaryDirContent(boundsdir);
    PrintWriter out = new PrintWriter(new File(outDir, "bounds.txt"), "UTF-8");
    // uk.me.parabola.imgfmt.app.Area searchBbox = new uk.me.parabola.imgfmt.app.Area (0,0,0,0);
    for (String bndFile : bndFileNames) {
        out.println(bndFile + "****************");
        BoundaryQuadTree bqt = BoundaryUtil.loadQuadTree(boundsdir, bndFile);
        if (bqt == null)
            break;
        Map<String, Tags> map = bqt.getTagsMap();
        for (Entry<String, Tags> entry : map.entrySet()) {
            TreeMap<String, String> btree = new TreeMap<String, String>();
            String line = bndFile + ":" + entry.getKey();
            Iterator<Entry<String, String>> tagIter = entry.getValue().entryIterator();
            while (tagIter.hasNext()) {
                Entry<String, String> tag = tagIter.next();
                btree.put(tag.getKey(), tag.getValue());
            }
            // print sorted tags
            for (Entry<String, String> e : btree.entrySet()) {
                out.println(line + ";" + e);
            }
        }
    }
    out.close();
}
Also used : TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) File(java.io.File) Tags(uk.me.parabola.mkgmap.reader.osm.Tags) PrintWriter(java.io.PrintWriter)

Aggregations

Tags (uk.me.parabola.mkgmap.reader.osm.Tags)8 Area (java.awt.geom.Area)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Path2D (java.awt.geom.Path2D)2 EOFException (java.io.EOFException)2 File (java.io.File)2 Entry (java.util.Map.Entry)2 PrintWriter (java.io.PrintWriter)1 LinkedList (java.util.LinkedList)1 TreeMap (java.util.TreeMap)1 Coord (uk.me.parabola.imgfmt.app.Coord)1 MultiHashMap (uk.me.parabola.util.MultiHashMap)1