Search in sources :

Example 6 with City

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

the class MapBuilder method processPoints.

/**
 * Step through the points, filter and create a map point which is then added
 * to the map.
 *
 * Note that the location and resolution of map elements is relative to the
 * subdivision that they occur in.
 *
 * @param map	The map to add points to.
 * @param div	The subdivision that the points belong to.
 * @param points The points to be added.
 */
private void processPoints(Map map, Subdivision div, List<MapPoint> points) {
    LBLFile lbl = map.getLblFile();
    div.startPoints();
    int res = div.getResolution();
    boolean haveIndPoints = false;
    int pointIndex = 1;
    // points (not 1)
    for (MapPoint point : points) {
        if (point.isCity() && point.getMinResolution() <= res) {
            ++pointIndex;
            haveIndPoints = true;
        }
    }
    for (MapPoint point : points) {
        if (point.isCity() || point.getMinResolution() > res)
            continue;
        String name = point.getName();
        Point p = div.createPoint(name);
        p.setType(point.getType());
        if (point.hasExtendedType()) {
            ExtTypeAttributes eta = point.getExtTypeAttributes();
            if (eta != null) {
                eta.processLabels(lbl);
                p.setExtTypeAttributes(eta);
            }
        }
        Coord coord = point.getLocation();
        try {
            p.setLatitude(coord.getLatitude());
            p.setLongitude(coord.getLongitude());
        } catch (AssertionError ae) {
            log.error("Problem with point of type 0x" + Integer.toHexString(point.getType()) + " at " + coord.toOSMURL());
            log.error("  Subdivision shift is " + div.getShift() + " and its centre is at " + div.getCenter().toOSMURL());
            log.error("  " + ae.getMessage());
            continue;
        }
        POIRecord r = poimap.get(point);
        if (r != null)
            p.setPOIRecord(r);
        map.addMapObject(p);
        if (!point.hasExtendedType()) {
            if (name != null && div.getZoom().getLevel() == 0) {
                if (pointIndex > 255)
                    log.error("Too many POIs at location " + div.getCenter().toOSMURL() + " - " + name + " will be ignored");
                else if (point.isExit()) {
                    Exit e = ((MapExitPoint) point).getExit();
                    if (e != null)
                        e.getHighway().addExitPoint(name, pointIndex, div);
                } else if (makePOIIndex)
                    lbl.createPOIIndex(name, pointIndex, div, point.getType());
            }
            ++pointIndex;
        }
    }
    if (haveIndPoints) {
        div.startIndPoints();
        // reset to 1
        pointIndex = 1;
        for (MapPoint point : points) {
            if (!point.isCity() || point.getMinResolution() > res)
                continue;
            String name = point.getName();
            Point p = div.createPoint(name);
            p.setType(point.getType());
            Coord coord = point.getLocation();
            try {
                p.setLatitude(coord.getLatitude());
                p.setLongitude(coord.getLongitude());
            } catch (AssertionError ae) {
                log.error("Problem with point of type 0x" + Integer.toHexString(point.getType()) + " at " + coord.toOSMURL());
                log.error("  Subdivision shift is " + div.getShift() + " and its centre is at " + div.getCenter().toOSMURL());
                log.error("  " + ae.getMessage());
                continue;
            }
            map.addMapObject(p);
            if (name != null && div.getZoom().getLevel() == 0) {
                // retrieve the City created earlier for this
                // point and store the point info in it
                City c = cityMap.get(point);
                if (pointIndex > 255) {
                    System.err.println("Can't set city point index for " + name + " (too many indexed points in division)\n");
                } else {
                    c.setPointIndex((byte) pointIndex);
                    c.setSubdivision(div);
                }
            }
            ++pointIndex;
        }
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) ExtTypeAttributes(uk.me.parabola.imgfmt.app.trergn.ExtTypeAttributes) POIRecord(uk.me.parabola.imgfmt.app.lbl.POIRecord) LBLFile(uk.me.parabola.imgfmt.app.lbl.LBLFile) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) Point(uk.me.parabola.imgfmt.app.trergn.Point) City(uk.me.parabola.imgfmt.app.lbl.City) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) Point(uk.me.parabola.imgfmt.app.trergn.Point) Exit(uk.me.parabola.imgfmt.app.Exit)

Example 7 with City

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

