Quantcast
Channel: DotSpatial
Viewing all articles
Browse latest Browse all 3973

New Post: Convert shapefile to raster

$
0
0
Oscarafone77 wrote:
You should have a look at the DotSpatial.Analysis.VectorToRaster.ToRaster method and the parameters it requires and the work is done

Oscar
Hi

This method doesn't work correctly. I special a cell size of 5, but the raster I got has a cell height of 4.69xxxx, and a cell width of 4.99xxxxx.

Here is my code:
            string shpFile = @"E:\Project\TestData\UpCatchment.shp";
            double xMin = 82292.591;
            double yMin = 81549.981;
            double xMax = 82851.763;
            double yMax = 81599.988;
            double cellsize = 5;
            IFeatureSet fs = FeatureSet.Open(shpFile);
            fs.FillAttributes();
            fs.DataTable.Columns.Add("myField");
            for (int i = 0; i < fs.Features.Count; i++)
            {
                fs.Features[i].DataRow.BeginEdit();
                fs.Features[i].DataRow["myField"] = 1;
                fs.Features[i].DataRow.EndEdit();
            }
            Extent extent = new Extent(new double[] {xMin, yMin, xMax,yMax});
            IRaster raster = VectorToRaster.ToRaster(fs, cellsize, "myField", "output.bgd", "", new string[] { }, null);

Viewing all articles
Browse latest Browse all 3973

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>