<font face="courier new,monospace">Even, here is the basic flow of my task. I am opening several subdatasets 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 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],UNIT[\"metre\",1],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",-111],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"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">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>I am sure I am missing something.<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 03:51, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Selon Kyle Shannon <<a href="mailto:ksshannon@gmail.com">ksshannon@gmail.com</a>>:<br>
<div class="im"><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 since<br>
> I create it, and the warp api tutorial implies that is it mine, I destroy it<br>
> with GDALDestroyWarpOptions(). My problem is that AutoCreateWarpedVRT<br>
> appears to be stepping on my warp options when it destroys it's own copy.<br>
><br>
> I call AutoCreateWarpedVRT() and that function calls<br>
> GDALCloneWarpOptions(). When AutoCreateWarpedVRT destroys the copy it owns,<br>
> it appears to be stepping on my copy, and when I call<br>
> GDALDestroyWarpOptions(), I get a seg fault. Am I doing something wrong?<br>
<br>
</div>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 the<br>
pTransformerArg field by yourself, as it is freed by the destructor of the<br>
VRTWarpedDataset. But if you just use GDALDestroyWarpOptions(), it should work<br>
OK<br>
<div><div></div><div class="h5"><br>
><br>
> kss<br>
><br>
><br>
><br>
> /**<br>
> *<br>
> * Kyle Shannon<br>
> * <a href="mailto:ksshannon@gmail.com">ksshannon@gmail.com</a><br>
> *<br>
> */<br>
><br>
><br>
><br>
><br>
> On Mon, May 9, 2011 at 15:43, Even Rouault<br>
> <<a href="mailto:even.rouault@mines-paris.org">even.rouault@mines-paris.org</a>>wrote:<br>
><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 *have* to<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 the<br>
> > docs<br>
> > don't talk about NaN. It is a corner case, and likely not really well<br>
> > supported in all places.<br>
> ><br>
><br>
<br>
<br>
</div></div></blockquote></div><br>