This project is read-only.

Use GDAL in VB-Project

Aug 6, 2014 at 1:49 PM
Hello,

I'm using DotSpatial in my VB-Project and came to the point where i have to create a raster data file.
The problem is, that DotSpatial itself only offers to save raster data as .bgd files, what, in my case, is not enough, because i need to export my raster as .asc to open it in QuantumGIS...
So I found out, that I have to load the GDAL-Extension to enlarge the offer of supported data types like asc for example.

Now I came to the point, that even after following the instructions, I get the message to include IDockManager, IHeaderControl and IStatusControl to my form....

My Question:
Cause I already have a UI, I just want to use GDAL and Dotspatial as a Library to work with geodata, how may I resolve this problem?

Thanks
SilesianPower
Aug 6, 2014 at 2:05 PM
Hi,

what DS version you are using? In latest (1.7) there is no message about IDockManager, etc. In 1.7 there are default implementations of those interfaces.
And the second question - what instructions you followed? Probably they out of date...
And the third - if you already have an UI, and you do not want to use any other GUI plugins which require that implementations of IDockManager\IHeaderControl and IStatusControl must exists, then you just can include empty implementations of them into your application.

Maxim.
Aug 6, 2014 at 2:21 PM
1) I'm using DS 1.7, but somehow I get these warnings
2) http://mudnug.wordpress.com/2011/11/23/how-to-support-loading-extensions-in-dotspatial/
3) I tried it like you said, but nevertheless, I get the ErrorMessage, that the ending .asc file type is not supported

SilesianPower
Aug 6, 2014 at 2:57 PM
  1. Yes, you are right, there are some messages in other place. I thought that we already removed them all...
  2. Yes, that link is out of date. I'll update documentation regarding GDAL on Codeplex soon.
  3. I've tried to include empty implementation into my sample application, and got the error too. There is a bug (still) in 1.7 with IHeaderControl interface. You have to add [Export] attribute to your empty implementation of IHeaderControl, C#:
    [Export(typeof(IHeaderControl))] // THIS ATTRIBUTE REQUIRED!
    public class MyHeaderControl : IHeaderControl
    {
        public void Add(HeaderItem item)
        {
            
        }
        // Skipped other methods
    }
For other classes you may not add this attribute.
Also, check that in your output folder there is an Plugins\DotSpatial.Data.Rasters.GdalExtension\ folder with all gdal dlls.
Aug 6, 2014 at 3:11 PM
  1. So if this link is out of date, is there anything I have to change in they way I load the gdal extensions (facing the instructions)?
  2. I'm using Visual Basic and on the other hand I dont understand what I should do now, sorry :S
Yes, in my Debug Folder, there is a folder Plugins\Dotspatial.Data.Rasters.GdalExtensions with all the content it came with by the DS-Download
Aug 6, 2014 at 3:20 PM
In VB.Net it will be
<Export(GetType(IHeaderControl))>
Public Class MyHeaderControl 
        Implements IHeaderControl
...........
You not need change bitness of your app as described at that link. At the moment GDAL extension supports AnyCPU mode.
Just call appManager1.LoadExtensions(); somewhere inside your mainform constructor.
Feb 21, 2015 at 6:42 PM
Hello,
I already tried to work with GDAL in Dotspatial about two years ago and failed. Now I have I new project that has to deal with rasters and I started a new attempt.

The Tutorials concerning GDAL (i.e. (3), (6), (9)) say "Copy the Data Extensions folder from the downloaded folder to the current project’s Bin\ Debug folder. "
I downloaded the latest Dotspatial release (1.7), but there's no folder named 'Data Extensions'. Neither in all the previous releases, that I downloaded before.

http://mudnug.wordpress.com/2011/11/23/how-to-support-loading-extensions-in-dotspatial/ refers to dotspatial 1.0 so thats probably outdated as well. As mogiknin said 'Yes, that link is out of date. I'll update documentation regarding GDAL on Codeplex soon. '

So my question is: Is there an up to date Tutorial on how to use GDAL in a Dotspatial project?
Or could someone try to tell me how it works in a few simple words?

Thanks in advance!
Claudia
Feb 25, 2015 at 2:14 AM
Edited Feb 26, 2015 at 3:02 AM
I use version 1.7, and I load GDAL as follow:
  1. Copy GDAL extension into \Bin\Debug\Windows Extensions
  2. Load Extensions (GDAL) in Code of MainForm
