Search in sources :

Example 26 with Label

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

the class PlacesFile method createRegion.

Region createRegion(Country country, String name, String abbr) {
    String s = abbr != null ? name + (char) 0x1d + abbr : name;
    String uniqueRegionName = s.toUpperCase() + "_C" + country.getLabel().getOffset();
    Region r = regions.get(uniqueRegionName);
    if (r == null) {
        r = new Region(country);
        Label l = lblFile.newLabel(s);
        r.setLabel(l);
        regionList.add(r);
        regions.put(uniqueRegionName, r);
    }
    return r;
}
Also used : Label(uk.me.parabola.imgfmt.app.Label)

Example 27 with Label

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

the class Map method addCopyright.

/**
 * Add a copyright message to the map.
 * @param str the copyright message. The second (last?) one set
 * gets shown when the device starts (sometimes?).
 */
public void addCopyright(String str) {
    Label cpy = lblFile.newLabel(str);
    treFile.addCopyright(cpy);
}
Also used : Label(uk.me.parabola.imgfmt.app.Label)

Example 28 with Label

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

the class MDRFile method addStreet.

public void addStreet(RoadDef street, Mdr5Record mdrCity) {
    // Add a separate record for each name
    for (Label lab : street.getLabels()) {
        if (lab == null)
            break;
        if (lab.getOffset() == 0)
            continue;
        String name = lab.getText();
        if (!mdr7Del.isEmpty()) {
            String[] parts = name.split(" ");
            int pos = parts.length;
            for (int i = parts.length - 1; i >= 0; i--) {
                if (!mdr7Del.contains(parts[i])) {
                    break;
                }
                pos = i;
            }
            if (pos == 0)
                continue;
            if (pos < parts.length) {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i + 1 < pos; i++) {
                    sb.append(parts[i]);
                    sb.append(" ");
                }
                sb.append(parts[pos - 1]);
                // XXX maybe add -intern()
                name = sb.toString();
            }
        }
        int strOff = createString(name);
        // We sort on the dirty name (ie with the Garmin shield codes) although those codes do not
        // affect the sort order. The string for mdr15 does not include the shield codes.
        mdr7.addStreet(currentMap, name, lab.getOffset(), strOff, mdrCity);
    }
}
Also used : Label(uk.me.parabola.imgfmt.app.Label) Point(uk.me.parabola.imgfmt.app.trergn.Point)

Example 29 with Label

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

the class RoadDef method writeLabels.

private void writeLabels(ImgFileWriter writer) {
    for (int i = 0; i < numlabels; i++) {
        Label l = labels[i];
        int ptr = l.getOffset();
        if (i == (numlabels - 1))
            ptr |= 0x800000;
        writer.put3(ptr);
    }
}
Also used : Label(uk.me.parabola.imgfmt.app.Label)

Example 30 with Label

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

the class NETFile method sortRoads.

/**
 * Sort the roads by name and remove duplicates.
 *
 * We want a list of roads such that every entry in the list is a different road. Since in osm
 * roads are frequently chopped into small pieces we have to remove the duplicates.
 * This doesn't have to be perfect, it needs to be useful when searching for roads.
 *
 * So we have a separate entry if the road is in a different city. This would probably be enough
 * except that associating streets with cities is not always very good in OSM. So I also create an
 * extra entry for each subdivision. Finally there a search for disconnected roads within the subdivision
 * with the same name.
 *
 * Performance note: The previous implementation was very, very slow when there were a large number
 * of roads with the same name. Although this was an unusual situation, when it happened it appears
 * that mkgmap has hung. This implementation takes a fraction of a second even for large numbers of
 * same named roads.
 *
 * @return A sorted list of road labels that identify all the different roads.
 */
