Opened 10 years ago
Last modified 8 years ago
#5639 closed defect
GDALDriver::CreateCopy() fails for "USGSDEM" — at Initial Version
Reported by: | harishkumargvs | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | GDAL_Raster | Version: | unspecified |
Severity: | major | Keywords: | CreateCopy |
Cc: |
Description
Trying to create a DEM from in-memory data but, GDALDriver::CreateCopy() fails by returning NULL. Here's the code:
USES_CONVERSION; GDALDataset *poDST = NULL; OGRSpatialReference oSRS; char *prj4 = NULL; GDALAllRegister();
Get the GDAL driver GDALDriver *poDriver = NULL; poDriver = GetGDALDriverManager()->GetDriverByName("USGSDEM"); if (!poDriver) goto cleanup;
if (!poDriver->GetMetadataItem(GDAL_DCAP_CREATECOPY) poDriver->GetMetadataItem(GDAL_DCAP_CREATECOPY)[0] != 'Y') goto cleanup;
GDAL georeferencing double trf[6] = { 3102254.0400000000,
4.9999999999999973, 0.00000000000000000, 1764819.1100000001, 0.00000000000000000, -4.9999999999999973 };
Create an in memory dataset of the copy char inmem[256]; long nCols(137), nRows(225); float *pfData = (float*)malloc(nCols * nRows * sizeof(float)); if (!pfData) goto cleanup;
for (long idx = 0; idx < nCols * nRows; idx++)
pfData[idx] = (float) FLT_MAX; NoData values
sprintf_s(inmem, 256,
"MEM:::DATAPOINTER=0x%p," "PIXELS=%d," "LINES=%d," "BANDS=1," "DATATYPE=Float32," "PIXELOFFSET=4", pfData, nCols, nRows);
GDALDataset *poSRS = NULL; poSRS = (GDALDataset*)GDALOpen(inmem, GA_ReadOnly); if (!poSRS) goto cleanup;
if (poSRS->SetMetadataItem(GDALMD_AREA_OR_POINT, GDALMD_AOP_AREA)) goto cleanup;
if (poSRS->SetGeoTransform(trf)) goto cleanup;
GDALRasterBand* poBand = poSRS->GetRasterBand(1); if (!poBand) goto cleanup;
if (poBand->SetNoDataValue(FLT_MAX)) goto cleanup;
const wchar_t* path = L"Test.dem";
char szCSInfo[] = "PROJCS[\"NAD_1983_StatePlane_Colorado_Central_FIPS_0502\",GEOGCS[\"Longitude_Latitude\",DATUM[\"North_American_1983\",SPHEROID[\"GRS_1980\",6378137,298.2572221]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"\"],PARAMETER[\"Scale_Factor\",1.000000],PARAMETER[\"Standard_Parallel_1\",38.450000],PARAMETER[\"Standard_Parallel_2\",39.750000],PARAMETER[\"Central_Meridian\",-105.500000],PARAMETER[\"Latitude_Of_Origin\",37.833333],PARAMETER[\"False_Easting\",914401.828900],PARAMETER[\"False_Northing\",304800.609600],UNIT[\"Foot_US\",0.30480060960121920243840487680975]]"; char *sz = szCSInfo;
if (oSRS.importFromWkt(&sz)) goto cleanup;
if (oSRS.morphFromESRI()) goto cleanup;
if (oSRS.exportToWkt(&prj4) !prj4) goto cleanup;
if (poSRS->SetProjection(prj4)) goto cleanup;
Write the data to file poDST = poDriver->CreateCopy(W2A(path), poSRS, FALSE, NULL, NULL, NULL); if (!poDST)
goto cleanup;
cleanup:
if (pfData) {
free(pfData); pfData = NULL;
} if (prj4)
OGRFree(prj4);
if (poDST)
GDALClose(poDST);
if (poSRS)
GDALClose(poSRS);
Note: GDALDriver::CreateCopy() used to work fine with gdal17.dll versioned 1.7.2.0 but with gdal110.dll versioned 1.10.1.0 it fails...