Search in sources :

Example 6 with Numbers

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

the class RoadHelper method convertNodesForHouseNumbers.

/**
 * Make sure that each node that is referenced by the house
 * numbers is a number node. Some of them will later be changed
 * to routing nodes.
 * Only called if numbers is non-null and not empty.
 */
private void convertNodesForHouseNumbers(MapRoad road) {
    int rNodNumber = 0;
    for (Numbers n : numbers) {
        int node = n.getNodeNumber();
        n.setIndex(rNodNumber++);
        road.getPoints().get(node).setNumberNode(true);
    }
}
Also used : Numbers(uk.me.parabola.imgfmt.app.net.Numbers)

Example 7 with Numbers

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

the class MapBuilder method processRoads.

private void processRoads(Map map, MapDataSource src) {
    LBLFile lbl = map.getLblFile();
    MapPoint searchPoint = new MapPoint();
    for (MapLine line : src.getLines()) {
        if (line.isRoad()) {
            String cityName = line.getCity();
            String cityCountryName = line.getCountry();
            String cityRegionName = line.getRegion();
            String zipStr = line.getZip();
            if (cityName == null && locationAutofill.contains("nearest")) {
                // Get name of next city if untagged
                searchPoint.setLocation(line.getLocation());
                MapPoint nextCity = locator.findNextPoint(searchPoint);
                if (nextCity != null) {
                    cityName = nextCity.getCity();
                    // city/region/country fields should match to the found city
                    cityCountryName = nextCity.getCountry();
                    cityRegionName = nextCity.getRegion();
                    // use the zip code only if no zip code is known
                    if (zipStr == null)
                        zipStr = nextCity.getZip();
                }
            }
            MapRoad road = (MapRoad) line;
            road.resetImgData();
            City roadCity = calcCity(lbl, cityName, cityRegionName, cityCountryName);
            if (roadCity != null)
                road.addRoadCity(roadCity);
            if (zipStr != null) {
                road.addRoadZip(lbl.createZip(zipStr));
            }
            List<Numbers> numbers = road.getRoadDef().getNumbersList();
            if (numbers != null) {
                for (Numbers num : numbers) {
                    for (int i = 0; i < 2; i++) {
                        boolean left = (i == 0);
                        ZipCodeInfo zipInfo = num.getZipCodeInfo(left);
                        if (zipInfo != null && zipInfo.getZipCode() != null) {
                            Zip zip = zipInfo.getImgZip();
                            if (zipInfo.getImgZip() == null) {
                                zip = lbl.createZip(zipInfo.getZipCode());
                                zipInfo.setImgZip(zip);
                            }
                            if (zip != null)
                                road.addRoadZip(zip);
                        }
                        CityInfo cityInfo = num.getCityInfo(left);
                        if (cityInfo != null) {
                            City city = cityInfo.getImgCity();
                            if (city == null) {
                                city = calcCity(lbl, cityInfo.getCity(), cityInfo.getRegion(), cityInfo.getCountry());
                                cityInfo.setImgCity(city);
                            }
                            if (city != null)
                                road.addRoadCity(city);
                        }
                    }
                }
            }
        }
    }
}
Also used : Zip(uk.me.parabola.imgfmt.app.lbl.Zip) CityInfo(uk.me.parabola.mkgmap.general.CityInfo) MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) 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) Numbers(uk.me.parabola.imgfmt.app.net.Numbers) ZipCodeInfo(uk.me.parabola.mkgmap.general.ZipCodeInfo) LBLFile(uk.me.parabola.imgfmt.app.lbl.LBLFile)

Example 8 with Numbers

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

the class NumberRangeTest method run.

private void run(String[] strings) {
    List<Numbers> numbers = new ArrayList<Numbers>();
    for (String s : strings) {
        Numbers n = new Numbers(s);
        n.setIndex(n.getNodeNumber());
        numbers.add(n);
    }
    NumberPreparer np = new NumberPreparer(numbers);
    BitWriter bitWriter = np.fetchBitStream();
    bytesUsed += bitWriter.getLength();
    // Now read it back in
    byte[] bytes = new byte[bitWriter.getLength()];
    System.arraycopy(bitWriter.getBytes(), 0, bytes, 0, bytes.length);
    NumberReader nr = new NumberReader(new BitReader(bytes));
    nr.setNumberOfNodes(numbers.get(numbers.size() - 1).getIndex() + 1);
    List<Numbers> list = nr.readNumbers(np.getSwapped());
    // Have to fix up the node numbers
    for (Numbers n : list) {
        n.setNodeNumber(n.getIndex());
    }
    // Test that they are the same.
    String orig = numbers.toString();
    String calculated = list.toString();
    if (!orig.equals(calculated)) {
        System.out.printf("Fail: expecting: %s\n            Got: %s\n", orig, calculated);
    }
}
Also used : BitWriter(uk.me.parabola.imgfmt.app.BitWriter) Numbers(uk.me.parabola.imgfmt.app.net.Numbers) ArrayList(java.util.ArrayList) NumberReader(func.lib.NumberReader) NumberPreparer(uk.me.parabola.imgfmt.app.net.NumberPreparer) BitReader(uk.me.parabola.imgfmt.app.BitReader)

