s57 enc reading and rendering

Topics: SharpMap Project, SharpMap v2.0
Feb 23, 2010 at 4:07 PM

Hi all,

is it possible to read and render s57 data using SharpMap? i tried but SharpMap got crashed.

following is my code.

SharpMap.Map mymap = new SharpMap.Map(mapImage1.Size);

SharpMap.Layers.VectorLayer vLayer = new SharpMap.Layers.VectorLayer(“OgrSample”);

vLayer.DataSource = new SharpMap.Data.Providers.Ogr(@"test.000");

mymap.Layers.Add(vLayer);

mymap.ZoomToExtents();

mapImage1.Map = mymap;

SharpMap crashes at last line (mapImage1.Map = mymap).//Null reference exception

Please share your code or throw some light.

Coordinator
Feb 23, 2010 at 4:30 PM

It sounds like mapImage1 has not been initialized yet. hth jd

Feb 23, 2010 at 6:45 PM
johndiss wrote:

It sounds like mapImage1 has not been initialized yet. hth jd

sry, i forgot to mention mapImage1. mapImage1 is initialized. it is crashing in parseGeometry function in SharpMap.Extension DLL.

Coordinator
Feb 23, 2010 at 8:57 PM

Hi rkguatam, can you post a full stack trace. cheers jd

Feb 23, 2010 at 10:42 PM
> vLayer.DataSource = new SharpMap.Data.Providers.Ogr(@"test.000");
 
It's very likely that it never found that test.000 file.
Feb 24, 2010 at 6:00 AM
johndiss wrote:

Hi rkguatam, can you post a full stack trace. cheers jd

following is the stack trace.

SharpMap.Extensions.dll!SharpMap.Data.Providers.Ogr.ParseOgrGeometry(OSGeo.OGR.Geometry OgrGeometry = null)
SharpMap.Extensions.dll!SharpMap.Data.Providers.Ogr.GetGeometriesInView(SharpMap.Geometries.BoundingBox bbox = {128.855504587156,35 129.644495412844,35.5})
SharpMap.dll!SharpMap.Layers.VectorLayer.Render(System.Drawing.Graphics g = {System.Drawing.Graphics}, SharpMap.Map map = {SharpMap.Map})
SharpMap.dll!SharpMap.Map.GetMap()

Feb 24, 2010 at 6:09 AM
FrankR wrote:
> vLayer.DataSource = new SharpMap.Data.Providers.Ogr(@"test.000");
 
It's very likely that it never found that test.000 file.

no this is not the case because i am getting values (value of BBOX) from file as seen in call stack trace and also if this was the case then crash location would have been

> vLayer.DataSource = new SharpMap.Data.Providers.Ogr(@"test.000");

 

SharpMap.Extensions.dll!SharpMap.Data.Providers.Ogr.ParseOgrGeometry(OSGeo.OGR.Geometry OgrGeometry = null)
SharpMap.Extensions.dll!SharpMap.Data.Providers.Ogr.GetGeometriesInView(SharpMap.Geometries.BoundingBox bbox = {128.855504587156,35 129.644495412844,35.5})
SharpMap.dll!SharpMap.Layers.VectorLayer.Render(System.Drawing.Graphics g = {System.Drawing.Graphics}, SharpMap.Map map = {SharpMap.Map})
SharpMap.dll!SharpMap.Map.GetMap()

 

Coordinator
Feb 24, 2010 at 10:53 AM
Edited Feb 24, 2010 at 10:53 AM

A NRE seems legit there if the OgrGeometry being passed in is null. It would be straight forward enough to test for null and skip parsing within the  ParseOgrGeometry method and then ensure that a null was not added into any collections being built, however it seems that it may be an issue with the data? Or does a null Geometry have a special significance in S57 e.g deleted (but not removed) record or similar?

Coordinator
Feb 24, 2010 at 11:32 AM
Edited Feb 24, 2010 at 1:29 PM

S-57 is a multi layer file. You must specify which layer you want to address with the provider. If you don't do that, Layer 0 is chosen, which may not have geometry data.

Use

 

Int32 someLayerNumber = 12;
vLayer.DataSource = new SharpMap.Data.Providers.Ogr(@"test.000", someLayerNumber);

 

or

String someLayerName = "FAIRWY";
vLayer.DataSource = new SharpMap.Data.Providers.Ogr(@"test.000", someLayerName);

to setup your datasource.

If you want to use several layers of test.000, you need to have a layer/datasource pair for each.

If there are 2.5D geometries in the dataset, Parsing the wkb geometries will still fail.

Hth
FObermaier

Coordinator
Feb 26, 2010 at 7:05 AM

With the latest changes to the OgrProvider you should be able to read S-57 ENC files without any problems

Please see this for additional settings. I added a sample to the WinFormSamples project.

Hth FObermaier

Mar 19, 2010 at 7:23 PM

Hi --   Where can I find the "WinformsSamplesProject"? cheers

Mar 19, 2010 at 8:30 PM

Thanks. I found the "WinformSamples Project". From what I see from this thread is that one has to render the layers based on which layers he wants to show. That is fine. I was able to change S57 charts to shapefiles and I was rendering the layers one by one as I want. However lables for soundings and colouring the different depth layers was a problem. Does OgrProvider look after all of this now? Would someone please post a screenshot of how does the final map looks like ? Cheers

 

Coordinator
Mar 22, 2010 at 9:21 AM

Hello elagizi,

color/style information is not taken care of by the ogrprovider as-is. This could be done with a custom theme.

I don't know what you mean with "soundings". As long as you have set GDAL_DATA environment variable to the appropriate directory (the one that contains the s57*.csv files), the OgrProvider returns not just one layer for puntal-, one for lineal- and one for areal geometries.

Hth FObermaier