Beginner - GDalRasterLayer

Topics: SharpMap v0.9 / v1.x
Sep 28, 2009 at 1:23 PM

Hi,

I'm SharpMap beginner and I develop in C# (not a beginner in C#).

I started with 0.9 release that came with InstallWizard. I could display image (with PictureImage).

Now, I am using SharpMap trunk 59103.

I would like to display a tif map (not georeferenced) to plot few points on.

I used GDALRasterLayer to load a TIF image, this way :

1/ SharpMap.Layers.GdalRasterLayer layer;
2/ layer = new SharpMap.Layers.GdalRasterLayer("GeoTIFF", @"Map.TIF");
3/ map.Layers.Add(layer);

Line 2/ throws an exception : TypeInitializationException

File Map.TIF exists.

First Argument ("GeoTIFF") I choose is from an Example, but I understood this was just the name of my layer : is that name Important ?

 

If anybody can help me.

Thanks,

JL

 

 

 

Coordinator
Sep 28, 2009 at 3:42 PM

Hi JL please see http://sharpmap.codeplex.com/Wiki/View.aspx?title=Configure%20GDAL%20%20OGR%20FWTools%20%28as%20of%20revision%2057193%29&referringTitle=Home 

Sep 28, 2009 at 5:44 PM

Hi,

Thanks for your answer.

I had 2.4.4. So I downloaded 2.4.2, installed it, and placed all dlls in my directory where is my .exe

But pb is still the same.

I have no idea.

 

JL

 

Coordinator
Sep 28, 2009 at 5:56 PM

Have you created the necessary element in your [web|app].config ?

Sep 28, 2009 at 8:01 PM

I'm writing a desktop application : is there a config file to write ?

 

Sep 28, 2009 at 9:13 PM

Well, in fact, each time I try to use GDal functions, it seems to throw that exception (TypeInitializationException).

Last try with :

MessageBox.Show( SharpMap.Layers.GdalRasterLayer.FWToolsVersion.ToString() );

 

Please, what did I miss to use or initiate ?

I put those dll in my exe directory :

gdal_csharp, gdal_fw, gdalconst_csharp, mapscript_csharp, ogr_csharp, osr_csharp, ProjNET, SharpMap, SharpMap.Extensions, SharpMap.UI.

 

JL

 

 

Coordinator
Sep 29, 2009 at 10:30 AM

Hi JL, I have updated http://sharpmap.codeplex.com/Wiki/View.aspx?title=Configure%20GDAL%20%20OGR%20FWTools%20%28as%20of%20revision%2057193%29 hopefully it is clearer now. cheers jd

Sep 29, 2009 at 12:40 PM

Hi,

.config file name looks like linux name but I'm developping in C# on Windows OS a desktop application : what is this config file ? Do I have to use one ? What should be its name ? I did not find any information about it : is it special to GDal use ?

 

Thanks for your help,

JL



Sep 29, 2009 at 12:50 PM

Ok,

my app is Test.exe, I created Test.config : it works better but I still got one error.

 

Now, this line works :

1/ MessageBox.Show( SharpMap.Layers.GdalRasterLayer.FWToolsVersion.ToString() );

2/           SharpMap.Layers.GdalRasterLayer layer;
3/           layer = new SharpMap.Layers.GdalRasterLayer( "GeoTIFF", @"J:\Geolocalisation\DATA\CartaBossy\Map.TIF");
4/           map.Layers.Add(layer);

but Line 3 still throws one "TypeInitializationException" exception

Other pb : line 1 doesn't work if I'm in Debug mode in Dot Net (step by step instruction).

JL

Coordinator
Sep 29, 2009 at 1:49 PM

Full stack trace please.. btw I have no idea if a non georeferenced tiff is ever going to work..

Sep 29, 2009 at 3:05 PM

Here is the stack trace :

 

à SharpMap.Layers.GdalRasterLayer.get_FWToolsVersion()
   à Test.Form1..ctor() dans J:\Geolocalisation\SharpMapCS\Test\Test\Form1.cs:ligne 32
   à Test.Program.Main() dans J:\Geolocalisation\SharpMapCS\Test\Test\Program.cs:ligne 18
   à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   à System.Threading.ThreadHelper.ThreadStart()

 

Coordinator
Sep 29, 2009 at 3:10 PM

does the exception have an inner exception?

Sep 29, 2009 at 3:32 PM

Main stack trace :

à SharpMap.Layers.GdalRasterLayer..ctor(String strLayerName, String imageFilename)
   à Test.Form1..ctor() dans J:\Geolocalisation\SharpMapCS\Test\Test\Form1.cs:ligne 35
   à Test.Program.Main() dans J:\Geolocalisation\SharpMapCS\Test\Test\Program.cs:ligne 18
   à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   à System.Threading.ThreadHelper.ThreadStart()

 

Here is the Inner exception stack trace :

à SharpMap.Extensions.Data.FwToolsHelper..cctor()

 

Coordinator
Sep 29, 2009 at 3:58 PM

All I can suggest is that you put a breakpoint in FWToolsHelper.FWToolsHelper()  and step through..

Sep 29, 2009 at 4:01 PM

That's what I try to do but in Debug mode in step through all GDAL access throws that exception.

As this error looks like the one I had before, I put Test.config in all directories (\bin and \bin\debug). But it didn't change.

Coordinator
Sep 29, 2009 at 4:05 PM
Edited Sep 29, 2009 at 4:06 PM

If you put app.config in the root of your project, the compiler will take care of copying and naming it correctly.. I am pretty sure it should be called Test.exe.config

Sep 29, 2009 at 4:39 PM

Thanks JohnDiss, you were right !

few minutes ago, I really thought there were a difference with Test.config... I don't understand...

So, now, I can do step through, and line 4 throws an exception (null reference exception). Don't understand I make a new object, layer is not null after Line 3 execution :

2/           SharpMap.Layers.GdalRasterLayer layer;
3/           layer = new SharpMap.Layers.GdalRasterLayer( "GeoTIFF", @"J:\Geolocalisation\DATA\CartaBossy\Map.TIF");
4/           map.Layers.Add(layer);

à Test.Form1..ctor() dans J:\Geolocalisation\SharpMapCS\Test\Test\Form1.cs:ligne 36
   à Test.Program.Main() dans J:\Geolocalisation\SharpMapCS\Test\Test\Program.cs:ligne 18
   à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   à System.Threading.ThreadHelper.ThreadStart()

Coordinator
Sep 29, 2009 at 4:58 PM

is map null?

Sep 29, 2009 at 5:10 PM

Right !

Sorry JohnDiss I was concentrated only on GDal...

 

Thanks for you very appreciate help,

 

JL

 

Jan 6, 2010 at 12:56 PM

When you try to use the call to …Providers.Ogr I get an error (‘.ctor’ ambiguous because multiple kinds of members with this name exist in classSharpMap.Data.Providers. Ogr

I had the same issue in the past but only with vb.net(c# seemed to work ok).Anyway  I managed to resolve this error by leaving only one constructor (the one that accepts only one argument - the filename) on the classSharpMap.Data.Providers. Ogr and recompiled sharpmap.