OGR Data Provider & GDAL Wrapper source

Topics: Data Access
Dec 8, 2006 at 12:42 AM
Does anyone know where I can get the source code for the OGR Data Provider and the associated GDAL wrapper?

The link in the wiki (http://www.codeplex.com/Wiki/View.aspx?ProjectName=SharpMap&title=OGR%20Provider) isn't goin anywhere.

Thanks
AlanK
Coordinator
Jan 11, 2007 at 6:19 PM
Hi

I will post the new OgrProvider next week, which is refactored without
the need of the biggy GDALWrapper and based on Gdal 1.4.

BR
/Christian

Jan 14, 2007 at 9:13 PM
Thanks Christian.
Are you planning on using the SWIG C# components?
Cheers
AlanK
Coordinator
Jan 14, 2007 at 9:36 PM
Hi AlanK,

Yeah, I want to get rid of the GDALWrapper library. It needed a lot of time to
maintain it.
I've uploaded the new Ogr provider in the latest change set |url:16268|http://www.codeplex.com/SharpMap/SourceControl/DownloadSourceCode.aspx?changeSetId=16268]

Give it a try. Don't forget to download the [file:Dependencies for GDAL.zip] located at Extensions

Tamas Szekeres helped the GDAL guys to get the c# swig bindings working.
Jan 15, 2007 at 8:49 PM
Thanks Christian,
I've downloaded and will have look at it.

Tamas has done a good job hasn't he?
Cheers
AlanK
Jan 16, 2007 at 2:52 PM
Hi.Im trying to learn how to use OGR. I have downloaded "SharpMap-16268.zip" and "DependenciesForGDAL.zip".
I have modified demo source code "MapHelper.cs" so it would load MapInfo file instead of shape file. But when I tried to view "ajax.aspx" in browser, i have received an error "System.DllNotFoundException: Unable to load DLL 'gdalogrwrap'". But this file isn't missing. I have read somewhere that I should create .manifest file with the same name, but that didn't help.
Did anyone have the same problem? Can someone suggest something?
Here is a part of the source code that I have changed:

using SharpMap;
using OGR;

public class MapHelper
{
public static SharpMap.Map InitializeMap(System.Drawing.Size size)
{
HttpContext.Current.Trace.Write("Initializing map...");

//Initialize a new map of size 'imagesize'
SharpMap.Map map = new SharpMap.Map(size);

//Set up the countries layer
SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");
//Set the datasource to a shapefile in the App_data folder

layCountries.DataSource = new SharpMap.Data.Providers.Ogr(HttpContext.Current.Server.MapPath(@"~\App_data\untitled.tab"));

//Set fill-style to green
layCountries.Style.Fill = new SolidBrush(Color.Green);
//Set the polygons to have a black outline
layCountries.Style.Outline = System.Drawing.Pens.Black;
layCountries.Style.EnableOutline = true;
layCountries.SRID = 4326;


//Add the layers to the map object.
//The order we add them in are the order they are drawn, so we add the rivers last to put them on top
map.Layers.Add(layCountries);

//limit the zoom to 360 degrees width
map.MaximumZoom = 360;
map.BackColor = Color.LightBlue;

map.Zoom = 360;
map.Center = new SharpMap.Geometries.Point(0,0);

HttpContext.Current.Trace.Write("Map initialized");
return map;
}
Jan 16, 2007 at 4:50 PM
I'm a bit puzzled, does it also supports Rasters?

GDAL is for raster formats and OGR - for vector or I miss something and there is an OGR -> GDAL adapter available?

I guess it will require something like RasterLayer in the same way as VectorLayer or WmsLayer ...
Jan 16, 2007 at 5:26 PM
Sorry, OGR is part of GDAL :), but still what are plans about raster formats in GDAL?

Should it be just a RasterLayer or ImageGeometry for the beginning and later something like Implementation of OGS GridCoverage Specifications http://www.opengeospatial.org/standards/gc, any ideas?
Coordinator
Jan 16, 2007 at 6:09 PM
Hi,

- A new GDAL raster layer will be released as soon as it runs stable. (next week I think)

- At the moment we don't plan to implement WCS due to limited development resources.

BR
/Christian
Jan 16, 2007 at 7:55 PM
Ah, thanks a lot, I can wait a little :)

