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.v20.2.dll
NuGet Packages: DevExpress.WindowsDesktop.Wpf.Map, DevExpress.Wpf.Map
Declaration
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 | |
LineString | |
Polygon | |
MultiPoint | |
MultiLineString | |
MultiPolygon | |
GeometryCollection that contains elements listed above. | Related map items. |
Load Data
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;
}
}
}
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 });
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SqlGeometryDataAdapter class.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.