GDAL矢量栅格化
}
const char *pszFormat = “GTiff”;
GDALDriver *poDriver;
poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
// if( poDriver == NULL )
// exit( 1 );
GDALDataset *poNewDS = poDriver->Create( pszOutFileName, m_nImageWidth,m_nImageHeight,1, GDT_Float32 , NULL );
if ( !poSRS )
{
// strErr.Format(“因为无地理信息,%s无法栅格化”,m_strInputV);
// AfxMessageBox(strErr);
// return strErr;
//fot jy
double adfGeoTransform[6];
adfGeoTransform[0] = psExent.MinX;
adfGeoTransform[1] = (psExent.MaxX – psExent.MinX)/m_nImageWidth;
adfGeoTransform[2] = 0;
adfGeoTransform[3] = psExent.MaxY;
adfGeoTransform[4] = 0;
adfGeoTransform[5] = (psExent.MinY – psExent.MaxY)/m_nImageHeight;
GDALSetGeoTransform( poNewDS, adfGeoTransform );
// OGRSpatialReference * poOGRSR;
// poOGRSR->SetUTM(50);
// poSRS->exportToWkt(&pszProjection);
// poNewDS->SetProjection(pszProjection);
//for jy
}
else
{
double adfGeoTransform[6];
adfGeoTransform[0] = psExent.MinX;
adfGeoTransform[1] = (psExent.MaxX – psExent.MinX)/m_nImageWidth;
adfGeoTransform[2] = 0;
adfGeoTransform[3] = psExent.MaxY;
adfGeoTransform[4] = 0;
adfGeoTransform[5] = (psExent.MinY – psExent.MaxY)/m_nImageHeight;
GDALSetGeoTransform( poNewDS, adfGeoTransform );
poNewDS->SetProjection(pszProjection);
}
// GDALDatasetH poDstDs;
// poDstDs = (GDALDatasetH)poNewDS;//GDALOpen(pszOutFileName,GA_Update);
int * pnbandlist;
pnbandlist = new int [1];
pnbandlist[0]=1;
double *dburnValues;
dburnValues = new double[1];
dburnValues[0]=255;
OGRLayerH * player;
player = new OGRLayerH[1];
player[0] = (OGRLayerH)poLayer;
// poLayer->GetInfo()
char **papszOptions = NULL;
// papszOptions = CSLSetNameValue( papszOptions, “ALL_TOUCHED”, “TRUE” );
// papszOptions = CSLSetNameValue( papszOptions, “ATTRIBUTE”, “Band1Mean” );
papszOptions = CSLSetNameValue( papszOptions, “CHUNKSIZE”, “1” );
papszOptions = CSLSetNameValue( papszOptions, “ATTRIBUTE”, m_strPara );
// AfxMessageBox(“start”);
// CPLErr err= GDALRasterizeLayers(poDstDs,1,pnbandlist,1,player,NULL,NULL,dburnValues,papszOptions,NULL,NULL);
// void * pTransformArg;
// pTransformArg = GDALCreateApproxTransformer();
void * pTransformArg=NULL;
void * m_hGenTransformArg=NULL;
m_hGenTransformArg = GDALCreateGenImgProjTransformer( NULL,
pszProjection,
(GDALDatasetH)poNewDS,
poNewDS->GetProjectionRef(),
FALSE, 1000.0, 3 );
pTransformArg = GDALCreateApproxTransformer( GDALGenImgProjTransform,m_hGenTransformArg, 0.125 );
CPLErr err= GDALRasterizeLayers((GDALDatasetH)poNewDS,1,pnbandlist,1,player,GDALGenImgProjTransform,m_hGenTransformArg,NULL,papszOptions,GDALTermProgresscjs,”矢量栅格化”);
// AfxMessageBox(“end”);
// CPLErr err= GDALRasterizeLayers(po
// DstDs,1,pnbandlist,1,player,NULL,NULL,NULL,papszOptions,NULL,NULL);
GDALDestroyGenImgProjTransformer(m_hGenTransformArg);
GDALDestroyApproxTransformer(pTransformArg);
GDALClose(poNewDS);
OGR_DS_Destroy( poDS );
// GDALClose( poDstDs );
delete[]player;
delete[]pnbandlist;
delete[]dburnValues;
strErr = “栅格化成功”;
return strErr;
}
转载自:https://blog.csdn.net/haojknm/article/details/5854317