There is also some library on CodeProject which can use GDAL but it seems to use C++.NET which I don't like, however maybe some ideas from GDAL binding will be usefull: http://www.codeproject.com/csharp/gismap.asp
Jan 17, 2007 at 10:56 AM
Can someone provide a link to some examples on how to use OGR with MapInfo?
I receive errors when trying to use OGR provider to open .tab file (Read my post above for more info).
And why do I need FWTools to use it (I have installed it)? Isn't 'SharpMap.Extensions.dll' enough to use OGR provider?
Coordinator
Jan 17, 2007 at 9:58 PM
Hi,

If you download the latest change set of SharpMap, you don't need to
install the FwTools.
FwTools was a dependencies for the old Ogr provider, which was based on
a GDALWrapper lib.
Now we use the C# bindings of GDAL.

BR
/Christian
Coordinator
Jan 17, 2007 at 10:37 PM
Hi,

You can find a little tutorial here:
http://sharptools.de/Blog/tabid/203/Default.aspx
Jan 18, 2007 at 11:26 AM
Thank you replies and tutorial. However I still can't make it work :). Here is a detailed description:
1.Extracted "SharpMap-16268.zip" and opened SharpMap.sln
2.MSVStudio Message appeared "The source control provider associated with this solution could not be found. The projects will be treated as not under control". Pressed "No" - dont remove prov info permanently.
3.MSVStudio Message appeared "The project file or web has been moved, renamed or is not on your computer. These projects will be labeled as unavailable in Sol.Explorer. Pressed "Ok".
4.Copied NetTopologySuite.dll, Npgsql.dll, Mono.Security.dll, PostgreSql.Data.PostgreSqlClient.dll, Oracle.DataAccess.dll, gdalgdalconstcsharp.dll, gdalogrcsharp.dll, gdalosrcsharp.dll, gdalgdalcsharp.dll into SharpMap.Extensions\bin\Debug
5.Copied gdal14.dll, gdalgdalwrap.dll, gdalgdalconstwrap.dll, gdalogrwrap.dll, gdalosrwrap.dll, OraOps10w.dll into SharpMap.Extensions\bin\Debug
6.SharMap Solution -> Build Solution -> Received lots of errors due to missing file "nunit.framework" which is referenced in UnitTests project.
7.SharpMap ->Build; SharpMap.Extensions->Build
8.File->New->Project...->Visual C# : Windows Application
9.Tools->Choose Tool Box Items..->.Net Framework Components, Browse->SharpMap\SharpMap.UI\bin\Debug\SharpMap.UI.dll; "AjaxMapControl" Appeared
10.In the form designer: created MapImage object on my form (dragged it from the ToolBox); new reference appeared in my project - SharpMap.UI.dll
11.Added references to SharpMap.Extensions\bin\Debug\SharpMap.dll, SharpMap.Entensions.dll
12.Copied (*_wrap.dll) and the Gdal14.dll to my project's Debug folder
13.Added the following lines to the Form1.cs:
public Form1()
{
InitializeComponent();

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:\Untitled.TAB");

mymap.Layers.Add(vLayer);
mymap.ZoomToExtents();
mapImage1.Map = mymap;
}
14.Debug->Start Debugging; Received message: "An unhandled exception of type 'System.TypeInitializationException' occurred in SharpMap.Extensions.dll
Additional information: The type initializer for 'OGR.ogr' threw an exception.". Shows me yellow-colored line in OgrProvider.cs: "ogr.RegisterAll();"
Jan 18, 2007 at 12:06 PM
Btw, I can send you my C# project with mapinfo file, if you want.
Jan 22, 2007 at 10:51 AM
I have noticed that before this error I receive "A first chance exception of type 'System.DllNotFoundException' occurred in gdalogrcsharp.dll" with "Additional information: Unable to load DLL 'gdalogrwrap'". So it's the same problem loading ogr wrapper.
Coordinator
Jan 22, 2007 at 10:07 PM
Hi,

Have you copied all *_wrap.dll and the gdal14.dll into your bin directory of you project?

Christian
Jan 23, 2007 at 11:36 AM
Hi,
I have tried it as you said and still it doesn't work. I think you should check my project. If it runs on your pc then maybe it's not the ogr wrapper that causing problems, but something else. I did everything exactly as written in your tutorial (as you can see in my previous posts), so i guess other ppl could have the same problem.
Here is a rapidshare link to my project (4 MB):
http://rapidshare.com/files/12989176/WindowsApplication1.rar.html

