Example #1
0
OGRDataSourceH OGR_Dr_CreateDataSource( OGRSFDriverH hDriver,
                                        const char *pszName, 
                                        char ** papszOptions )

{
    VALIDATE_POINTER1( hDriver, "OGR_Dr_CreateDataSource", NULL );

    OGRSFDriver* poDriver = (OGRSFDriver *) hDriver;
    CPLAssert( NULL != poDriver );

    OGRDataSource* poDS = NULL;
    poDS = poDriver->CreateDataSource( pszName, papszOptions );

    /* This fix is explained in Ticket #1223 */
    if( NULL != poDS )
    {
        poDS->SetDriver( poDriver );
        CPLAssert( NULL != poDS->GetDriver() );
    }
    else
    {
        CPLDebug( "OGR", "CreateDataSource operation failed. NULL pointer returned." );
    }

    return (OGRDataSourceH) poDS;
}
Example #2
0
OGRDataSourceH OGR_Dr_Open( OGRSFDriverH hDriver, const char *pszName, 
                            int bUpdate )

{
    VALIDATE_POINTER1( hDriver, "OGR_Dr_Open", NULL );

    OGRDataSource *poDS = ((OGRSFDriver *)hDriver)->Open( pszName, bUpdate );

    if( poDS != NULL && poDS->GetDriver() == NULL )
        poDS->SetDriver( (OGRSFDriver *)hDriver );

    return (OGRDataSourceH) poDS;
}
Example #3
0
OGRDataSource *OGRSFDriver::CopyDataSource( OGRDataSource *poSrcDS, 
                                            const char *pszNewName,
                                            char **papszOptions )

{
    if( !TestCapability( ODrCCreateDataSource ) )
    {
        CPLError( CE_Failure, CPLE_NotSupported, 
                  "%s driver does not support data source creation.",
                  GetName() );
        return NULL;
    }

    OGRDataSource *poODS;

    poODS = CreateDataSource( pszNewName, 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 );
    }

    /* Make sure that the driver is attached to the created datasource */
    /* It is also done in OGR_Dr_CopyDataSource() C method, in case */
    /* another C++ implementation forgets to do it. Currently (Nov 2011), */
    /* this implementation is the only one in the OGR source tree */
    if( poODS != NULL && poODS->GetDriver() == NULL )
        poODS->SetDriver( this );

    return poODS;
}
Example #4
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 );

    OGRDataSource* poDS =
        ((OGRSFDriver *) hDriver)->CopyDataSource( 
            (OGRDataSource *) hSrcDS, pszNewName, papszOptions );

    /* Make sure that the driver is attached to the created datasource */
    /* if not already done by the implementation of the CopyDataSource() */
    /* method */
    if( poDS != NULL && poDS->GetDriver() == NULL )
        poDS->SetDriver( (OGRSFDriver *)hDriver );

    return (OGRDataSourceH)poDS;
}