Unable to view a Postgis Layer in a MapBox, however, the Layer.GetCount() works...

Topics: Data Access, SharpMap v0.9 / v1.x
Apr 18, 2013 at 1:17 PM
Dear All,

I followed strictly the tutorials to add a postgis layer in a mapbox.
I switched to Net Framework 4.0
I added the SharpMap.UI
I added the others dependencies AND the SharpMap.Extension
I added the code in the app.config file
I have no bug on my project compilation
I added the legacy.sql commandes to my PostGis DB.

However, there is nothing in my mapBox... Controls seems to work fine, and everything works fine when I use a shapefile data provider.

Any ideas ?

I use Visual Studio 2010.

Here follows my code :
 SharpMap.Styles.VectorStyle objectStyle = new SharpMap.Styles.VectorStyle
                Line = Pens.Black

            SharpMap.Layers.VectorLayer myLayer = new SharpMap.Layers.VectorLayer("My layer");
            string ConnStr = "Server=;Port=5432;User Id=postgres;Password=postgres;Database=test;";
            myLayer.DataSource = new SharpMap.Data.Providers.PostGIS2(ConnStr, "limites_communales", "geom", "gid");
            myLayer.Style = objectStyle;


            SharpMap.Data.Providers.ShapeFile test2 = new SharpMap.Data.Providers.ShapeFile(@"d:\Geodata\limites_communales.shp");
            SharpMap.Layers.VectorLayer commLayer = new SharpMap.Layers.VectorLayer("communes", test2);

         //   mapBox1.Map.Layers.Add(commLayer);

            mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
Apr 18, 2013 at 1:27 PM
Any particular reason you are using PostGIS2 provider?
Please use PostGIS provider, as it is maintained, the other not.
Apr 18, 2013 at 3:56 PM

No particular reason, indeed.
Notice that I need to use Postgis 2.0 on Postgres 9.2 (maybe the reason why I used the postgis2 provider... even if there's no link...).

I did the test, but there's no more result...

If I add the following
to my code, I obtain right number of features in my db table...


Apr 19, 2013 at 7:30 AM
Have you called mapBox1.Map.ZoomToExtents();, too, when just adding the PostGIS layer?

Are you using Geography or Geometry in the PostGIS table? If you are using Geography, the provider will always return an extent of -180, 180; -90, 90. If you have a very local dataset, you might not notice that anything is drawn. What does provider.GetExtents(); return?

IIRC, if you configure the logger, you are getting the sql statements that are passed to the postgres server. Try those in pgAdmin III and you might see what is going wrong.

Hth FObermaier
Apr 19, 2013 at 12:25 PM
Yes, I did it.
The returned extends seems right (the same obtained from QGis software...).

I use a geometry table in 31370 SRID, but with others values, it doesn't work too...

I've tried to configure my logger, but I dont know exactly how to do that. I've added a breakpoint just after the Provider creation, I don't see some SQL request in the contained datas...

I feel completely lost...
Here is my whole project, if you whish to have a look...


Thanks !

Apr 19, 2013 at 6:42 PM
Here is how you configure logging:

Set the logger to Debug-level and you should see the statements
Apr 22, 2013 at 5:59 AM
I just had a brief look at the SharMap.Extensions Zip file offered for download. It may be lacking NetTopologySuite.IO project.
You can easily fix that using the nuget package manager by typing
Install-Package NetTopologySuite.IO

We'll fix the Zip-File though, too.

Hth FObermaier