PostGIS Layer? Any Suggestions?

Mar 21, 2011 at 2:29 PM

Hello,

I was wondering how can i get a PostGIS Layer in mapsUI Control.

I tried to add SharpMap.Extensions as an external refecence but no luck (I'm not surprised that it didn't worked).

I tried as well to add from the current SharpMap trunk to my project the PostGIS and PostGIS2 to SharpMap.Providers using IProvider2 (named by me), but no luck cause I have to assign the IProvide2 to the DataSource of the Layer which is an IProvider.

It's some way to get a PostGIS Layer in mapsUI control?

thank in advice.

Mar 21, 2011 at 5:48 PM

Hi!

Eventually I would like to use SharpMaps version of the PostGIS provider and also the SharpMap version of the providers that are now in Mapsui's SharpMap.Providers. Perhaps this would be possible with an adapter class which takes a SharpMap provider as constructor argument and implements Mapsui's IProvider interface. The adapter should do some internal translation. This could be quite simple, see for example the Utilities of the SharpMap.Providers. 

http://mapsui.codeplex.com/SourceControl/changeset/view/64565#1122289

However, right now Mapsui and SharpMap use different geometries. So, if you use the original SharpMap version you need to convert the Geometries. That will be some more work than the sample suggests.

Alternatively you could compile PostGis with Mapsui like I have done with the providers in SharpMap.Providers, but that would be a more temporary solution and I am not sure if that is less work. 

If you create such an adapter I would like to add it to Mapsui as a patch. Even if your geometry conversion is only partial (i could imagine you only need points or polygons for you purpose).

Paul

Mar 22, 2011 at 12:08 PM

hello.

Yes I need the PostGIS Layer to render some points using the SymbolStyle on the map.

As you recomanded i made an adapter for post gis but from the PostGIS from SharpMap.

I used the ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) to get the geometries and in IEnumerable<IFeature> GetFeaturesInView(BoundingBox box, double resolution) i've created a new IFeatures and a new FeatureDataSet and i used the ExecuteIntersectionQuery to populate the dataset and to add the features.

Simple. :)

 

I've uploaded it in the Patches section.

After that I've done this:

            string connStr = String.Format("Server={0};Port={1};" + 
                    "User Id={2};Password={3};Database={4};",
                    host, port, username, 
                    password, database );
            string tablename = "points";
             string idColumn = "gid";
           
            PostGIS pg = new PostGIS(connStr, tablename, idColumn);
            pg.DefinitionQuery = "name = 'Point 1'";
            SharpMap.Layers.Layer points = new SharpMap.Layers.Layer("Points");
            points.DataSource = pg;
            
            SymbolStyle s = new SymbolStyle();
            
            SharpMap.Styles.Color color = new SharpMap.Styles.Color();
            color.R = 129;
            color.G = 2;
            color.B = 134;
            
            SharpMap.Styles.Brush brush = new SharpMap.Styles.Brush();
            brush.Color = color;
            s.Fill = brush;
            s.Line.Color = color;
            s.Line.Width = 5.5F;
            s.Opacity = 0.5F;
           
            points.Styles.Add(s);
           
            mapControl.Map.Layers.Add(points);

 

Thanks for support. :)

Mar 26, 2011 at 8:23 PM

Hoppa! thanks for the patch. I committed the patch as new PostGis provider in SharpMap.Providers. Eventually I would prefer to work with a generic adapter, and include the orginal SharpMap.dll and uses it's providers. But that is another step.

Paul

Mar 29, 2011 at 4:26 AM

Hi Paul, 

  I'm sure there's a good reason - but why does mapsui not use the standard SharpMap?  It seems that there are quite a few geometry, projection, etc features that are progressing in SharpMap but which aren't available in mapsui.  

  I've been working on a project where I've had to use some other libraries to manually reproject points for the time being.  Is there any work that I could contribute that might help move mapsui's codebase to allow the use of the standard SharpMap?

Shaw

Mar 30, 2011 at 11:00 AM

Hi Shaw,

The main reason for the differences with the original SharpMapV1 is that I want my project to compile for Silverlight. The three most prominent missing parts are: XmlDocument. GDI+ and DataSet/DataTable. Those were replaced with alternatives in the Mapsui version. I don't see any options to use SharpMapV1 instead of the Mapsui SharpMap version. 

You could use SharpMapV1's data providers using an adapter as described above (the adapter still needs to be written). But for the other stuff that will be hard. The best hope for a future merge will be that the original SharpMap adopts some of the changes made in Mapsui. 

For the projection stuff I am planning to use the same library as is now used in SharpMapV1.

Another point where we could further integrate is if we start using the same GeoAPI.

What other things in SharpMapV1 are you missing in Mapsui? I am not aware of too many changes actually.

Paul

Mar 30, 2011 at 11:19 PM
Hi Paul

I think the main feature I was going to use was the reproduction of a layer or feature. Hopefully sharpmap 2 will be more suitable for interfacing to save you some rewrite work.

Mapsui is amazing btw, it has saved me so much time and pain getting simple map visualization working

Thanks

Sent from my iPhone

On 30/03/2011, at 20:00, "pauldendulk" <notifications@codeplex.com> wrote:

From: pauldendulk

Hi Shaw,

The main reason for the differences with the original SharpMapV1 is that I want my project to compile for Silverlight. The three most prominent missing parts are: XmlDocument. GDI+ and DataSet/DataTable. Those were replaced with alternatives in the Mapsui version. I don't see any options to use SharpMapV1 instead of the Mapsui SharpMap version.

You could use SharpMapV1's data providers using an adapter as described above (the adapter still needs to be written). But for the other stuff that will be hard. The best hope for a future merge will be that the original SharpMap adopts some of the changes made in Mapsui.

For the projection stuff I am planning to use the same library as is now used in SharpMapV1.

Another point where we could further integrate is if we start using the same GeoAPI.

What other things in SharpMapV1 are you missing in Mapsui? I am not aware of too many changes actually.

Paul