I'm using GDAL .Net wrapper, GDAL.Net.

I have a list of scattered points ( in X,Y,Z coordinates) that I would like to rasterized via the function GDAL_GRID( or via the underlying .Net wrapper, Gdal.wrapper_GDALGrid(). Currently this is what I do:

  1. I write the list of scattered points to CSV file
  2. Then I construct the .vrt file that maps to the previous CSV file, by using relevant .Net XML libraries.
  3. And then I use the GDAL.Dataset ds =Gdal.OpenEx(vrtFile, 0, null, null, null)) in .Net to read the contents of vrt file and CSV file into Gdal.Dataset, so that I can use the Gdal.wrapper_GDALGrid(tiffFile, ds, null, null, string.Empty) to create the raster file tiffFile.

Note that step 1 and 2 touch the file system, which I'm thinking of doing away with.

Is there anyway that I can create the GDAL.Dataset ds straight from the scattered points, all in memory, without writing the scattered points to CSV, and create vrt file on disk?


You should be able to follow a similar pattern to the "Writing to OGR" tutorial:

  • Create a new GDAL.Dataset object
  • Add a feature layer to store points
  • Use your geometry list to create Point objects
  • Add them to the feature layer
  • feed the Dataset object to GDAL Grid
  • Have you tried doing the above? I believe the above approach will work if you want to burn the point list direct into the Dataset, but I'm unsure if it works if you need to have vrt to refer to the point list
    – Graviton
    Dec 23 '18 at 7:50
  • You don't need a VRT - Grid(destName, srcDS, **kwargs): Args: destName --- Output dataset name, srcDS --- a Dataset object or a filename Dec 23 '18 at 18:10
  • Also it should be noted that currently the correct binding for Layers in GDAl.Dataset for GDAl.Net is missing.
    – Graviton
    Dec 24 '18 at 3:02
  • Bummer, that kills that strategy. Dec 24 '18 at 4:26
  • You have any more ideas on this?
    – Graviton
    Dec 24 '18 at 7:24

Built on Marc Pfister's answer, I can come up with a GDAL.Net version that works well, despite that the correct binding for Layers in GDAL.Dataset is missing.

Here's the code:

    private Dataset CreateDataset(List<Tuple<double,double,double>> csvData, string tempDir)
        var driverOgr = Ogr.GetDriverByName("ESRI Shapefile");
        var dsOgr= driverOgr.CreateDataSource(tempDir, null);
      var layerOgr =  dsOgr.CreateLayer("polyPoint", null, wkbGeometryType.wkbPoint25D, null);
        var fieldDef = new FieldDefn("location", 0);
        layerOgr.CreateField(fieldDef, 0);

        for(int i=0; i< csvData.Count; i++)
            using (var feature = new Feature(new FeatureDefn($"point {i}")))
                var geometry = new Geometry(wkbGeometryType.wkbPoint25D);
                geometry.SetPoint(0, csvData[i].Item1, csvData[i].Item2, csvData[i].Item3);


        //need to use this to work around the missing layer in Dataset binding, https://github.com/OSGeo/gdal/issues/918
        var dsGDAL = new Dataset(DataSource.getCPtr(dsOgr).Handle, false, null);
        return dsGDAL;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.