Search in sources :

Example 1 with Mdr5Record

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

the class MdrBuilder method addPoints.

/**
 * Read points from this map and add them to the index.
 * @param mr The currently open map.
 * @param maps Maps of regions, cities countries etc.
 */
private void addPoints(MapReader mr, AreaMaps maps) {
    List<Point> list = mr.pointsForLevel(0, MapReader.WITHOUT_EXT_TYPE_DATA);
    for (Point p : list) {
        Label label = p.getLabel();
        if (p.getNumber() > 256) {
            continue;
        }
        Mdr5Record mdrCity = null;
        boolean isCity;
        if (p.getType() >= 0x1 && p.getType() <= 0x11) {
            // This is itself a city, it gets a reference to its own MDR 5 record.
            // and we also use it to set the name of the city.
            mdrCity = maps.cities.get((p.getSubdiv().getNumber() << 8) + p.getNumber());
            if (mdrCity != null) {
                mdrCity.setLblOffset(label.getOffset());
                mdrCity.setName(label.getText());
            }
            isCity = true;
        } else {
            // This is not a city, but we have information about which city
            // it is in.  If so then add the mdr5 record number of the city.
            POIRecord poi = p.getPOIRecord();
            City c = poi.getCity();
            if (c != null)
                mdrCity = getMdr5FromCity(maps, c);
            isCity = false;
        }
        if (label != null && !label.getText().trim().isEmpty())
            mdrFile.addPoint(p, mdrCity, isCity);
    }
}
Also used : Mdr5Record(uk.me.parabola.imgfmt.app.mdr.Mdr5Record) Label(uk.me.parabola.imgfmt.app.Label) POIRecord(uk.me.parabola.imgfmt.app.lbl.POIRecord) Point(uk.me.parabola.imgfmt.app.trergn.Point) City(uk.me.parabola.imgfmt.app.lbl.City)

Example 2 with Mdr5Record

use of uk.me.parabola.imgfmt.app.mdr.Mdr5Record 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 3 with Mdr5Record

use of uk.me.parabola.imgfmt.app.mdr.Mdr5Record 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)

Example 4 with Mdr5Record

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

the class MdrBuilder method onMapEnd.

/**
 * Adds a new map to the file.  We need to read in the img file and
 * extract all the information that can be indexed from it.
 *
 * @param info An interface to read the map.
 */
public void onMapEnd(FileInfo info) {
    if (!info.isImg())
        return;
    // Add the map name
    mdrFile.addMap(info.getHexname(), info.getCodePage());
    String filename = info.getFilename();
    MapReader mr = null;
    try {
        mr = new MapReader(filename);
        AreaMaps maps = new AreaMaps();
        maps.countries = addCountries(mr);
        maps.regions = addRegions(mr, maps);
        List<Mdr5Record> mdrCityList = fetchCities(mr, maps);
        maps.cityList = mdrCityList;
        addPoints(mr, maps);
        addCities(mdrCityList);
        addStreets(mr, mdrCityList);
        addZips(mr);
    } catch (FileNotFoundException e) {
        throw new ExitException("Could not open " + filename + " when creating mdr file");
    } finally {
        Utils.closeFile(mr);
    }
}
Also used : MapReader(uk.me.parabola.imgfmt.app.map.MapReader) Mdr5Record(uk.me.parabola.imgfmt.app.mdr.Mdr5Record) FileNotFoundException(java.io.FileNotFoundException) ExitException(uk.me.parabola.imgfmt.ExitException)

Aggregations

Mdr5Record (uk.me.parabola.imgfmt.app.mdr.Mdr5Record)4 City (uk.me.parabola.imgfmt.app.lbl.City)3 Point (uk.me.parabola.imgfmt.app.trergn.Point)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 ExitException (uk.me.parabola.imgfmt.ExitException)1 Label (uk.me.parabola.imgfmt.app.Label)1 POIRecord (uk.me.parabola.imgfmt.app.lbl.POIRecord)1 MapReader (uk.me.parabola.imgfmt.app.map.MapReader)1 Mdr13Record (uk.me.parabola.imgfmt.app.mdr.Mdr13Record)1 Mdr14Record (uk.me.parabola.imgfmt.app.mdr.Mdr14Record)1 RoadDef (uk.me.parabola.imgfmt.app.net.RoadDef)1