ToRaster method

Apr 13, 2011 at 8:10 PM


I am trying to convert vector data (FeatureSet) to raster. Method ToRaster ( doesn't work for me.

My code is below:

FeatureSet fs = new FeatureSet();            



DotSpatial.Analysis.VectorToRaster.ToRaster(fs, 250, "LENGTH", "D:\\raster.bgd");


It doesn't work when I try to save it to .asc format as well. It doesn't crash, it creates file of 1KB size.

When I try to open created file (in Raster object) I get an exeption:

"Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection."

I am using DotSpatial 2-12-2011 library version.

Thank you in advance!


Sep 13, 2012 at 3:50 PM

The same error in my code...

Any news about this? Has it been registered as bug / issue?

Sep 14, 2012 at 6:05 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Sep 14, 2012 at 6:15 PM

I think you are missing a line of code:


            var raster = DotSpatial.Analysis.VectorToRaster.ToRaster(fs, 250, "LENGTH", "C:\\raster.bgd");


Sep 17, 2012 at 7:23 AM

Thank you very much.

It does work!

Jul 1, 2013 at 6:58 PM
i used it too and work but i have another problem,
actually i write this code and i want to count each value .this code work but whenever i run it i get diffrent answer,it means i get diffrent numberValue matrix at each run.
      OpenFileDialog openShapfile = new OpenFileDialog();
        openShapfile.Filter = "shapfilefiles|*.shp";
        string filename = openShapfile.FileName;
        IFeatureSet fs = FeatureSet.Open(filename);

        var raster = DotSpatial.Analysis.VectorToRaster.ToRaster(fs, 0, "LU", "C:\\raster2.bgd");

        double[] m = new double[7] { 0, 1, 2, 3, 4, 5, 6 };
        double[] numberValue = new double[7];
        int count = 0;
        for (int i = 0; i < raster.NumRows; i++)
            for (int j = 0; j < raster.NumColumns; j++)
                for (int ii = 0; ii < 7; ii++)

                    if (raster.Value[i,j]==m[ii])
                        n[ii] = n[ii] + 1;