Skip to main content

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.v23.2.dll

NuGet Package: DevExpress.Wpf.Map

Declaration

public class SqlGeometryDataAdapter :
    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.

Map Control with data from 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:

<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>
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;
        }
    }
}

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.

<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> 
 private void VectorLayer_DataLoaded(object sender, DataLoadedEventArgs e) {
  mapControl.ZoomToFitLayerItems(new LayerBase[] { vectorLayer });
}
See Also