Example 9 with Numbers

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

the class NumberException method readSingleSide.

/**
 * If the road has numbers on just one side, then there is a shortened reading routine.
 * The left variables are mostly used during reading regardless of which side of the
 * road has numbers. Make everything work here.
 * @param numbers The output list that the number record should be added to.
 */
private void readSingleSide(List<Numbers> numbers) {
    rightBase = leftBase;
    rightStart = leftStart;
    rightEnd = leftEnd;
    rightLastEndDiff = leftLastEndDiff;
    adjustValues();
    Numbers n = new Numbers();
    n.setIndex(nodeCounter);
    if (leftStyle == NONE)
        n.setNumbers(Numbers.RIGHT, rightStyle, rightStart, rightEnd);
    else
        n.setNumbers(Numbers.LEFT, leftStyle, leftStart, leftEnd);
    numbers.add(n);
    nodeCounter++;
}
Also used : Numbers(uk.me.parabola.imgfmt.app.net.Numbers)

Example 10 with Numbers

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

the class NumberException method fetchNumbers.

/**
 * Read the house numbers for a stretch of road.
 *
 * The start and end positions of the the left hand side of the road is first, followed
 * by the right hand side of the road.
 *
 * The differences to the last point are stored. It is also possible to
 * @param numbers When numbers are read, they are saved here.
 */
private void fetchNumbers(List<Numbers> numbers) {
    // If one side has no numbers, then there is only one set of numbers to calculate, but
    // changes to base are applied to both sides.
    boolean doSingleSide = (leftStyle == NONE || rightStyle == NONE);
    if (leftStyle == NONE)
        leftBase = rightBase;
    // Check for command to copy the base number
    boolean doSameBase = false;
    if (!doSingleSide) {
        doSameBase = br.get1();
        if (doSameBase)
            copyBase();
    }
    // int abc = br.get(3);
    boolean doRightOverride = false;
    if (!doSingleSide)
        doRightOverride = !br.get1();
    boolean doReadStart = !br.get1();
    boolean doReadEnd = !br.get1();
    // item.addText("cmd: fetch numbers abc: %x", abc);
    int startDiff = 0, endDiff = leftLastEndDiff;
    if (doReadStart) {
        startDiff = startReader.read();
    }
    if (doReadEnd) {
        endDiff = endReader.read();
    }
    leftStart = leftBase + startDiff;
    leftEnd = leftStart + endDiff;
    leftBase = leftEnd;
    leftLastEndDiff = endDiff;
    if (doSingleSide) {
        readSingleSide(numbers);
        restoreReaders();
        return;
    }
    // start diff falls through at least when doSameBase is in force
    if (!doSameBase)
        startDiff = 0;
    // default to the saved value.
    if (doRightOverride || !doReadEnd)
        endDiff = rightLastEndDiff;
    doReadStart = false;
    doReadEnd = false;
    if (!doSameBase)
        doReadStart = !br.get1();
    if (doRightOverride)
        doReadEnd = !br.get1();
    if (doReadStart)
        startDiff = startReader.read();
    if (doReadEnd)
        endDiff = endReader.read();
    rightStart = rightBase + startDiff;
    rightEnd = rightStart + endDiff;
    rightBase = rightEnd;
    rightLastEndDiff = endDiff;
    adjustValues();
    Numbers n = new Numbers();
    n.setIndex(nodeCounter);
    n.setNumbers(Numbers.LEFT, leftStyle, leftStart, leftEnd);
    n.setNumbers(Numbers.RIGHT, rightStyle, rightStart, rightEnd);
    numbers.add(n);
    nodeCounter++;
    restoreReaders();
}
Also used : Numbers(uk.me.parabola.imgfmt.app.net.Numbers)

Aggregations

Numbers (uk.me.parabola.imgfmt.app.net.Numbers)13 ArrayList (java.util.ArrayList)5 Coord (uk.me.parabola.imgfmt.app.Coord)4 NumberStyle (uk.me.parabola.imgfmt.app.net.NumberStyle)4 MapRoad (uk.me.parabola.mkgmap.general.MapRoad)3 CityInfo (uk.me.parabola.mkgmap.general.CityInfo)2 HousenumberMatchByPosComparator (uk.me.parabola.mkgmap.osmstyle.housenumber.HousenumberGenerator.HousenumberMatchByPosComparator)2 NumberReader (func.lib.NumberReader)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1 LongArrayList (it.unimi.dsi.fastutil.longs.LongArrayList)1 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 BitReader (uk.me.parabola.imgfmt.app.BitReader)1