wpf-18177-controls-and-libraries-map-control-examples-vector-data-customize-data-appearance-how-to-automatically-load-cartesian-data-to-a-geo-map.md
To automatically load Cartesian map data from a shapefile onto a Geo map, do the following.
If the shapefile data contains a *.PRJ file with the same name and path as the *.SHP file, specify the ShapefileDataAdapter.FileUri property. The data will be loaded automatically.
Otherwise, to load coordinate system information if the file names or paths are different, use the ShapefileDataAdapter.LoadPrjFile method to initialize the SourceCoordinateSystem class descendant object, which should be assigned to the CoordinateSystemDataAdapterBase.SourceCoordinateSystem property of the data adapter.
<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"
xmlns:local="clr-namespace:LoadPrjData"
xmlns:sys="clr-namespace:System;assembly=System"
x:Class="LoadPrjData.MainWindow"
Title="MainWindow" MinHeight="350" MinWidth="525" Loaded="Window_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Margin="4,4,2,4" Content="Coordinate System:"/>
<ComboBox Grid.Column="1" Name="cbCoordinateSystem" HorizontalAlignment="Stretch"
Margin="2,4,4,4" SelectedIndex="0" ItemsSource="{Binding Data}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Padding="4"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button Grid.Column="2" Content="Locate Vector Data" Margin="4" Padding="4" Click="Button_Click"></Button>
</Grid>
<dxm:MapControl Name="map" Grid.Row="1">
<dxm:ImageTilesLayer>
<dxm:BingMapDataProvider Kind="Road" BingKey="YOUR BING KEY"/>
</dxm:ImageTilesLayer>
<dxm:VectorLayer ShapeFill="#60FF8800">
<dxm:ShapefileDataAdapter
FileUri="{Binding ElementName=cbCoordinateSystem, Path=SelectedValue.FileUri}"
SourceCoordinateSystem="{Binding ElementName=cbCoordinateSystem, Path=SelectedValue.CoordinateSystem}">
</dxm:ShapefileDataAdapter>
</dxm:VectorLayer>
</dxm:MapControl>
</Grid>
</Window>
Imports System
Imports System.Collections.Generic
Imports System.Windows
Imports DevExpress.Xpf.Map
Namespace LoadPrjData
Partial Public Class MainWindow
Inherits Window
Private data_Renamed As New List(Of MapData)()
Public ReadOnly Property Data() As List(Of MapData)
Get
Return data_Renamed
End Get
End Property
Public Sub New()
InitializeComponent()
End Sub
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim baseUri As New Uri(System.Reflection.Assembly.GetEntryAssembly().Location)
' #Region "#AutomaticallyLoaded"
data_Renamed.Add(New MapData() With {.Name = "Automatically loaded data", .FileUri = New Uri(baseUri, "../../Shapefiles/Albers/switzerland.shp")})
' #End Region ' #AutomaticallyLoaded
' #Region "#LoadPrjFile"
data_Renamed.Add(New MapData() With {.Name = "LoadPrjFile( ) loaded coordinate system", .FileUri = New Uri(baseUri, "../../Shapefiles/Lambert/Belize.shp"), .CoordinateSystem = ShapefileDataAdapter.LoadPrjFile(New Uri(baseUri, "../../Shapefiles/Lambert/Projection.prj"))})
' #End Region ' #LoadPrjFile
' #Region "#ManuallyCreated"
data_Renamed.Add(New MapData() With { _
.Name = "Manually created coordinate system", .FileUri = New Uri(baseUri, "../../Shapefiles/TransverseMercator/israel.shp"), .CoordinateSystem = New CartesianSourceCoordinateSystem() With { _
.CoordinateConverter = New UTMCartesianToGeoConverter() With {.Hemisphere = Hemisphere.Northern, .UtmZone = 36} _
} _
})
' #End Region ' #ManuallyCreated
Me.DataContext = Me
End Sub
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
map.ZoomToFitLayerItems(0.4)
End Sub
End Class
Public Class MapData
Public Property Name() As String
Public Property FileUri() As Uri
Public Property CoordinateSystem() As SourceCoordinateSystem
End Class
End Namespace
using System;
using System.Collections.Generic;
using System.Windows;
using DevExpress.Xpf.Map;
namespace LoadPrjData {
public partial class MainWindow : Window {
List<MapData> data = new List<MapData>();
public List<MapData> Data { get { return data; } }
public MainWindow() {
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
Uri baseUri = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location);
#region #AutomaticallyLoaded
data.Add(new MapData() {
Name = "Automatically loaded data",
FileUri = new Uri(baseUri, "../../Shapefiles/Albers/switzerland.shp")
});
#endregion #AutomaticallyLoaded
#region #LoadPrjFile
data.Add(new MapData() {
Name = "LoadPrjFile( ) loaded coordinate system",
FileUri = new Uri(baseUri, "../../Shapefiles/Lambert/Belize.shp"),
CoordinateSystem = ShapefileDataAdapter.LoadPrjFile(new Uri (
baseUri, "../../Shapefiles/Lambert/Projection.prj"))
});
#endregion #LoadPrjFile
#region #ManuallyCreated
data.Add(new MapData() {
Name = "Manually created coordinate system",
FileUri = new Uri(baseUri, "../../Shapefiles/TransverseMercator/israel.shp"),
CoordinateSystem = new CartesianSourceCoordinateSystem() {
CoordinateConverter = new UTMCartesianToGeoConverter() {
Hemisphere = Hemisphere.Northern,
UtmZone = 36
}
}
});
#endregion #ManuallyCreated
this.DataContext = this;
}
private void Button_Click(object sender, RoutedEventArgs e) {
map.ZoomToFitLayerItems(0.4);
}
}
public class MapData {
public string Name { get; set; }
public Uri FileUri { get; set; }
public SourceCoordinateSystem CoordinateSystem { get; set; }
}
}