Пример #1
0
int SDTSTransfer::GetBounds( double *pdfMinX, double *pdfMinY,
                             double *pdfMaxX, double *pdfMaxY )

{
    bool bFirst = true;

    for( int iLayer = 0; iLayer < GetLayerCount(); iLayer++ )
    {
        if( GetLayerType( iLayer ) == SLTPoint )
        {

            SDTSPointReader *poLayer = reinterpret_cast<SDTSPointReader *>(
                GetLayerIndexedReader( iLayer ) );
            if( poLayer == nullptr )
                continue;

            poLayer->Rewind();

            SDTSRawPoint *poPoint = nullptr;
            while( (poPoint = reinterpret_cast<SDTSRawPoint *>(
                      poLayer->GetNextFeature() ) ) != nullptr )
            {
                if( bFirst )
                {
                    *pdfMinX = poPoint->dfX;
                    *pdfMaxX = poPoint->dfX;
                    *pdfMinY = poPoint->dfY;
                    *pdfMaxY = poPoint->dfY;
                    bFirst = false;
                }
                else
                {
                    *pdfMinX = std::min( *pdfMinX, poPoint->dfX );
                    *pdfMaxX = std::max( *pdfMaxX, poPoint->dfX );
                    *pdfMinY = std::min( *pdfMinY, poPoint->dfY );
                    *pdfMaxY = std::max( *pdfMaxY, poPoint->dfY );
                }

                if( !poLayer->IsIndexed() )
                    delete poPoint;
            }
        }
        else if( GetLayerType( iLayer ) == SLTRaster )
        {
            SDTSRasterReader *poRL = GetLayerRasterReader( iLayer );
            if( poRL == nullptr )
                continue;

            double adfGeoTransform[6];
            poRL->GetTransform( adfGeoTransform );

            const double dfMinX = adfGeoTransform[0];
            const double dfMaxY = adfGeoTransform[3];
            const double dfMaxX = adfGeoTransform[0]
                + poRL->GetXSize() * adfGeoTransform[1];
            const double dfMinY = adfGeoTransform[3]
                + poRL->GetYSize() * adfGeoTransform[5];

            if( bFirst )
            {
                *pdfMinX = dfMinX;
                *pdfMaxX = dfMaxX;
                *pdfMinY = dfMinY;
                *pdfMaxY = dfMaxY;
                bFirst = false;
            }
            else
            {
                *pdfMinX = std::min( dfMinX, *pdfMinX );
                *pdfMaxX = std::max( dfMaxX, *pdfMaxX );
                *pdfMinY = std::min( dfMinY, *pdfMinY );
                *pdfMaxY = std::max( dfMaxY, *pdfMaxY );
            }

            delete poRL;
        }
    }

    return !bFirst;
}
Пример #2
0
int SDTSTransfer::GetBounds( double *pdfMinX, double *pdfMinY,
                             double *pdfMaxX, double *pdfMaxY )

{
    int         bFirst = TRUE;
    
    for( int iLayer = 0; iLayer < GetLayerCount(); iLayer++ )
    {
        if( GetLayerType( iLayer ) == SLTPoint )
        {
            SDTSPointReader     *poLayer;
            SDTSRawPoint    *poPoint;
        
            poLayer = (SDTSPointReader *) GetLayerIndexedReader( iLayer );
            if( poLayer == NULL )
                continue;
            
            poLayer->Rewind();
            while( (poPoint = (SDTSRawPoint*) poLayer->GetNextFeature()) )
            {
                if( bFirst )
                {
                    *pdfMinX = *pdfMaxX = poPoint->dfX;
                    *pdfMinY = *pdfMaxY = poPoint->dfY;
                    bFirst = FALSE;
                }
                else
                {
                    *pdfMinX = MIN(*pdfMinX,poPoint->dfX);
                    *pdfMaxX = MAX(*pdfMaxX,poPoint->dfX);
                    *pdfMinY = MIN(*pdfMinY,poPoint->dfY);
                    *pdfMaxY = MAX(*pdfMaxY,poPoint->dfY);
                }
                
                if( !poLayer->IsIndexed() )
                    delete poPoint;
            }
        }
        
        else if( GetLayerType( iLayer ) == SLTRaster )
        {
            SDTSRasterReader    *poRL;
            double              adfGeoTransform[6];
            double              dfMinX, dfMaxX, dfMinY, dfMaxY;

            poRL = GetLayerRasterReader( iLayer );
            if( poRL == NULL )
                continue;

            poRL->GetTransform( adfGeoTransform );

            dfMinX = adfGeoTransform[0];
            dfMaxY = adfGeoTransform[3];
            dfMaxX = adfGeoTransform[0] + poRL->GetXSize()*adfGeoTransform[1];
            dfMinY = adfGeoTransform[3] + poRL->GetYSize()*adfGeoTransform[5];

            if( bFirst )
            {
                *pdfMinX = dfMinX;
                *pdfMaxX = dfMaxX;
                *pdfMinY = dfMinY;
                *pdfMaxY = dfMaxY;
                bFirst = FALSE;
            }
            else
            {
                *pdfMinX = MIN(dfMinX,*pdfMinX);
                *pdfMaxX = MAX(dfMaxX,*pdfMaxX);
                *pdfMinY = MIN(dfMinY,*pdfMinY);
                *pdfMaxY = MAX(dfMaxY,*pdfMaxY);
            }

            delete poRL;
        }
    }

    return !bFirst;
}