Exemplo n.º 1
0
/*public*/
EdgeRing*
EdgeRing::findEdgeRingContaining(EdgeRing* testEr,
                                 vector<EdgeRing*>* shellList)
{
    const LinearRing* testRing = testEr->getRingInternal();
    if(! testRing) {
        return nullptr;
    }
    const Envelope* testEnv = testRing->getEnvelopeInternal();
    Coordinate testPt = testRing->getCoordinateN(0);
    EdgeRing* minShell = nullptr;
    const Envelope* minEnv = nullptr;

    typedef std::vector<EdgeRing*> ERList;
    for(ERList::size_type i = 0, e = shellList->size(); i < e; ++i) {
        EdgeRing* tryShell = (*shellList)[i];
        LinearRing* tryRing = tryShell->getRingInternal();
        const Envelope* tryEnv = tryRing->getEnvelopeInternal();
        if(minShell != nullptr) {
            minEnv = minShell->getRingInternal()->getEnvelopeInternal();
        }
        bool isContained = false;

        // the hole envelope cannot equal the shell envelope

        if(tryEnv->equals(testEnv)) {
            continue;
        }

        const CoordinateSequence* tryCoords =
            tryRing->getCoordinatesRO();

        if(tryEnv->contains(testEnv)) {

            // TODO: don't copy testPt !
            testPt = ptNotInList(testRing->getCoordinatesRO(), tryCoords);

            if(PointLocation::isInRing(testPt, tryCoords)) {
                isContained = true;
            }

        }

        // check if this new containing ring is smaller
        // than the current minimum ring
        if(isContained) {
            if(minShell == nullptr || minEnv->contains(tryEnv)) {
                minShell = tryShell;
            }
        }
    }
    return minShell;
}
Exemplo n.º 2
0
bool
QuadtreeNestedRingTester::isNonNested()
{
    buildQuadtree();
    for(size_t i = 0, ni = rings.size(); i < ni; ++i) {
        const LinearRing* innerRing = rings[i];
        const CoordinateSequence* innerRingPts = innerRing->getCoordinatesRO();
        const Envelope* envi = innerRing->getEnvelopeInternal();

        vector<void*> results;
        qt->query(envi, results);
        for(size_t j = 0, nj = results.size(); j < nj; ++j) {
            LinearRing* searchRing = (LinearRing*)results[j];
            const CoordinateSequence* searchRingPts = searchRing->getCoordinatesRO();

            if(innerRing == searchRing) {
                continue;
            }

            const Envelope* e1 = innerRing->getEnvelopeInternal();
            const Envelope* e2 = searchRing->getEnvelopeInternal();
            if(!e1->intersects(e2)) {
                continue;
            }

            const Coordinate* innerRingPt = IsValidOp::findPtNotNode(innerRingPts,
                                            searchRing, graph);

            // Unable to find a ring point not a node of the search ring
            assert(innerRingPt != nullptr);

            bool isInside = PointLocation::isInRing(*innerRingPt, searchRingPts);
            if(isInside) {
                /*
                 * innerRingPt is const just because the input
                 * CoordinateSequence is const. If the input
                 * Polygon survives lifetime of this object
                 * we are safe.
                 */
                nestedPt = const_cast<Coordinate*>(innerRingPt);
                return false;
            }
        }
    }
    return true;
}