<div dir="auto">Why not build an OGC gpkg GEOPACKAGE it supports 4326 tiles <div dir="auto">you can extract the tile_data blob if you need to</div><div dir="auto"><div dir="auto"><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 10, 2019, 5:51 PM  <<a href="mailto:mladen-g@distributel.net">mladen-g@distributel.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hello,<br>
<br>
I've been using GDAL for a while, but I am still a newbie to the API.   <br>
I see there are some experts on this group, so apologies if I'm asking  <br>
something simple (my searches did not reveal the answers I was looking  <br>
for).<br>
<br>
Here is my problem:<br>
<br>
I need to take an input raster, split into areas of various sizes,  <br>
resample each area into a 256x256 tile, reproject to EPSG:4326 and  <br>
send the resulting pixels to a DB.<br>
<br>
GDAL is perfect for this, but I am using the C# bindings and I'm not  <br>
sure what is the most performant way to do it.<br>
<br>
I used the following two references to create something that works,  <br>
but I am wondering if it can be improved:<br>
<a href="https://gis.stackexchange.com/questions/297831/using-gdalwarp-with-c-bindings" rel="noreferrer noreferrer" target="_blank">https://gis.stackexchange.com/questions/297831/using-gdalwarp-with-c-bindings</a><br>
<a href="https://lists.osgeo.org/pipermail/gdal-dev/2017-February/046046.html" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/pipermail/gdal-dev/2017-February/046046.html</a><br>
<br>
How I do it right now:<br>
<br>
1)  Copy the input grid to RAM disk for fast access<br>
2)  Invoke Gdal.wrapper_GDALWarpDestName() for reprojection,  <br>
resampling, and output to a /vsimem/ memory-mapped file<br>
3)  Read the memory-mapped file into a Dataset (returned by  <br>
wrapper_GDALWarpDestName())<br>
4)  Write the Dataset values to DB<br>
<br>
What I would like to know:<br>
<br>
1)  To skip the /vsimem file creation, how can I use  <br>
Gdal.wrapper_GDALWarpDestDs() instead of -DestName?  It requires a  <br>
dataset as a parameter, but I am not sure how to initialize it  <br>
correctly.  I've tried Gdal.GetDriverByName("VRT").Create(...) and  <br>
.GetDriverByName("MEM").Create(...), but all the values end up being 0  <br>
when I pass the dataset to wrapper_GDALWarpDestDs()?<br>
<br>
2)  Is there a more direct, efficient way to do what I'm doing?  Here  <br>
is the relevant code<br>
<br>
<snip><br>
using (Dataset rasterInput = Gdal.Open(inputRasterPath, Access.GA_ReadOnly))<br>
{<br>
   IntPtr[] ptr = {Dataset.getCPtr(inputRasterPath).Handle};<br>
   GCHandle gcHandle = GCHandle.Alloc(ptr, GCHandleType.Pinned);<br>
...<br>
    var dss = new  <br>
SWIGTYPE_p_p_GDALDatasetShadow(gcHandle.AddrOfPinnedObject(), false,  <br>
null);<br>
..<br>
    foreach (var tileExtent in overlappingTileExtents) // tileExtent  <br>
just contains minX/minY/maxX/maxY<br>
    {<br>
    ...<br>
<br>
       string vsiMemFilePath =  <br>
$"/vsimem/{destinationTableName}#{extentName}#tile{indexNumber}.vrt";<br>
       string[] options = {<br>
                                 "-of", "VRT",<br>
                                 "-srcnodata", "99999.9",<br>
                                 "-dstnodata", "99999.9",<br>
                                 "-ot", "Float32",<br>
                                 "-t_srs", "EPSG:4326",<br>
                                 "-r", "average"),<br>
                                 "-te", tileExtent.xmin.ToString(),  <br>
tileExtent.ymin.ToString(), tileExtent.xmax.ToString(),  <br>
tileExtent.ymax.ToString(),<br>
                                 "-ts", "256", "256"<br>
                             };<br>
<br>
        using (Dataset ds =  <br>
Gdal.wrapper_GDALWarpDestName(vsiMemFilePath, 1, dss, new  <br>
GDALWarpAppOptions(options), null, null))<br>
        {<br>
...<br>
          //read the geotransform + first band and write each pixel  <br>
lat/long + value to the DB<br>
...<br>
        }<br>
<br>
     Gdal.Unlink(vsiMemFilePath)<br>
<br>
....<br>
<br>
Regards,<br>
Mladen<br>
<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" rel="noreferrer">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a></blockquote></div>