Create new Raster

Developer
Feb 12, 2011 at 4: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?

Developer
Feb 17, 2011 at 11:16 PM

Answer to the questions can be found in DotSpatial Tutorial 3

(Raster data operations in DotSpatial)

Apr 9, 2012 at 4: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'

Thanks

Developer
Apr 9, 2012 at 7:50 PM

BTW, the correct link to that tutorial is http://download.codeplex.com/Download?ProjectName=dotspatial&DownloadId=280725

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

Hello,

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 7: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?

Developer
Jul 27, 2012 at 7:20 PM
Edited Jul 27, 2012 at 7: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 9:44 PM

Please excuse me,

I followed your tutorial (http://mudnug.wordpress.com/2011/11/23/how-to-support-loading-extensions-in-dotspatial/) 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?