This project is read-only.

Create new Raster

Feb 12, 2011 at 5:44 PM

I want to create a new raster through code (.asc - ASCII grid file format). The raster should have 10meter cell size, 500 rows, 500 columns, and lower left corner at [458591 , 4649897] (UTM zone 12). Data type should be "double" data type. Initial value of all cells should be 1.0.

  1. Which method to use to create the raster? (Raster.Create(), new Raster(), new DoubleRaster() ?? there's lots of different methods - I'm confused)
  2. How to assign the cell size, and lower left corner?
  3. How to set values of the raster?
  4. How to save the raster to a file?

Are there any examples in DotSpatial code that I could use to get started?

Feb 18, 2011 at 12:16 AM

Answer to the questions can be found in DotSpatial Tutorial 3

(Raster data operations in DotSpatial)

Apr 9, 2012 at 5:31 PM

I'm with jirikadlec2.

- which method use to create rasters? 'Create' or 'CreateRaster' (after the documentation they are exactly the same)

- how to set-up the header (coordinates of origin, null values)?

- and most importantly, what are the 'options to be used'  when using 'Create' or 'CreateRaster'


Apr 9, 2012 at 8:50 PM

BTW, the correct link to that tutorial is

Jul 25, 2012 at 1:40 PM
Edited Jul 25, 2012 at 1:40 PM


I was also looking for a code sample for creating a new raster.

Unfortunately tutorial 3 doesn't help me. First, it transfers some of the variables from an existing raster, and doesn't set them directly. Second it's in C#.

So I tryed to convert it to VB.Net and keep it as simple as possible with the following code:

        Dim rasterOptions As String()
        rasterOptions = New String(0) {}
        Dim newRaster As IRaster
        newRaster = Raster.CreateRaster("C:\Temp\testraster.bgd", Nothing, 50, 50, 1, System.Type.GetType(7), rasterOptions)

But I always get an error 'The specified file type is not supported'.

and I can't find out where I'm wrong, though I hink the bug is in rasterOptions.

Jul 26, 2012 at 8:10 AM

Meanwhile I found another sample code and wrote some code that at least creates a .bgd Raster.

Dim newRaster As New DotSpatial.Data.Raster
        newRaster = DotSpatial.Data.Raster.CreateRaster("C:\temp\test3.bgd", "", ncols, nrows, 1, GetType(Double), myRasterOptions)
        newRaster.Bounds = New DotSpatial.Data.RasterBounds(nrows, ncols, myExtend)      

With every other extension than .bgd or Ohter dataType i still get the same error message 'The specified file type is not supported.'

Is it because of a missing drivercode? Where do I get that from?

Jul 27, 2012 at 8:20 PM
Edited Jul 27, 2012 at 8:20 PM

I would bet that bgd is the only file type that is supported by default. If you add the Gdal extension, you might get more types.

Jul 31, 2012 at 10:44 PM

Please excuse me,

I followed your tutorial ( to support loading extensions step by step. 

You write: "Copy the Data Extensions/GDAL folder from the location where you downloaded DotSpatial".

The location where I unzipped DotSpatial (C:\dev\) contains no folder named 'Data Extensions'.
There's a folder named 'Application Extensions', but that doesn't contain a subfolder named GDAL.
In the Plugins folder (C:\dev\Plugins) there is a subfolder named GDAL. But when I copy this to my bin\Debug\Plugins folder I still get the same error message 'The specified file type is not supported.' So there is no GDAL support.

Where am I wrong?