<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title></title>
</head>
<body style="font-family:Arial;font-size:14px">
<p>Hello,<br>
<br>
Can you be more specific about what steps you are suggesting I take, and how that would improve performance?<br>
Are you saying that gdalwarp-ing to gpkg is more performant than writing to VRT?<br>
<br>
I looked at the geopackage docs and it seems that all results are encoded as ARGB, so in the case where I do not have Float32 rasters, I think I would have some inefficiency. Also I guess I would have to specify PNG as the output, since I would have information loss with JPG? In general I don't understand it enough to try, it would help if you could expand a bit.<br>
<br>
What I have tried so far:<br>
<br>
1) Retrieve the dataset using "Gdal.wrapper_GDALWarpDestName(...)" (which works correctly):<br>
<br>
Dataset ds = Gdal.wrapper_GDALWarpDestName(memFilename, 1, dss, new GDALWarpAppOptions(options), null, null);<br>
<br>
2) Retrieve the projection, GeoTransform, and GCPs (GCPs were null)<br>
<br>
string projection = ds.GetProjection();<br>
...<br>
double[] geoTransform = new double[6];<br>
ds.GetGeoTransform(resultGeoTransform);<br>
...<br>
GCP[] resGcps = ds.GetGCPs();<br>
<br>
3) Retrieve the width and height of band 1 of "ds"<br>
<br>
Band band = ds.GetRasterBand(1);<br>
int xSize = band.XSize;<br>
int ySize = band.YSize;<br>
<br>
4) Create a new dataset with 1 band of the same width & height as retrieved in #3 (x size and y size were both 256, I just entered the literals here).<br>
<br>
Dataset newData = Gdal.GetDriverByName("VRT").Create(memFilename, 256, 256, 1, DataType.GDT_Float32, null);<br>
<br>
5) Set the projection and Geotransform as retrieved in #2, which seem to be the only two settable attributes (except GCPs which were null in the original)<br>
<br>
newData.SetProjection(projection);<br>
<br>
var newGeoTransform = new double[6];<br>
newGeoTransform[0] =geoTransform[0];<br>
newGeoTransform[1] = geoTransform[1];<br>
newGeoTransform[3] = geoTransform[3];<br>
newGeoTransform[5] = geoTransform[5];<br>
newData.SetGeoTransform(newGeoTransform);<br>
<br>
6) Use this dataset as the input to Gdal.wrapper_GDALWarpDestDS(...):<br>
<br>
int status = Gdal.wrapper_GDALWarpDestDS(newData, 1, dss, new GDALWarpAppOptions(options), null, null);<br>
<br>
This gave me a result of all null values :/<br>
<br>
Not sure where I am going wrong?<br>
<br>
<br>
Quoting Geospatial Information Technology Solutions <<a href="mailto:geospatialsolutions@gmail.com">geospatialsolutions@gmail.com</a>>:</p>
<blockquote style="border-left:2px solid blue;margin-left:2px;padding-left:12px;" type="cite">
<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"> </div>
</div>
</div>
<br>
<div class="gmail_quote">
<div class="gmail_attr" dir="ltr">On Thu, Oct 10, 2019, 5:51 PM <<a href="mailto:mladen-g@distributel.net">mladen-g@distributel.net</a>> wrote:</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p><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" rel="noreferrer" target="_blank">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></p>
</blockquote>
</div>
</blockquote>
<p><br>
<br></p>
</body>
</html>