This project is read-only.

raster.saveas() not working with geotiff

Apr 29, 2014 at 6:58 PM
Edited Apr 29, 2014 at 8:26 PM
Hello!

I am trying to save a raster in geotiff format after a vector to raster convertion. But raster.saveas as is not working. I'm using the following code:
string rasterpath = "pathtomyraster.bgd";
var raster = DotSpatial.Analysis.VectorToRaster.ToRaster(shp, 0.01, fieldtoconvert, rasterpath);
raster.Projection = shp.Projection;
raster.SaveAs("pathtomyraster.tif");
I gives an exception saying that the specified file format is not supported. If I change pathtomyraster.bgd for pathtomyraster.tif, then the error comes in that line.


I guess it is happening because the GDAL extension is not loaded. What references do I need to add in order to make the .SaveAs work with geotiff formats without the need to load it as an extension?

Kind Regards,
Apr 29, 2014 at 7:27 PM
Yes, it seems that gdal extension is not loaded. The recommended way - to load this extension. It is quite easy - you need to create Plugins\Gdal folder in your output directory and copy all gdals dlls there (i assuming that you are using recommended 1.6 release - all gdals dlls located at Windows Extensions\GDAL folder).
After this you just need to add these two lines into your code:
var appManager = new AppManager();
appManager.LoadExtensions();
If you do not want to use gdal as extension, then again you need to ensure that all gdal dlls are in your output folder. After this you need to reference DotSpatial.Data.Rasters.GdalExtension.dll and use GdalRasterProvider directly.
Apr 29, 2014 at 8:50 PM
Thanks again, mogikanin. It worked after creating the folder and copying the extension and GDAL files, as you suggested.

On another note, I want to make a small contribution by providing a plugin to import data from Microsoft Access to a shapefile. This should be very similar to the "import excel table" feature that is present in DemoMap. Do you already have this feature? If not I would be glad to contribute, as I already have the functions working and just need to add the plugin functionality. Unfortunately, I could not complete the Extension tutorial, as the template doesn't work with VS express. Is there a possibility that the team will make a template for VS Express or extend the tutorial to include it?

Best

Márcio
Apr 30, 2014 at 7:44 AM
Sure, you are welcome to contributing! I think this plugin will be useful for other users. I don't know why template do not working with VS express. But you can create extension without it - just simply create inheritor of Extension class and override several methods. You can find a lot of examples how to create own extension in source code - e.g. the most simplest DotSpatial.Plugins.About.