Create feature from postgis

Apr 12, 2016 at 6:19 PM
Edited Apr 12, 2016 at 8:35 PM

I'm wondering how can I create a Feature directly from one postgis record : I can get the geometry with an st_aswkt or as_binary and so on... but how can I fill the geometry in the feature or at least be able to manipulate the geometry with mapwingis methods ?


Apr 17, 2016 at 10:09 AM
Hi Olivier,

This should give you some ideas:
const string connection = "PG:dbname=*** host=*** user=*** password=***";
// Get data source:
var ds = new VectorDatasource(connection);
// Get each layer in data source:
foreach (VectorLayer layer in ds)
    Debug.Print("Layer: " + layer.Name);

// Get first layer:
var lyr = ds.GetLayer(0);
// Get all features in this layer:
var fs = lyr.Data.Features;
Debug.Print("Number of features: " + fs.Count());

int count = 0;
// Get details about each feature:
foreach (var ft in fs)
    Debug.Print("Feature: {0}; Number of points: {1}", count++, ft.Geometry.Points.Count);

Marked as answer by pmeems on 4/17/2016 at 11:56 PM
Apr 17, 2016 at 10:35 AM
Well done Paul, it works, thanks very much !!