Connect Postgis Database and display linestring on WPF ?

Topics: SharpMap Project, SharpMap v0.9 / v1.x
Feb 24 at 7:23 PM
is it possible ?
I tried to do it. but it didnt work ? How can I display postgis data on WPF ?

it is my sample code:
When I tried to do this. The red regtangle appear on WPFmap.?How can I fix it ?

MainWindow.XAML

<Window x:Class="WpfOrnek.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:smh="clr-namespace:SharpMap.UI.WPF;assembly=SharpMap.UI.WPF"
        xmlns:local="clr-namespace:WpfOrnek"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>              
        <smh:SharpMapHost Name="WpfMap" Margin="0,39,0,0"/>
        <Menu x:Name="menu" HorizontalAlignment="Left" Height="34" VerticalAlignment="Top" Width="507">
            <MenuItem Header="deneme" Name="dene" Click="Yol_Tikla_OnClick">
                <MenuItem Header="ekle"/>
            </MenuItem>
        </Menu>
    </Grid>
</Window>

MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Npgsql;
using GeoAPI.Geometries;

namespace WpfOrnek
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public static string P_postgisconn = "server=localhost;port=5432;user=postgres;pwd=PASS;database=kgmdb";
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Yol_Tikla_OnClick(object sender, RoutedEventArgs e)
        {
            yolGetir();
        }
        private void yolGetir()
        {
            var ds = new SharpMap.Data.Providers.PostGIS(P_postgisconn, "kgmeksen36", "geom", "id");
            var lay = new SharpMap.Layers.VectorLayer("dd", ds);
            SharpMap.Layers.VectorLayer VLyol = new SharpMap.Layers.VectorLayer("yol");
            VLyol.DataSource = new SharpMap.Data.Providers.PostGIS(P_postgisconn, "kgmeksen36", "geom", "id");
            WpfMap.MapLayers.Add(lay);
            }
    }
}
Coordinator
Feb 25 at 9:41 AM
Assuming the construction of your PostGIS provider is correct, you need to add the following code after adding the postgis layer:
if (WpfMap.MapLayers.Count == 1)
{
    Envelope env = lay.Envelope;
    WpfMap.ZoomToEnvelope(env);
}
Feb 25 at 8:32 PM
Thank you for your reply. but i tried this code. The result is same. Unfortunately display is same. The red regtangle appear again. How can i fix it ?
 var ds = new SharpMap.Data.Providers.PostGIS(P_postgisconn, "kgmeksen36", "geom", "id");
            var lay = new SharpMap.Layers.VectorLayer("dd", ds);
            SharpMap.Layers.VectorLayer VLyol = new SharpMap.Layers.VectorLayer("yol");
            VLyol.DataSource = new SharpMap.Data.Providers.PostGIS(P_postgisconn, "kgmeksen36", "geom", "id");
            WpfMap.MapLayers.Add(lay);
            {
                Envelope env = lay.Envelope;
                WpfMap.ZoomToEnvelope(env);
            }
Coordinator
Feb 26 at 7:52 AM
Are you sure you have all required reference fullfilled?
Are you able to use the postgis provider in the WPFSamples project?
Feb 27 at 10:51 AM
Thank you. I get it. I get correct refecences. After I display my postgis data on my wpfmap.