private List<LabeledRoadDef> sortRoads() {
    List<SortKey<LabeledRoadDef>> sortKeys = new ArrayList<>(roads.size());
    Map<Label, byte[]> cache = new HashMap<>();
    for (RoadDef rd : roads) {
        Label[] labels = rd.getLabels();
        for (int i = 0; i < labels.length && labels[i] != null; ++i) {
            Label label = labels[i];
            if (label.getLength() == 0)
                continue;
            // Sort by name, city, region/country and subdivision number.
            LabeledRoadDef lrd = new LabeledRoadDef(label, rd);
            SortKey<LabeledRoadDef> nameKey = new IntegerSortKey<NETFile.LabeledRoadDef>(lrd, label.getOffset(), 0);
            // If there is a city add it to the sort.
            // what if we more than one?
            City city = (rd.getCities().isEmpty() ? null : rd.getCities().get(0));
            SortKey<LabeledRoadDef> cityKey;
            if (city != null) {
                int region = city.getRegionNumber();
                int country = city.getCountryNumber();
                cityKey = sort.createSortKey(null, city.getLabel(), (region & 0xffff) << 16 | (country & 0xffff), cache);
            } else {
                cityKey = sort.createSortKey(null, Label.NULL_OUT_LABEL, 0, cache);
            }
            SortKey<LabeledRoadDef> sortKey = new MultiSortKey<>(nameKey, cityKey, new IntegerSortKey<LabeledRoadDef>(null, rd.getStartSubdivNumber(), 0));
            sortKeys.add(sortKey);
        }
    }
    Collections.sort(sortKeys);
    List<LabeledRoadDef> out = new ArrayList<>(sortKeys.size());
    Label lastName = null;
    City lastCity = null;
    List<LabeledRoadDef> dupes = new ArrayList<>();
    // The duplicates are saved to the dupes list.
    for (SortKey<LabeledRoadDef> key : sortKeys) {
        LabeledRoadDef lrd = key.getObject();
        Label name = lrd.label;
        RoadDef road = lrd.roadDef;
        // what if we more than one?
        City city = (road.getCities().isEmpty() ? null : road.getCities().get(0));
        if (road.hasHouseNumbers() || !name.equals(lastName) || city != lastCity) {
            // process any previously collected duplicate road names and reset.
            addDisconnected(dupes, out);
            dupes = new ArrayList<>();
            lastName = name;
            lastCity = city;
        }
        dupes.add(lrd);
    }
    // Finish off the final set of duplicates.
    addDisconnected(dupes, out);
    sortByName(out);
    return out;
}
Also used : IntegerSortKey(uk.me.parabola.imgfmt.app.srt.IntegerSortKey) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Label(uk.me.parabola.imgfmt.app.Label) IntegerSortKey(uk.me.parabola.imgfmt.app.srt.IntegerSortKey) DoubleSortKey(uk.me.parabola.imgfmt.app.srt.DoubleSortKey) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey) MultiSortKey(uk.me.parabola.imgfmt.app.srt.MultiSortKey) City(uk.me.parabola.imgfmt.app.lbl.City) MultiSortKey(uk.me.parabola.imgfmt.app.srt.MultiSortKey)

Aggregations

Label (uk.me.parabola.imgfmt.app.Label)35 BufferedImgFileReader (uk.me.parabola.imgfmt.app.BufferedImgFileReader)7 ImgFileReader (uk.me.parabola.imgfmt.app.ImgFileReader)7 POIRecord (uk.me.parabola.imgfmt.app.lbl.POIRecord)5 Point (uk.me.parabola.imgfmt.app.trergn.Point)4 ArrayList (java.util.ArrayList)2 BitReader (uk.me.parabola.imgfmt.app.BitReader)2 City (uk.me.parabola.imgfmt.app.lbl.City)2 LBLFile (uk.me.parabola.imgfmt.app.lbl.LBLFile)2 RoadDef (uk.me.parabola.imgfmt.app.net.RoadDef)2 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)2 HashMap (java.util.HashMap)1 Random (java.util.Random)1 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)1 BitWriter (uk.me.parabola.imgfmt.app.BitWriter)1 BufferedImgFileWriter (uk.me.parabola.imgfmt.app.BufferedImgFileWriter)1 Exit (uk.me.parabola.imgfmt.app.Exit)1 ImgFileWriter (uk.me.parabola.imgfmt.app.ImgFileWriter)1 Section (uk.me.parabola.imgfmt.app.Section)1 DecodedText (uk.me.parabola.imgfmt.app.labelenc.DecodedText)1