How to get extra information from POSTGIS Providers?

Oct 15, 2013 at 9:26 AM
Hi! there,
I have a postgis table imported from S57 000 file.
Now I can draw vector layers and label layers from these tables. The code is like
 //Set up a SeaArea layer
            tablename = "seaare";
            SharpMap.Layers.VectorLayer S57_laySeaArea = new SharpMap.Layers.VectorLayer("S57_SeaArea");
            provider_map1 = new SharpMap.Data.Providers.PostGIS(S57_connection, tablename, geomCol, idColumn);
            provider_map1.DefinitionQuery = "GeometryType(wkb_geometry) = 'POLYGON' "; 
           S57_laySeaArea.DataSource = provider_map1;
            //Set fill-style to green
            S57_laySeaArea.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.LightCyan);
            //Set the polygons to have a black outline
            //laySeaArea.Style.Outline = System.Drawing.Pens.Black;
            S57_laySeaArea.Style.EnableOutline = false;
             map.Layers.Add(S57_laySeaArea);
But the ordinary database table contains some important information, such as Style.MaxVisible, .MinVisible in the table columns; How could I get these value for each lines and points?


Note, in label layer, I can get the label value from 'LabelColumn'. But in vector layer, I have no idea how to get the value from column scamax, scamin, and etc.
Coordinator
Oct 15, 2013 at 12:32 PM
I assume you want to exclude those features from rendering? You can to apply a theme
public class S57MinMaxVisibleTheme : SharpMap.Styles.Thematics.ITheme
{
    public SharpMap.Styles.VectorStyle Default { get; set; } 
    public SharpMap.Styles.IStyle GetStyle(SharpMap.Data.FeatureDataRow row)
    {
        var res = (SharpMap.Styles.VectorStyle)Default.Clone();
        res.MinVisible = System.Convert.ToDouble(row["minvisible"]);
        res.MaxVisible = System.Convert.ToDouble(row["maxvisible"]);
    }
}
Another idea whould be to update PostGIS provider's DefinitionQuery property to sth like
provider_map1 = string.Format (NumberFormatInfo.InvariantInfo, "(\"minvisible\" < {0} AND {0} <= \"maxvisible\")", map.Zoom);
Hth FObermaier
Oct 15, 2013 at 4:01 PM
Dear FObermaier,
Sorry for making misunderstanding. But the real meaning I would like to get is the other column value nearby the geometry column and id Column. For example, I have 100 vector lines in SeaArea table. From the following code, I can get all lines in SeaArea table.
provider_map1 = new SharpMap.Data.Providers.PostGIS(S57_connection, tablename, geomCol, idColumn);
provider_map1.DefinitionQuery = "GeometryType(wkb_geometry) = 'POLYGON' "; 
But aside the geometry column, there are some extra column, such as maxvisible, maxvisible, comment, and etc.
And these value of minvisible( scamin) or MaxVisible( scamax) might be different for each line.
In S57 format, MaxVisible is established in meter unit, but the map is established in degree unit.
So I need to make unit transformation before DefinitionQuery. Then I could update PostGIS provider's DefinitionQuery property as your comment.
Is there any good suggestion to make it??
Coordinator
Oct 15, 2013 at 7:52 PM
yenpo wrote:
In S57 format, MaxVisible is established in meter unit, but the map is established in degree unit.
So I need to make unit transformation before DefinitionQuery. Then I could update PostGIS provider's DefinitionQuery property as your comment.
Is there any good suggestion to make it??
You need to assign a CoordinateTransformation
const string targetWkt = "... WKT ...";
var csFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
var csTarget = csFact.CreateFromWkt(targetWkt);
var ctFac = new ProjNet.CoordinateSystems.Transformation.CoordinateTransformationFactory();

S57_laySeaArea.CoordinateTransformation = ctFac.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.Geographic.WGS84, ctTarget);