@@ -506,8 +506,8 @@ void CPL_write_gdal(NumericMatrix x, CharacterVector fname, CharacterVector driv
506506
507507 // can this driver Create()?
508508 char **papszMetadata = poDriver->GetMetadata ();
509- if (!CSLFetchBoolean ( papszMetadata, GDAL_DCAP_CREATE, FALSE ) )
510- stop (" driver does not support Create() method." ); // #nocov
509+ if (!CSLFetchBoolean ( papszMetadata, GDAL_DCAP_CREATE, FALSE ) && ! CSLFetchBoolean ( papszMetadata, GDAL_DCAP_CREATECOPY, FALSE ) )
510+ stop (" driver does not support Create() or CreateCopy() method." ); // #nocov
511511
512512 // figure out eType:
513513 GDALDataType eType = GDT_Unknown;
@@ -552,7 +552,20 @@ void CPL_write_gdal(NumericMatrix x, CharacterVector fname, CharacterVector driv
552552 if (create) {
553553 if (from[0 ] != 0 || from[1 ] != 0 )
554554 stop (" from values should be zero when creating a dataset" ); // #nocov
555- if ((poDstDS = poDriver->Create ( fname[0 ], dims[0 ], dims[1 ], dims[2 ], eType,
555+
556+ if (poDriver->GetMetadataItem (GDAL_DCAP_CREATE) == NULL &&
557+ poDriver->GetMetadataItem (GDAL_DCAP_CREATECOPY) != NULL ) {
558+ GDALDriver *memDriver = GetGDALDriverManager ()->GetDriverByName (" MEM" );
559+ GDALDataset *memDS;
560+ if ((memDS = memDriver->Create (fname[0 ], dims[0 ], dims[1 ], dims[2 ], eType,
561+ create_options (options).data ())) == NULL )
562+ stop (" cannot create copy in memory" ); // #nocov
563+ if ((poDstDS = poDriver->CreateCopy (fname[0 ], memDS, FALSE , NULL , NULL , NULL )) == NULL ) {
564+ GDALClose (memDS);
565+ stop (" cannot CreateCopy from memory dataset" );
566+ } else
567+ GDALClose (memDS);
568+ } else if ((poDstDS = poDriver->Create ( fname[0 ], dims[0 ], dims[1 ], dims[2 ], eType,
556569 create_options (options).data ())) == NULL )
557570 stop (" creating dataset failed" ); // #nocov
558571
0 commit comments