Search in sources :

Example 1 with RoadDef

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

the class RGNFileReader method readLineCommonExtType.

/**
 * Common code to read extended type lines or polygons for a given sub division.
 * @param reader The reader for the img file.
 * @param div The subdivision.
 * @param line The line or shape that is to be populated.
 */
private void readLineCommonExtType(ImgFileReader reader, Subdivision div, Polyline line) {
    int type = reader.get();
    type = (type & 0xff) << 8;
    byte b1 = reader.get();
    boolean hasExtraBytes = (b1 & 0x80) != 0;
    boolean hasLabel = (b1 & 0x20) != 0;
    type |= 0x10000 + (b1 & 0x1f);
    line.setType(type);
    line.setDeltaLong((short) reader.getChar());
    line.setDeltaLat((short) reader.getChar());
    b1 = reader.get();
    int len;
    // one byte or two byte length field?
    if ((b1 & 0x01) != 0) {
        len = (b1 >> 1) & 0x7f;
        assert len < 0x7f;
    } else {
        byte b2 = reader.get();
        len = (((b2 & 0xff) << 8) + (b1 & 0xff)) >> 2;
        assert len >= 0x7f;
    }
    // the encoded value includes the base field
    --len;
    assert len > 0;
    int base = reader.get();
    byte[] bitstream = reader.get(len);
    BitReader br = new BitReader(bitstream);
    // This reads the bit stream and adds all the points found,
    readBitStream(br, div, line, false, len, base);
    if (hasLabel) {
        int labelOffset = reader.getu3();
        Label label;
        if ((labelOffset & 0x800000) == 0) {
            label = lblFile.fetchLabel(labelOffset & 0x7fffff);
        } else {
            int netoff = labelOffset & 0x3fffff;
            labelOffset = netFile.getLabelOffset(netoff);
            label = lblFile.fetchLabel(labelOffset);
            RoadDef roadDef = new RoadDef(0, netoff, label.getText());
            line.setRoadDef(roadDef);
        }
        line.setLabel(label);
    }
    if (hasExtraBytes) {
        extractExtraBytes(reader, line);
    }
}
Also used : Label(uk.me.parabola.imgfmt.app.Label) RoadDef(uk.me.parabola.imgfmt.app.net.RoadDef) BitReader(uk.me.parabola.imgfmt.app.BitReader)

Example 2 with RoadDef

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

the class ImgReadTest method testNet.

@Test
public void testNet() throws IOException {
    try (MapReader mr = new MapReader(Utils.joinPath(Args.TEST_RESOURCE_IMG, Args.DEF_MAP_FILENAME3))) {
        List<RoadDef> roads = mr.getRoads();
        assertEquals("number of roads", 1365, roads.size());
    }
}
Also used : MapReader(uk.me.parabola.imgfmt.app.map.MapReader) RoadDef(uk.me.parabola.imgfmt.app.net.RoadDef) Test(org.junit.Test)

Example 3 with RoadDef

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

the class RGNFileReader method readLineCommon.

/**
 * Since polygons are pretty much like polylines in the img format the
 * reading code can be shared.
 *
 * @param reader The reader for the img file.
 * @param div The subdivision.
 * @param line The line or shape that is to be populated.
 */
private void readLineCommon(ImgFileReader reader, Subdivision div, Polyline line) {
    byte type = reader.get();
    if (line instanceof Polygon)
        line.setType(type & 0x7f);
    else {
        line.setType(type & 0x3f);
        line.setDirection((type & 0x40) != 0);
    }
    int labelOffset = reader.getu3();
    // Extra bit (for bit stream)
    boolean extra = (labelOffset & 0x400000) != 0;
    Label label;
    if ((labelOffset & 0x800000) == 0) {
        label = lblFile.fetchLabel(labelOffset & 0x7fffff);
    } else {
        int netoff = labelOffset & 0x3fffff;
        labelOffset = netFile.getLabelOffset(netoff);
        label = lblFile.fetchLabel(labelOffset);
        RoadDef roadDef = new RoadDef(0, netoff, label.getText());
        line.setRoadDef(roadDef);
    }
    line.setLabel(label);
    line.setDeltaLong((short) reader.getChar());
    line.setDeltaLat((short) reader.getChar());
    int len;
    if ((type & 0x80) == 0)
        len = reader.get() & 0xff;
    else
        len = reader.getChar();
    int base = reader.get();
    byte[] bitstream = reader.get(len);
    BitReader br = new BitReader(bitstream);
    // This reads the bit stream and adds all the points found
    readBitStream(br, div, line, extra, len, base);
}
Also used : Label(uk.me.parabola.imgfmt.app.Label) RoadDef(uk.me.parabola.imgfmt.app.net.RoadDef) BitReader(uk.me.parabola.imgfmt.app.BitReader)

Example 4 with RoadDef

use of uk.me.parabola.imgfmt.app.net.RoadDef 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

RoadDef (uk.me.parabola.imgfmt.app.net.RoadDef)4 BitReader (uk.me.parabola.imgfmt.app.BitReader)2 Label (uk.me.parabola.imgfmt.app.Label)2 Test (org.junit.Test)1 City (uk.me.parabola.imgfmt.app.lbl.City)1 MapReader (uk.me.parabola.imgfmt.app.map.MapReader)1 Mdr5Record (uk.me.parabola.imgfmt.app.mdr.Mdr5Record)1