Thanks anyway :)
Jan 23, 2007 at 11:43 AM
Sorry, I gave you wrong link :). Here is a correct one:
http://rapidshare.com/files/12990890/WindowsApplication1.rar
Jan 26, 2007 at 1:24 AM
Hello:

I made exactly the same steps to try to load a mapinfo map with the OGR provider and get the same error.

This is my first time to try with SharpMap, I'm so glad with this project and I'm very interested that it works with Mapinfo because this is the format map that I have.


Thanks, and please if somebody find the solution let me now to my email: moradoxy@yahoo.com.

Feb 1, 2007 at 2:03 PM
Edited Feb 1, 2007 at 2:26 PM
Still, I haven't found a way to make it work with ".TAB" files. If moradoxy got the same error, then it must be something with the provider itself. Can some one help? Atleast say that it is a bug :).
Btw, I am using MapInfo 7.8. Maybe Ogr provider was designed for latest versions of MapInfo?
Feb 14, 2007 at 7:15 PM
Hello

Can anybody get the website to work with MAP file?

Im getting error: _OgrLayer = _OgrDataSource.GetLayerByIndex(LayerNum);

layMap1.DataSource = new SharpMap.Data.Providers.Ogr(HttpContext.Current.Server.MapPath(@"~\Appdata\worldwms.map"));
Coordinator
Feb 20, 2007 at 10:45 PM
Hi,

What vector format is your map file?

regards
Christian
Feb 21, 2007 at 7:39 PM
Hi,

The vector format is mapinfo file. When using fwtools 1.2.0 (openev_fw) it works fine.
Do you have any idea?

Regards
Michael
Feb 22, 2007 at 3:28 PM
Hi,

I got the map to work (Pure file).

