Beispiel #1
0
double OGRCompoundCurve::get_Area() const
{
    if( IsEmpty() || !get_IsClosed() )
        return 0;

    // Optimization for convex rings.
    if( IsConvex() )
    {
        // Compute area of shape without the circular segments.
        OGRPointIterator* poIter = getPointIterator();
        OGRLineString oLS;
        oLS.setNumPoints( getNumPoints() );
        OGRPoint p;
        for( int i = 0; poIter->getNextPoint(&p); i++ )
        {
            oLS.setPoint( i, p.getX(), p.getY() );
        }
        double dfArea = oLS.get_Area();
        delete poIter;

        // Add the area of the spherical segments.
        dfArea += get_AreaOfCurveSegments();

        return dfArea;
    }

    OGRLineString* poLS = CurveToLine();
    double dfArea = poLS->get_Area();
    delete poLS;

    return dfArea;
}
Beispiel #2
0
OGRBoolean OGRCurve::IsConvex() const
{
    OGRBoolean bRet = TRUE;
    OGRPointIterator* poPointIter = getPointIterator();
    OGRPoint p1, p2, p3;
    if( poPointIter->getNextPoint(&p1) &&
        poPointIter->getNextPoint(&p2) )
    {
        while( poPointIter->getNextPoint(&p3) )
        {
            double crossproduct = (p2.getX() - p1.getX()) * (p3.getY() - p2.getY()) -
                                  (p2.getY() - p1.getY()) * (p3.getX() - p2.getX());
            if( crossproduct > 0 )
            {
                bRet = FALSE;
                break;
            }
            p1.setX(p2.getX());
            p1.setY(p2.getY());
            p2.setX(p3.getX());
            p2.setY(p3.getY());
        }
    }
    delete poPointIter;
    return bRet;
}
Beispiel #3
0
OGRBoolean OGRCompoundCurvePointIterator::getNextPoint( OGRPoint* p )
{
    if( iCurCurve == poCC->getNumCurves() )
        return FALSE;
    if( poCurveIter == NULL )
        poCurveIter = poCC->getCurve(0)->getPointIterator();
    if( !poCurveIter->getNextPoint(p) )
    {
        iCurCurve++;
        if( iCurCurve == poCC->getNumCurves() )
            return FALSE;
        delete poCurveIter;
        poCurveIter = poCC->getCurve(iCurCurve)->getPointIterator();
        // Skip first point.
        return poCurveIter->getNextPoint(p) &&
               poCurveIter->getNextPoint(p);
    }
    return TRUE;
}