Back to Devexpress

SqlGeometryDataAdapter Class

wpf-devexpress-dot-xpf-dot-map-940acb4f.md

latest7.9 KB
Original Source

SqlGeometryDataAdapter Class

A data adapter that loads data from a SQL geometry data source and displays it on vector layers.

Namespace : DevExpress.Xpf.Map

Assembly : DevExpress.Xpf.Map.v25.2.dll

NuGet Package : DevExpress.Wpf.Map

Declaration

csharp
public class SqlGeometryDataAdapter :
    SqlGeometryDataAdapterBase
vb
Public Class SqlGeometryDataAdapter
    Inherits SqlGeometryDataAdapterBase

Remarks

The SQL geometry data type represents data in a Euclidean (flat) coordinate system. For more information about the SQL geometry type, refer to the following Microsoft article: Spatial Data.

The image below shows a vector map loaded from a SQL geometry data source.

The following table lists supported SQL geometry elements and related map items:

|

Sql Geometry Element

|

Map Item

| | --- | --- | |

Point

|

MapDot

| |

LineString

|

MapPolyline

| |

Polygon

|

MapPath

| |

MultiPoint

|

MapDot

| |

MultiLineString

|

MapPolyline

| |

MultiPolygon

|

MapPath

| |

GeometryCollection that contains elements listed above.

|

Related map items.

|

Load Data

Follow the steps below to load data from a SQL geometry data source:

xaml
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map"
        x:Class="SqlGeometryDataAdapterExample.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <dxm:MapControl>
            <dxm:VectorLayer>
                <dxm:VectorLayer.ShapeTitleOptions>
                    <dxm:ShapeTitleOptions Pattern="{}{TextCol}"
                                           Visible="True"/>
                </dxm:VectorLayer.ShapeTitleOptions>
                <dxm:SqlGeometryDataAdapter 
                    SqlText = "SELECT [id],[GeomCol1],[TextCol] FROM [dbo].[DemoTable]" 
                    SpatialDataMember = "GeomCol1" ConnectionString="{Binding}"/>
            </dxm:VectorLayer>
        </dxm:MapControl>
    </Grid>
</Window>
csharp
using System;
using System.IO;
using System.Windows;

namespace SqlGeometryDataAdapterExample {
    public partial class MainWindow : Window {
        const string dbPath = "..\\..\\..\\Data\\SQLG.mdf";
        string connectionString = "Data Source=(local);AttachDbFileName=" +
            Path.GetFullPath(Path.Combine(System.Reflection.Assembly.GetEntryAssembly().Location, dbPath)) +
            ";Database=SqlGeometryDemoDB;Integrated Security=True;MultipleActiveResultSets=True";
        public String ConnectionString { get { return connectionString; } }

        public MainWindow() {
            InitializeComponent();
            this.DataContext = ConnectionString;
        }
    }
}
vb
Imports System
Imports System.IO
Imports System.Windows

Namespace SqlGeometryDataAdapterExample
    Partial Public Class MainWindow
        Inherits Window
        Private Const dbPath As String = "..\..\..\Data\SQLG.mdf"

        Private connectionString_Renamed As String = "Data Source=(local);AttachDbFileName=" & Path.GetFullPath(Path.Combine(System.Reflection.Assembly.GetEntryAssembly().Location, dbPath)) & ";Database=SqlGeometryDemoDB;Integrated Security=True;MultipleActiveResultSets=True"
        Public ReadOnly Property ConnectionString() As String
            Get
                Return connectionString_Renamed
            End Get
        End Property

        Public Sub New()
            InitializeComponent()
            Me.DataContext = ConnectionString
        End Sub
    End Class
End Namespace

Change Map Appearance

The Map Control stores field values from the SQL geometry data table (except the SpatialDataMember field) as attributes for each vector item. You can colorize shapes based on attribute values or display this data in shape tooltips.

You can also group items of the same type. To do this, initialize the MapDataAdapterBase.Clusterer property with a clusterer that aggregates map items based on their location.

Use the MapControl.ZoomToFitLayerItems method to zoom the map to fit layer items.

xaml
<dxm:MapControl x:Name="mapControl">
 <dxm:VectorLayer DataLoaded="VectorLayer_DataLoaded" x:Name="vectorLayer">
   <dxm:SqlGeometryDataAdapter SqlText = "SELECT [id],[GeomCol1],[TextCol] FROM [dbo].[DemoTable]" 
                               SpatialDataMember = "GeomCol1" ConnectionString="{Binding}" />
 </dxm:VectorLayer>
</dxm:MapControl>
csharp
private void VectorLayer_DataLoaded(object sender, DataLoadedEventArgs e) {
  mapControl.ZoomToFitLayerItems(new LayerBase[] { vectorLayer });
}
vb
Private Sub VectorLayer_DataLoaded(ByVal sender As Object, ByVal e As DataLoadedEventArgs)
    mapControl.ZoomToFitLayerItems(New LayerBase() {vectorLayer})
End Sub

Inheritance

Object DispatcherObject DependencyObject Freezable MapDependencyObject MapDataAdapterBase CoordinateSystemDataAdapterBase SqlGeometryDataAdapterBase SqlGeometryDataAdapter

See Also

SqlGeometryDataAdapter Members

Load Vector Items from Vector Format Source

DevExpress.Xpf.Map Namespace