SharpTools

January 17, 2007

HowTo use the Ogr provider with MapInfo files

Filed under: HowTo,SharpMap — cgraefe @ 10:32 pm

 

In my last weblog entry I announced the redesigned Ogr provider for SharpMap.
Now I will describe in short how to use it in your own GIS projects.

1. Compile the latest change set of SharpMap

– Download the latest change set from the SharpMap project page and extract it.
– Also don’t forget to loaded the dependencies for compiling SharpMap.Extensions properly. Dependencies.zip & DependenciesForGdal.zip
– In the folder SharpMap you open the SharpMap.sln with Visual Studio
– The SharpMap.Extensions needs the following references: NetTopologySuite.dll, Npgsql.dll, Mono.Security.dll, PostgreSql.Data.PostgreSqlClient.dll, Oracle.DataAccess.dll, gdal_gdalconst_csharp.dll, gdal_ogr_csharp.dll, gdal_osr_csharp.dll, gdal_gdal_csharp.dll
– Also copy all the other dll’s from Gdal’s dependencies into your Debug/Release folder, because they do the “magic” wrapping work.
– Now should SharpMap compile fine with the extensions included.

 

2. Reference the extensions in your code

– Don’t forget to reference the SharpMap and SharpMap.Extensions assembly we created in the step before. And also copy all not managed dll’s into your Debug/Release folder. This are the Gdal wrapping dlls (*_wrap.dll) and the Gdal14.dll .

 

3. Use the Ogr provider

This is really simple. Just hack it as usual.

SharpMap.Map mymap = new SharpMap.Map(mapImage1.Size);
SharpMap.Layers.VectorLayer vLayer = new SharpMap.Layers.VectorLayer(“OgrSample”);
vLayer.DataSource = new SharpMap.Data.Providers.Ogr(@”D:\GeoData\MapInfo\World.TAB”);

mymap.Layers.Add(vLayer);
mymap.ZoomToExtents();
mapImage1.Map = mymap;

 

4. Enjoy it!

:-)

Best regards
Christian – Mainz/Germany

10 Comments »

  1. Hello:

    I tried to do the sample with Mapinfo Maps but unfortunally it did not work because ‘Ogr’ namespace does not exist, so in consecuense I tried to find a new version with this namespace but I wasn´t able to find the correct version, can you please help to complete my example.

    Comment by moradoxy — January 24, 2007 @ 2:42 am | Reply

  2. Hello (again):

    I Pass the extension compilation and the “ORG” namespace now works but when I run the example with a Mapinfo Map the program throw a exception in this line: “ogr.RegisterAll();” in the: “OrgProvider.cs” class.

    I follow all the instructions above describe (are very good) but I don´t know what I need to run this example with Mapinfo Mapas using the OGR providers.

    Comment by moradoxy — January 24, 2007 @ 3:26 pm | Reply

  3. Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 69:
    Line 70: _OgrDataSource = OGR.ogr.Open(this.Filename, 0);
    Line 71: _OgrLayer = _OgrDataSource.GetLayerByIndex(LayerNum);
    Line 72: }
    Line 73:

    Source File: C:\My Project\SharpMap\SharpMap.Extensions\Data\Providers\OgrProvider.cs Line: 71

    what should I do ?

    Comment by Seth Bourne — March 18, 2007 @ 3:18 am | Reply

  4. hi,

    my code also throw an exception as “moradoxy” for “ogr.RegisterAll();”.

    am i forget something? any can help me?

    Comment by korkut ozkan — May 5, 2007 @ 9:05 am | Reply

  5. Hi,
    I want use OGR provider in sharpMap.I downloaded new version of SharpMap but it
    dosen’t have OgrProvider.cs in Extension.
    please guide me.
    Thanks

    Comment by azadeh — May 6, 2007 @ 8:31 am | Reply

  6. I am trying to create a web portal that allows for the upload of a MapInfo tab file and retreives the spatial extents of the file. However, when I try to use the call to …Providers.Ogr I get an error (‘.ctor’ ambiguous because multiple kinds of members with this name exist in class SharpMap.Data.Providers.Ogr). This call appears to work in the sample web site that comes with SharpMap. I followed the example above without any success.

    I am using Visual Studio 2005 for the development.

    Any ideas?

    Thanks
    Gerry

    Comment by Gerry — July 15, 2008 @ 8:04 pm | Reply

  7. can you drop a demo or example solution in a zip file for us to see how you did it ?
    thanks a lot!

    Comment by agelos — January 9, 2009 @ 5:42 pm | Reply

  8. 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 class SharpMap.Data.Providers.Ogr
    I had the same issue in the past but only with vb.net .
    To managed to resolve this error by leaving only one constructor (the one that accepts only one argument – the filename) on the class SharpMap.Data.Providers.Ogr and recompiled sharpmap.

    Comment by aggelos — January 6, 2010 @ 12:51 pm | Reply

  9. Thx aggelos. I had the same problem with Providers.Ogr and removing all constructors except for the one I needed solved the problem.

    Comment by PnL — March 25, 2010 @ 8:42 am | Reply

  10. but i cant draw with all file mapinfo. ex my country or my city map ?? please help me ??

    Comment by thientv — May 14, 2010 @ 6:20 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: