Search in sources :

Example 1 with HousenumberMatchByNumComparator

use of uk.me.parabola.mkgmap.osmstyle.housenumber.HousenumberGenerator.HousenumberMatchByNumComparator in project mkgmap by openstreetmap.

the class HousenumberRoad method buildIntervals.

public void buildIntervals() {
    Collections.sort(houseNumbers, new HousenumberMatchByNumComparator());
    if (log.isInfoEnabled())
        log.info("Initial housenumbers for", road, "in", road.getCity(), houseNumbers);
    filterRealDuplicates();
    filterGroups();
    if (houseNumbers.isEmpty())
        return;
    List<HousenumberMatch> leftNumbers = new ArrayList<HousenumberMatch>();
    List<HousenumberMatch> rightNumbers = new ArrayList<HousenumberMatch>();
    for (HousenumberMatch house : houseNumbers) {
        if (house.getRoad() == null || house.isIgnored()) {
            continue;
        }
        if (house.getHousenumberRoad() != this || house.getHousenumberRoad().getRoad() != house.getRoad()) {
            log.error("internal error, road links are not correct", house.toBrowseURL());
        }
        if (house.isLeft()) {
            leftNumbers.add(house);
        } else {
            rightNumbers.add(house);
        }
    }
    detectGroups(leftNumbers, rightNumbers);
    Collections.sort(leftNumbers, new HousenumberMatchByPosComparator());
    Collections.sort(rightNumbers, new HousenumberMatchByPosComparator());
    int currNodePos = 0;
    int nodeIndex = 0;
    int prevNumberNodeIndex = 0;
    int prevNodePos = 0;
    extNumbersHead = null;
    ExtNumbers currNumbers = null;
    for (Coord p : road.getPoints()) {
        if (currNodePos == 0) {
            if (road.skipAddToNOD() == false)
                assert p instanceof CoordNode;
        }
        // An ordinary point in the road.
        if (p.isNumberNode() == false) {
            currNodePos++;
            continue;
        }
        // The first time round, this is guaranteed to be a CoordNode
        if (currNodePos == 0) {
            nodeIndex++;
            currNodePos++;
            continue;
        }
        // Now we have a CoordNode and it is not the first one.
        ExtNumbers numbers = new ExtNumbers(this);
        numbers.setNodeIndex(prevNumberNodeIndex);
        int leftUsed = numbers.setNumbers(leftNumbers, prevNodePos, currNodePos, true);
        int rightUsed = numbers.setNumbers(rightNumbers, prevNodePos, currNodePos, false);
        prevNodePos = currNodePos;
        // maintain chain
        numbers.prev = currNumbers;
        if (currNumbers != null)
            currNumbers.next = numbers;
        else {
            extNumbersHead = numbers;
        }
        currNumbers = numbers;
        leftNumbers.subList(0, leftUsed).clear();
        rightNumbers.subList(0, rightUsed).clear();
        prevNumberNodeIndex = nodeIndex;
        nodeIndex++;
        currNodePos++;
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) HousenumberMatchByPosComparator(uk.me.parabola.mkgmap.osmstyle.housenumber.HousenumberGenerator.HousenumberMatchByPosComparator) HousenumberMatchByNumComparator(uk.me.parabola.mkgmap.osmstyle.housenumber.HousenumberGenerator.HousenumberMatchByNumComparator) ArrayList(java.util.ArrayList) CoordNode(uk.me.parabola.imgfmt.app.CoordNode)

Aggregations

ArrayList (java.util.ArrayList)1 Coord (uk.me.parabola.imgfmt.app.Coord)1 CoordNode (uk.me.parabola.imgfmt.app.CoordNode)1 HousenumberMatchByNumComparator (uk.me.parabola.mkgmap.osmstyle.housenumber.HousenumberGenerator.HousenumberMatchByNumComparator)1 HousenumberMatchByPosComparator (uk.me.parabola.mkgmap.osmstyle.housenumber.HousenumberGenerator.HousenumberMatchByPosComparator)1