Imports System.ComponentModel.Composition
    <Export("Shell", GetType(ContainerControl))> _
          Private Shared Shell As ContainerControl
    Public Sub New()
        Dim AppManager11 = New DotSpatial.Controls.AppManager()
        Shell = Me
        AppManager11.LoadExtensions()
        InitializeComponent()
    End Sub
GIS for Sustainable Development
mua đàn piano, bán đàn piano Nhật bản
http://muabanpiano.net
Jan 14, 2016 at 4:18 AM
Edited Jan 14, 2016 at 4:33 AM
Hi,
Having worked with DotSpatial for some time now, and I tried again to get the GDAL plugin to work using DotSpatial 1.8. Only to fail having spent lots of time trying about all suggested solutions. I keep on bumping into the IHeaderControl requirement that still seems to be needed (a long-standing bug I believe). Like others, I can't find the promised tutorial.

I would like to hear if anybody got GDAL to work under DotSpatial 1.8 and VS 2015, preferable using vb.net. Or even if they know an alternative way of loading .asc rasters onto a map?

For you out there with the same problem: the DotSpatial IHeader interface demands Add, Remove, RemoveAll, SelectRoot, and IHeaderControl_Add to be implemented, even if it is with empty methods:

<Export(GetType(IHeaderControl))>
Public Class MyHeaderControl
Implements IHeaderControl

Public Event RootItemSelected As EventHandler(Of RootItemEventArgs) Implements IHeaderControl.RootItemSelected
Public Sub Add(item As HeaderItem)
End Sub

Public Sub Remove(key As String) Implements IHeaderControl.Remove
End Sub

Public Sub RemoveAll() Implements IHeaderControl.RemoveAll
End Sub

Public Sub SelectRoot(key As String) Implements IHeaderControl.SelectRoot
End Sub

Private Sub IHeaderControl_Add(item As HeaderItem) Implements IHeaderControl.Add
End Sub

End Class

Sorry for the way the editor treats my code snippet.

You also need Imports System.ComponentModel.Composition to be able to export.

My latest error is:
An unhandled exception of type 'System.Resources.MissingManifestResourceException'.
which indicates that there is something wrong with the name of my extension.
Any help would be appreciated.
Jan 14, 2016 at 10:11 AM
Hello pan,

do you need IHeaderControl to be empty?

If not there is a working IHeaderControl inside DotSpatial.Controls that should be loaded automatically. That means if you download the DotSpatial 1.8 dlls and remove all plugins and windows extensions (leave gdal) DemoMap is still working because default implementations of IHeaderControl, IStatusControl and IDockManager are contained in DotSpatial.Controls.dll.

If you need IHeaderControl to be empty have a look at the current Source Code. I added the DummyHeaderControl library to Trunk / Examples. If you compile this and add it to your plugin folder you should have a working empty header control.

jany_
Jan 14, 2016 at 8:48 PM
**jany_ wrote:**
Hello pan,

do you need IHeaderControl to be empty?

If not there is a working IHeaderControl inside DotSpatial.Controls that should be loaded automatically. That means if you download the DotSpatial 1.8 dlls and remove all plugins and windows extensions (leave gdal) DemoMap is still working because default implementations of IHeaderControl, IStatusControl and IDockManager are contained in DotSpatial.Controls.dll.

If you need IHeaderControl to be empty have a look at the current Source Code. I added the DummyHeaderControl library to Trunk / Examples. If you compile this and add it to your plugin folder you should have a working empty header control.

jany_
Dear jany
Could you please help me with the best wahy to perform raster calculate using gdal?Is it possible?I should do calculation pixel by pixel?How can I consider extend of rasters and things like cell size and .. to do in raster algabra?
I need some ideas how is the best to do it
Jan 15, 2016 at 6:42 AM
Edited Jan 15, 2016 at 9:10 AM
Hi Jany,

Thanks for responding.
After:
1 going back to DS V1.7 (from DS 1.8),
2 using the DotSpatial controls SpatialDockManager, SpatialHeaderManager, SpatialStatusStrip on my form,
3 assign these to the properties on the AppManager, together with the map and legend controls
4 adding a reference to the mono.dll
it is now working.

I found that Ted Dunsford's mini-instruction manual on
http://stackoverflow.com/questions/29122130/raster-data-loading-from-filepath-in-dotspatial/29803545#29803545 was really useful.

Pity that Gdal doesn't seem to support .asc files after all :).

Cheers
Francis
Jan 15, 2016 at 9:51 AM
Hey Francis,

the 4 steps you made should work with DS 1.8 as well.

