コード例 #1
0
ファイル: ogrunionlayer.cpp プロジェクト: bbradbury/lib_gdal
void OGRUnionLayer::AutoWarpLayerIfNecessary(int iLayer)
{
    if( !pabCheckIfAutoWrap[iLayer] )
    {
        pabCheckIfAutoWrap[iLayer] = TRUE;

        for(int i=0; i<GetLayerDefn()->GetGeomFieldCount();i++)
        {
            OGRSpatialReference* poSRS = GetLayerDefn()->GetGeomFieldDefn(i)->GetSpatialRef();
            if( poSRS != NULL )
                poSRS->Reference();

            OGRFeatureDefn* poSrcFeatureDefn = papoSrcLayers[iLayer]->GetLayerDefn();
            int iSrcGeomField = poSrcFeatureDefn->GetGeomFieldIndex(
                    GetLayerDefn()->GetGeomFieldDefn(i)->GetNameRef());
            if( iSrcGeomField >= 0 )
            {
                OGRSpatialReference* poSRS2 =
                    poSrcFeatureDefn->GetGeomFieldDefn(iSrcGeomField)->GetSpatialRef();

                if( (poSRS == NULL && poSRS2 != NULL) ||
                    (poSRS != NULL && poSRS2 == NULL) )
                {
                    CPLError(CE_Warning, CPLE_AppDefined,
                            "SRS of geometry field '%s' layer %s not consistent with UnionLayer SRS",
                            GetLayerDefn()->GetGeomFieldDefn(i)->GetNameRef(),
                            papoSrcLayers[iLayer]->GetName());
                }
                else if (poSRS != NULL && poSRS2 != NULL &&
                        poSRS != poSRS2 && !poSRS->IsSame(poSRS2))
                {
                    CPLDebug("VRT", "SRS of geometry field '%s' layer %s not consistent with UnionLayer SRS. "
                            "Trying auto warping",
                            GetLayerDefn()->GetGeomFieldDefn(i)->GetNameRef(),
                            papoSrcLayers[iLayer]->GetName());
                    OGRCoordinateTransformation* poCT =
                        OGRCreateCoordinateTransformation( poSRS2, poSRS );
                    OGRCoordinateTransformation* poReversedCT = (poCT != NULL) ?
                        OGRCreateCoordinateTransformation( poSRS, poSRS2 ) : NULL;
                    if( poReversedCT != NULL )
                        papoSrcLayers[iLayer] = new OGRWarpedLayer(
                                    papoSrcLayers[iLayer], iSrcGeomField, TRUE, poCT, poReversedCT);
                    else
                    {
                        CPLError(CE_Warning, CPLE_AppDefined,
                                 "AutoWarpLayerIfNecessary failed to create "
                                 "poCT or poReversedCT.");
                        if ( poCT != NULL )
                            delete poCT;
                    }
                }
            }

            if( poSRS != NULL )
                poSRS->Release();
        }
    }
}
コード例 #2
0
ファイル: ogrunionlayer.cpp プロジェクト: afarnham/gdal
void OGRUnionLayer::AutoWarpLayerIfNecessary(int iLayer)
{
    if( !pabCheckIfAutoWrap[iLayer] )
    {
        pabCheckIfAutoWrap[iLayer] = TRUE;

        OGRSpatialReference* poSRS = GetSpatialRef();
        if( poSRS != NULL )
            poSRS->Reference();

        OGRSpatialReference* poSRS2 = papoSrcLayers[iLayer]->GetSpatialRef();

        if( (poSRS == NULL && poSRS2 != NULL) ||
            (poSRS != NULL && poSRS2 == NULL) )
        {
            CPLError(CE_Warning, CPLE_AppDefined,
                    "SRS of layer %s not consistant with layer SRS",
                    papoSrcLayers[iLayer]->GetName());
        }
        else if (poSRS != NULL && poSRS2 != NULL &&
                 poSRS != poSRS2 && !poSRS->IsSame(poSRS2))
        {
            CPLDebug("VRT", "SRS of layer %s not consistant with layer SRS. "
                     "Trying auto warping",
                     papoSrcLayers[iLayer]->GetName());
            OGRCoordinateTransformation* poCT =
                OGRCreateCoordinateTransformation( poSRS2, poSRS );
            OGRCoordinateTransformation* poReversedCT = (poCT != NULL) ?
                OGRCreateCoordinateTransformation( poSRS, poSRS2 ) : NULL;
            if( poCT != NULL && poReversedCT != NULL )
                papoSrcLayers[iLayer] = new OGRWarpedLayer(
                            papoSrcLayers[iLayer], TRUE, poCT, poReversedCT);
        }

        if( poSRS != NULL )
            poSRS->Release();
    }
}