wpf-devexpress-dot-xpf-dot-map-940acb4f.md
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
public class SqlGeometryDataAdapter :
SqlGeometryDataAdapterBase
Public Class SqlGeometryDataAdapter
Inherits SqlGeometryDataAdapterBase
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
|
| |
LineString
|
| |
Polygon
|
| |
MultiPoint
|
| |
MultiLineString
|
| |
MultiPolygon
|
| |
GeometryCollection that contains elements listed above.
|
Related map items.
|
Follow the steps below to load data from a SQL geometry data source:
Create a SqlGeometryDataAdapter object.
Use the SqlGeometryDataAdapter.ConnectionString property to configure the connection string.
Set the SqlGeometryDataAdapter.SqlText property to specify the SQL query to the database.
Use the SqlGeometryDataAdapter.SpatialDataMember property to set the spatial data member.
Assign the SqlGeometryDataAdapter to the VectorLayer.Data property.
<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;
}
}
}
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
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 });
}
Private Sub VectorLayer_DataLoaded(ByVal sender As Object, ByVal e As DataLoadedEventArgs)
mapControl.ZoomToFitLayerItems(New LayerBase() {vectorLayer})
End Sub
Object DispatcherObject DependencyObject Freezable MapDependencyObject MapDataAdapterBase CoordinateSystemDataAdapterBase SqlGeometryDataAdapterBase SqlGeometryDataAdapter
See Also
SqlGeometryDataAdapter Members