Are you sure that gdal doesn't support .asc files?
I don't have any .asc files to really test this but I created an empty dummy .asc file. Then I clicked on the load layer button in DemoMap and could have selected the dummy .asc file when "All supported files" was selected for file type.

jany_
Jan 15, 2016 at 7:50 PM
Edited Jan 15, 2016 at 11:09 PM
Hi Jany_
I started a test application from scratch and got it to work with all DS controls and DS V1.8 and for .Net 4.5.2.
and AnyCPU project settings. The GDAL extension is not 'seen' by the application manager as a real extension ( AppManager1.Extensions.Count = 0) and it would be nice to know the difference between plugins and extensions.

However, when loading a layer, the gdal raster options do appear, including the .asc files, and the .asc file is loaded correctly.

Thanks for your help!
Cheers
Francis
Jan 22, 2016 at 3:48 AM
Hi
I'm also new to dotSpatial and am pretty impressed. Using v1.8 along with Tutorials 3 + 9, I can add GDAL raster to map .

For native bgd raster format I can use IRaster to access the pixels:
        Dim pRlyr As IMapRasterLayer = Map1.Layers(0)
        Dim demRaster As IRaster = pRlyr.DataSet
I've tried this for a GDAL raster:
 Dim pRlyr As MapImageLayer = DirectCast(Map1.Layers.SelectedLayer, MapImageLayer)
But pRlyr.Datasets is an IImageData and I can't figure out how to get IRaster or pixels (ie iterate through rows and columns).

Can anyone point me in the right direction?

Thanks

Tim
Jan 23, 2016 at 11:35 PM
Edited Jan 24, 2016 at 1:42 AM
Hi Jany_

I'm running into a little problem with the AppManager (V1.8).
When calling AppManager1.LoadExtensions it traps and error ''Object reference not set to an instance of an object".
Drilling down a bit it, it seems to have a problem with the header control. I use a dummy header control to keep DotSpatial happy. Also, as V1.8 does not have a toolstrip object anymore, I use the one that comes with VS. I did try to initialise the header control, but the error just shifts to that line of code.
Any suggestions?

Details of the error:
" at DotSpatial.Controls.Header.MenuBarHeaderControl.LoadToolstrips() in c:\Users\Matt\Documents\DotSpatial1.8\dotspatial\Trunk\DotSpatial.Controls\Header\MenuBarHeaderControl.cs:line 284" & vbCrLf & " at DotSpatial.Controls.AppManager.OnExtensionsActivated(EventArgs ea) in c:\Users\Matt\Documents\DotSpatial1.8\dotspatial\Trunk\DotSpatial.Controls\AppManager.cs:line 439" & vbCrLf & " at DotSpatial.Controls.AppManager.LoadExtensions() in c:\Users\Matt\Documents\DotSpatial1.8\dotspatial\Trunk\DotSpatial.Controls\AppManager.cs:line 411" & vbCrLf & " at NewCatchmentPlanner.ucDotSpatial..ctor() in D:\Development\NewCatchmentPlanner\CatchmentPlanner\ucDotSpatial.vb:line 19" " at DotSpatial.Controls.Header.MenuBarHeaderControl.LoadToolstrips() in c:\Users\Matt\Documents\DotSpatial1.8\dotspatial\Trunk\DotSpatial.Controls\Header\MenuBarHeaderControl.cs:line 284" & vbCrLf & " at DotSpatial.Controls.AppManager.OnExtensionsActivated(EventArgs ea) in c:\Users\Matt\Documents\DotSpatial1.8\dotspatial\Trunk\DotSpatial.Controls\AppManager.cs:line 439" & vbCrLf & " at DotSpatial.Controls.AppManager.LoadExtensions() in c:\Users\Matt\Documents\DotSpatial1.8\dotspatial\Trunk\DotSpatial.Controls\AppManager.cs:line 411" & vbCrLf & " at NewCatchmentPlanner.ucDotSpatial..ctor() in D:\Development\NewCatchmentPlanner\CatchmentPlanner\ucDotSpatial.vb:line 19" String
Jan 26, 2016 at 10:01 AM
Hey pan,

as far as I remember there was nothing removed in V1.8. I think the reason for the missing toolstrip object would be that it is no longer shown in the VS designer toolbox.

You say you are using a dummy header control but you get an error inside MenuBarHeaderControl which is the default header control included in DotSpatial.
I'm sorry but I can't figure out where your error comes from without having a look at the code you're running.

Why do you use a dummy header control anyway?