How can I read a layer attribute within the AJAX (It's still a mapinfo file) when clicked on the map.

Regards
Michael
Feb 23, 2007 at 1:33 PM
Hi,

Does anybody have sample code where they use GDAL with tab files(Mapinfo)?
The Tab file contains polygons and some attributes for each polygon, that I what to put onto the map.

How to extract attributes with GDAL?

Regards
Michael
Coordinator
Feb 23, 2007 at 11:20 PM
Hi Michael,

If you have used any other vector data provider it should be the same.
What problems do you experience?

regards
Christian
Feb 24, 2007 at 7:47 AM
Hi Christian

I have no problems, but can't find my way of getting the attributes of polygons.
I have a raster image (ecw) and a layer with around 300 polygons and each have a description and geoid.
I need to extract these attributes.
Do you have any sample code? (Also ajax code where you capture click and present the description or geoid)

Regards
Michael
Feb 27, 2007 at 6:39 PM
Hello:

Some body have news about the problem (above described) with MapInfo?
Mar 7, 2007 at 2:11 PM
Does any one get the OGR to run with MapInfo tables here?

seems that GDAL/OGR Wrapper doesn't work with SharpMap.
Mar 7, 2007 at 3:42 PM
Edited Mar 7, 2007 at 4:18 PM
Hi

OGR is working with mapinfo files.

See sample at http://map.vedbaek-havn.dk
It's written i VB.


Mar 9, 2007 at 8:27 AM
Hi All,

I've make the OGR/GDAL thing run with my application. Note that the latest OGR/GDAL version should be used. I am coding with VB.NET.
Mar 9, 2007 at 9:34 PM
I haven't managed to have a sample working. Can you post a sample project somewhere?

If I am not mistaken, one can use OGR library that comes with GDAL, in order to use S57 map files. Des anybody has implemented something like this?


George J.
Mar 22, 2007 at 10:30 PM
Edited Mar 23, 2007 at 2:57 AM
I finally got it running by copying ALL the .dlls from the fw bin directory to the bin directory of my webapp (currently just the DemoWebSite).

Mar 23, 2007 at 6:09 AM
Would you mind make an archive of the DemoWebSite project, make it availiable online, and list the packages you installed on your workstation in order to make the OGR support work?


Thanks,
George J.
Mar 23, 2007 at 6:53 AM
Edited Mar 23, 2007 at 9:32 PM
Edit: I've started a new s57 thread.

It's kind of a mess and it doesn't work yet. If I get it working I'll share.

Basically:

- Download the SharpMap sources
- Download the dependencies.zip file and unzip it in SmartMapExtensions
- In the SmartMapExtensions project, expand the references section, right click each broken reference and point it to the correct .dll that you just unzipped.
- Download and install the fw_tools stuff described elsewhere (search here).
- At the very least copy *.dll from the bin directory of the fw_tools stuff into the bin directory of the DemoWebSite project. This helped the most. Not ideal but it works.

Right now I am trying to display an S57 file but the ogr layer is throwing a datasource not implemented exception or some such.

I'm really just playing around with this stuff right now so sorry for the lack of definitive answers. My goal is to get S57's to render. I was able to use the evdesk tool in fw_tools to load and display my sample S57 so I know in theory the code base can handle it even if it did crash after a few redraws.



gcapnias wrote:
Would you mind make an archive of the DemoWebSite project, make it availiable online, and list the packages you installed on your workstation in order to make the OGR support work?


Thanks,
George J.


Mar 26, 2007 at 2:34 PM
Sorry for the delayed post, I was not here in the last several weeks.

Ok, I explain now what I have done to make the OGR/GDAL to work with SharpMap. I follow the steps that Donat said, except that I use the OGR/GDAL DLL that are compiled by myself from the OGR/GDAL CVS source code. Do not use the OGR/GDAL DLL supplied in the dependendices.zip, there is something wrong with them.

I don't know how to upload file here, if somebody need the DLL, please leave me a message and give me a email, I will send you the DLL.

Zhonghai
Mar 26, 2007 at 6:57 PM
The lastest version of ShardMap checked in - changeset 19234 - does not use GDAL/OGR library directly. Instead it uses FWTools - the C# wrappers GDAL/OGR library FWTools includes.

I have builded a dll, using changeset 19234, FwTools v1.2.2, Npgsql - .Net Data Provider for PostgreSQL v1.0 and NetTopologySuite v1.7.1 RC1 and the libraries for the Oracle data provider.

I cannot load a S57 map, although I can load the S57 map's layers with Open EV.


George J.
Apr 3, 2007 at 3:12 AM
I used the lastest version of SharpMap 19234,my applicatin used the SharpMap.dll,SharpMap.UI.dll,SharpMap.Extensions. When I debug my application to "GDAL.gdal.AllRegister();",i will received a message :“GDAL.gdalPINVOKE”typeInitializationException.
Can you tell me how to resolve this problem.

Thanks
Sunny_cool
Coordinator
Apr 3, 2007 at 3:46 AM
A TypeInitializationException happens when a static (type) initializer is run by the CLR and throws an exception.

I'm guessing that there is either a missing file or an incorrect version, since these are the kinds of initialization that go on in the static constructor. Do you have all the prerequisites, including FwTools 1.2 and setting your %PATH% environment variable to include %FWTOOLS%\bin (where %FWTOOLS% corresponds to the directory where FwTools was installed)?
Apr 6, 2009 at 1:40 PM
Hi all
i write this code :

    Public Function SetMapInfoLayer(ByVal MIName As String, ByVal FileName As String, Optional ByVal MaxVisible As Integer = Nothing, Optional ByVal MinVisible As Integer = Nothing, Optional ByVal SRID As Integer = Nothing) As SharpMap.Layers.VectorLayer
        Dim OGRLayer As SharpMap.Layers.VectorLayer = New SharpMap.Layers.VectorLayer(MIName)
        Try
            OGRLayer.DataSource = New SharpMap.Data.Providers.Ogr(System.IO.Path.GetFullPath(FileName))'''''''''''''''''''''''''''''''''error
        Catch ex As Exception

        End Try
        If MaxVisible <> Nothing Then OGRLayer.MaxVisible = MaxVisible
        If MinVisible <> Nothing Then OGRLayer.MinVisible = MinVisible
        If SRID <> Nothing Then OGRLayer.SRID = 4326
        Return OGRLayer
    End Function

But i see this error :
'.ctor' is ambiguous because multiple kinds of members with this name exist in class 'SharpMap.Data.Providers.Ogr'.

Help me please
Jun 24, 2010 at 4:49 PM

The last issue has to do with these constructors in the Ogr Provider...

public Ogr(string filename, string layerName)

and...

public Ogr(string filename, out string name)

VB doesn't recognize 'out' so it sees both constructors as having two strings as params which is causing the 'ambigous' error.  I had to change the constructor signature and re-compile to get it to work in VB.