Ejemplo n.º 1
0
OGRDataSourceH OGR_Dr_CopyDataSource( OGRSFDriverH hDriver,
                                      OGRDataSourceH hSrcDS,
                                      const char *pszNewName,
                                      char **papszOptions )

{
    VALIDATE_POINTER1( hDriver, "OGR_Dr_CopyDataSource", NULL );
    VALIDATE_POINTER1( hSrcDS, "OGR_Dr_CopyDataSource", NULL );
    VALIDATE_POINTER1( pszNewName, "OGR_Dr_CopyDataSource", NULL );

    GDALDriver* poDriver = (GDALDriver*)hDriver;
    if( !poDriver->GetMetadataItem( GDAL_DCAP_CREATE ) )
    {
        CPLError( CE_Failure, CPLE_NotSupported,
                  "%s driver does not support data source creation.",
                  poDriver->GetDescription() );
        return NULL;
    }

    GDALDataset *poSrcDS = (GDALDataset*) hSrcDS;
    GDALDataset *poODS;

    poODS = poDriver->Create( pszNewName, 0, 0, 0, GDT_Unknown, papszOptions );
    if( poODS == NULL )
        return NULL;

/* -------------------------------------------------------------------- */
/*      Process each data source layer.                                 */
/* -------------------------------------------------------------------- */
    for( int iLayer = 0; iLayer < poSrcDS->GetLayerCount(); iLayer++ )
    {
        OGRLayer        *poLayer = poSrcDS->GetLayer(iLayer);

        if( poLayer == NULL )
            continue;

        poODS->CopyLayer( poLayer, poLayer->GetLayerDefn()->GetName(),
                          papszOptions );
    }

    return (OGRDataSourceH)poODS;
}
Ejemplo n.º 2
0
static OGRErr CreateAndFillOutputDataset(OGRLayer* poSrcLayer,
                                         const char* pszDestDataSource,
                                         const char* pszFormat,
                                         const char* pszLayer,
                                         char** papszDSCO,
                                         char** papszLCO,
                                         int bQuiet)
{
    GDALDriver *poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
    if( poDriver == NULL )
    {
        fprintf( stderr, "%s driver not available\n", pszFormat );
        return OGRERR_FAILURE;
    }

    if( !CSLTestBoolean(
                CSLFetchNameValueDef(poDriver->GetMetadata(), GDAL_DCAP_CREATE,
                                     "FALSE") ) )
    {
        fprintf( stderr,  "%s driver does not support data source creation.\n",
                pszFormat );
        return OGRERR_FAILURE;
    }

    GDALDataset* poODS = poDriver->Create( pszDestDataSource, 0, 0, 0,
                                         GDT_Unknown, papszDSCO );
    if( poODS == NULL )
    {
        fprintf( stderr,  "%s driver failed to create %s\n",
                pszFormat, pszDestDataSource );
        return OGRERR_FAILURE;
    }

    if(NULL == pszLayer)
        pszLayer = poSrcLayer->GetName();
    int nError;
    GetLayerAndOverwriteIfNecessary(poODS, pszLayer, TRUE, &nError);
    if(nError == TRUE)
    {
        return OGRERR_FAILURE;
    }

    // create layer
    OGRLayer * poLayer = poODS->CopyLayer(poSrcLayer, pszLayer, papszLCO);
    if (NULL == poLayer)
    {
        fprintf(stderr, "\nFAILURE: Can not copy path to %s\n",
                pszDestDataSource);
        GDALClose(poODS);

        return OGRERR_FAILURE;
    }

    if (bQuiet == FALSE)
    {
        printf("\nPath successfully copied and added to the network at %s\n",
            pszDestDataSource);
    }

    GDALClose(poODS);

    return OGRERR_NONE;
}