<font face="courier new,monospace">Thanks Even, I appreciate it.<br><br>kss<br clear="all"></font><br>/**<br> *<br> * Kyle Shannon<br> * <a href="mailto:ksshannon@gmail.com" target="_blank">ksshannon@gmail.com</a><br> *<br>
*/<br><br><br>
<br><br><div class="gmail_quote">On Tue, May 10, 2011 at 15:41, Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@mines-paris.org">even.rouault@mines-paris.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Le mardi 10 mai 2011 17:39:52, Kyle Shannon a écrit :<br>
<div><div></div><div class="h5">> Even, here is the basic flow of my task. I am opening several subdatasets<br>
> in a for loop, warping them and populating an internal data structure.<br>
><br>
> #include "gdal_priv.h"<br>
> #include "gdalwarper.h"<br>
> #include "cpl_conv.h"<br>
> #include "cpl_port.h"<br>
> #include <string><br>
> #include <vector><br>
> int main()<br>
> {<br>
> GDALAllRegister();<br>
> /*<br>
> * Variable names for the netcdf forecast file<br>
> */<br>
><br>
> std::vector<std::string> varList;<br>
> varList.push_back( "Temperature_height_above_ground" );<br>
> varList.push_back( "V-component_of_wind_height_above_ground" );<br>
> varList.push_back( "U-component_of_wind_height_above_ground" );<br>
> varList.push_back( "Total_cloud_cover" );<br>
><br>
> std::string temp;<br>
> GDALDataset* srcDS;<br>
> GDALDataset* wrpDS;<br>
> GDALWarpOptions* psWarpOptions;<br>
> std::string srcWkt, dstWkt;<br>
> dstWkt = "PROJCS[\"WGS 84 / UTM zone 12N\",GEOGCS[\"WGS<br>
> 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS<br>
> 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174<br>
> 532925199433]],UNIT[\"metre\",1],PROJECTION[\"Transverse_Mercator\"],PARAME<br>
> TER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",-111],PARAMETE<br>
> R[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"<br>
> false_northing\",0]]";<br>
><br>
> /*<br>
> * Loop over variable names and open sub datasets<br>
> */<br>
><br>
> for( int i = 0;i < varList.size();i++ ) {<br>
><br>
> temp = "NETCDF:<a href="http://test.nc" target="_blank">test.nc</a>:" + varList[i];<br>
><br>
> srcDS = (GDALDataset*)GDALOpenShared( temp.c_str(), GA_ReadOnly );<br>
><br>
> srcWkt = srcDS->GetProjectionRef();<br>
><br>
> /*<br>
> * Grab the first band to get the nodata value for the variable,<br>
> * assume all bands have the same ndv<br>
> */<br>
> GDALRasterBand *poBand = srcDS->GetRasterBand( 1 );<br>
> int pbSuccess;<br>
> double dfNoData = poBand->GetNoDataValue( &pbSuccess );<br>
> psWarpOptions = GDALCreateWarpOptions();<br>
><br>
> int nBandCount = srcDS->GetRasterCount();<br>
> psWarpOptions->padfDstNoDataReal =<br>
> (double*) CPLMalloc( sizeof( double ) * nBandCount );<br>
> psWarpOptions->padfDstNoDataImag =<br>
> (double*) CPLMalloc( sizeof( double ) * nBandCount );<br>
> for( int b = 0;b < srcDS->GetRasterCount();b++ ) {<br>
> psWarpOptions->padfDstNoDataReal[b] = dfNoData;<br>
> psWarpOptions->padfDstNoDataImag[b] = dfNoData;<br>
> }<br>
> if( pbSuccess == false )<br>
> dfNoData = -9999.0;<br>
> psWarpOptions->papszWarpOptions =<br>
> CSLSetNameValue( psWarpOptions->papszWarpOptions,<br>
> "INIT_DEST", "NO_DATA" );<br>
><br>
> //set the dskWkt with an internal structure<br>
><br>
> wrpDS = (GDALDataset*) GDALAutoCreateWarpedVRT( srcDS, srcWkt.c_str(),<br>
> dstWkt.c_str(),<br>
> GRA_NearestNeighbour,<br>
> 1.0, psWarpOptions );<br>
><br>
> //copy warped data to internal structure<br>
><br>
> GDALDestroyWarpOptions( psWarpOptions );<br>
> GDALClose((GDALDatasetH) srcDS );<br>
> GDALClose((GDALDatasetH) wrpDS );<br>
> }<br>
> }<br>
><br>
<br>
</div></div>Of course, Valgrind has been helpfull once again (too bad you're on Windows<br>
;-))<br>
<br>
You just forgot : psWarpOptions->nBandCount = nBandCount;<br>
<div><div></div><div class="h5"><br>
> I am sure I am missing something.<br>
><br>
> kss<br>
><br>
> /**<br>
> *<br>
> * Kyle Shannon<br>
> * <a href="mailto:ksshannon@gmail.com">ksshannon@gmail.com</a><br>
> *<br>
> */<br>
><br>
> On Tue, May 10, 2011 at 03:51, Even Rouault <even.rouault@mines-<br>
<a href="http://paris.org" target="_blank">paris.org</a>>wrote:<br>
> > Selon Kyle Shannon <<a href="mailto:ksshannon@gmail.com">ksshannon@gmail.com</a>>:<br>
> > > I did have to set the padfNoDataImag array as well, so I am one step<br>
> > > closer. My new issue is ownership of my psWarpOptions. I assume that<br>
> ><br>
> > since<br>
> ><br>
> > > I create it, and the warp api tutorial implies that is it mine, I<br>
> > > destroy<br>
> ><br>
> > it<br>
> ><br>
> > > with GDALDestroyWarpOptions(). My problem is that AutoCreateWarpedVRT<br>
> > > appears to be stepping on my warp options when it destroys it's own<br>
> > > copy.<br>
> > ><br>
> > > I call AutoCreateWarpedVRT() and that function calls<br>
> > > GDALCloneWarpOptions(). When AutoCreateWarpedVRT destroys the copy it<br>
> ><br>
> > owns,<br>
> ><br>
> > > it appears to be stepping on my copy, and when I call<br>
> > > GDALDestroyWarpOptions(), I get a seg fault. Am I doing something<br>
> > > wrong?<br>
> ><br>
> > Difficult to say without seeing your code. Could you post a small<br>
> > self-sufficient code snippet that demonstrates your issue ?<br>
> ><br>
> > By reviewing the code, one potential issue would be if you try to free<br>
> > the pTransformerArg field by yourself, as it is freed by the destructor<br>
> > of the VRTWarpedDataset. But if you just use GDALDestroyWarpOptions(),<br>
> > it should work<br>
> > OK<br>
> ><br>
> > > kss<br>
> > ><br>
> > ><br>
> > ><br>
> > > /**<br>
> > ><br>
> > > *<br>
> > > * Kyle Shannon<br>
> > > * <a href="mailto:ksshannon@gmail.com">ksshannon@gmail.com</a><br>
> > > *<br>
> > > */<br>
> > ><br>
> > > On Mon, May 9, 2011 at 15:43, Even Rouault<br>
> > ><br>
> > > <<a href="mailto:even.rouault@mines-paris.org">even.rouault@mines-paris.org</a>>wrote:<br>
> > > > Le lundi 09 mai 2011 23:30:05, Kyle Shannon a écrit :<br>
> > > > > Thanks Even,<br>
> > > > > If that is the case, are there other values in psWarpOptions I<br>
> > > > > *have*<br>
> ><br>
> > to<br>
> ><br>
> > > > > set? I can't find docs discussing that.<br>
> > > ><br>
> > > > I don't think so, but you'll just have to try... I'm not surprised<br>
> > > > the docs<br>
> > > > don't talk about NaN. It is a corner case, and likely not really well<br>
> > > > supported in all places.<br>
</div></div></blockquote></div><br>