the class MdrBuilder method fetchCities.

/**
 * There is not complete information that we need about a city in the city
 * section, it has to be completed from the points section. So we fetch
 * and create the mdr5s first before points.
 */
private List<Mdr5Record> fetchCities(MapReader mr, AreaMaps maps) {
    Map<Integer, Mdr5Record> cityMap = maps.cities;
    List<Mdr5Record> cityList = new ArrayList<>();
    List<City> cities = mr.getCities();
    for (City c : cities) {
        int regionCountryNumber = c.getRegionCountryNumber();
        Mdr13Record mdrRegion = null;
        Mdr14Record mdrCountry;
        if ((regionCountryNumber & 0x4000) == 0) {
            mdrRegion = maps.regions.get(regionCountryNumber);
            mdrCountry = mdrRegion.getMdr14();
        } else {
            mdrCountry = maps.countries.get(regionCountryNumber & 0x3fff);
        }
        Mdr5Record mdrCity = new Mdr5Record();
        mdrCity.setCityIndex(c.getIndex());
        mdrCity.setRegionIndex(c.getRegionCountryNumber());
        mdrCity.setMdrRegion(mdrRegion);
        mdrCity.setMdrCountry(mdrCountry);
        mdrCity.setLblOffset(c.getLblOffset());
        mdrCity.setName(c.getName());
        int key = (c.getSubdivNumber() << 8) + (c.getPointIndex() & 0xff);
        assert key < 0xffffff;
        cityMap.put(key, mdrCity);
        cityList.add(mdrCity);
    }
    return cityList;
}
Also used : Mdr14Record(uk.me.parabola.imgfmt.app.mdr.Mdr14Record) Mdr5Record(uk.me.parabola.imgfmt.app.mdr.Mdr5Record) ArrayList(java.util.ArrayList) Mdr13Record(uk.me.parabola.imgfmt.app.mdr.Mdr13Record) City(uk.me.parabola.imgfmt.app.lbl.City) Point(uk.me.parabola.imgfmt.app.trergn.Point)

Example 8 with City

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

the class MdrBuilder method addStreets.

private void addStreets(MapReader mr, List<Mdr5Record> cityList) {
    List<RoadDef> roads = mr.getRoads();
    for (RoadDef road : roads) {
        String name = road.getName();
        if (name == null || name.isEmpty())
            continue;
        List<City> cities = road.getCities();
        if (cities.isEmpty())
            mdrFile.addStreet(road, null);
        else {
            for (City city : cities) {
                Mdr5Record mdrCity = cityList.get(city.getIndex() - 1);
                if (mdrCity.getMapIndex() == 0)
                    mdrCity = null;
                mdrFile.addStreet(road, mdrCity);
            }
        }
    }
}
Also used : Mdr5Record(uk.me.parabola.imgfmt.app.mdr.Mdr5Record) RoadDef(uk.me.parabola.imgfmt.app.net.RoadDef) City(uk.me.parabola.imgfmt.app.lbl.City)

Aggregations

City (uk.me.parabola.imgfmt.app.lbl.City)8 Point (uk.me.parabola.imgfmt.app.trergn.Point)4 LBLFile (uk.me.parabola.imgfmt.app.lbl.LBLFile)3 Mdr5Record (uk.me.parabola.imgfmt.app.mdr.Mdr5Record)3 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)3 ArrayList (java.util.ArrayList)2 Label (uk.me.parabola.imgfmt.app.Label)2 POIRecord (uk.me.parabola.imgfmt.app.lbl.POIRecord)2 Zip (uk.me.parabola.imgfmt.app.lbl.Zip)2 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashMap (java.util.HashMap)1 BitWriter (uk.me.parabola.imgfmt.app.BitWriter)1 Coord (uk.me.parabola.imgfmt.app.Coord)1 Exit (uk.me.parabola.imgfmt.app.Exit)1 Country (uk.me.parabola.imgfmt.app.lbl.Country)1 Region (uk.me.parabola.imgfmt.app.lbl.Region)1 Mdr13Record (uk.me.parabola.imgfmt.app.mdr.Mdr13Record)1 Mdr14Record (uk.me.parabola.imgfmt.app.mdr.Mdr14Record)1 Numbers (uk.me.parabola.imgfmt.app.net.Numbers)1