wpf-devexpress-dot-xpf-dot-map-c72946c4.md
A data adapter that loads data from shapefiles and displays it on vector layers.
Namespace : DevExpress.Xpf.Map
Assembly : DevExpress.Xpf.Map.v25.2.dll
NuGet Package : DevExpress.Wpf.Map
public class ShapefileDataAdapter :
CoordinateSystemDataAdapterBase,
ISupportDataLoading
Public Class ShapefileDataAdapter
Inherits CoordinateSystemDataAdapterBase
Implements ISupportDataLoading
The shapefile format is a geospatial vector data format that uses geometries (points, polylines, and polygons) to display geographic data (rivers, lakes, countries and others). The Map Control uses data from two types of files:
The Map Control stores data from the .dbf file to attributes for each vector item. You can colorize shapes based on attribute values or display this data in shape tooltips.
The image below shows a vector map loaded from a shapefile.
The following table lists supported shapefile elements and related map items:
|
Shape File Element
|
Map Item
| | --- | --- | |
Point,
PointM (the M value is ignored),
PointZ (the Z value is ignored),
Multipoint,
MultipointM (the M value is ignored),
MultipointZ (the Z value is ignored).
|
| |
PolyLine,
PolylineM (the M value is ignored),
PolylineZ (the Z value is ignored).
|
| |
Polygon,
PolygonM (the M value is ignored),
PolygonZ (the Z value is ignored).
|
|
For more information about shapefile element types, refer to ERSI Shapefile Technical Description.
Follow the steps below to load data from a shapefile:
Create a new ShapefileDataAdapter object.
Use the ShapefileDataAdapter.FileUri property to specify the path to a shapefile.
Assign the adapter to the VectorLayer.Data property.
<dxm:MapControl>
<dxm:VectorLayer>
<dxm:ShapefileDataAdapter FileUri="Data/Countries.shp"/>
</dxm:VectorLayer>
</dxm:MapControl>
Tip
If the Map Control does not display a shapefile, make sure that the ShapefileDataAdapter coordinate system is specified correctly. See the following help topic for more information: Provide Cartesian Data to a Geographical Map.
When vector items are loaded, the MapGeoDataAdapter.ShapesLoaded event occurs. Use the e.Shapes property to access loaded shapes.
<dxm:MapControl>
<dxm:VectorLayer>
<dxm:ShapefileDataAdapter FileUri="Data/Countries.shp"
ShapesLoaded="ShapefileDataAdapter_ShapesLoaded"/>
</dxm:VectorLayer>
</dxm:MapControl>
private void ShapefileDataAdapter_ShapesLoaded(object sender, DevExpress.Xpf.Map.ShapesLoadedEventArgs e) {
foreach (MapPath item in e.Shapes) {
item.Fill = Brushes.Gray;
}
}
Private Sub ShapefileDataAdapter_ShapesLoaded(ByVal sender As Object, ByVal e As DevExpress.Xpf.Map.ShapesLoadedEventArgs)
For Each item As MapPath In e.Shapes
item.Fill = Brushes.Gray
Next
End Sub
Use the MapControl.ZoomToFitLayerItems method to zoom a map to fit layer items.
<dxm:MapControl x:Name="mapControl">
<dxm:VectorLayer DataLoaded="VectorLayer_DataLoaded">
<dxm:ShapefileDataAdapter FileUri="Data/countries.shp" />
</dxm:VectorLayer>
</dxm:MapControl>
private void VectorLayer_DataLoaded(object sender, DataLoadedEventArgs e) {
mapControl.ZoomToFitLayerItems(new LayerBase[] { mapLayer });
}
Private Sub VectorLayer_DataLoaded(ByVal sender As Object, ByVal e As DataLoadedEventArgs)
mapControl.ZoomToFitLayerItems(New LayerBase() {mapLayer})
End Sub
You can change shape colors based on shape data. Refer to the following help topic for more information: Colorizers.
You can also group items of the same type. To do this, initialize the MapDataAdapterBase.Clusterer property with a clusterer.
The following code snippets (auto-collected from DevExpress Examples) contain references to the ShapefileDataAdapter 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.
wpf-map-load-vector-cartesian-data/CS/MapLesson2/MainWindow.xaml#L76
</dxm:VectorLayer.Colorizer>
<dxm:ShapefileDataAdapter FileUri="Data/Hotel1.shp">
<dxm:ShapefileDataAdapter.SourceCoordinateSystem>
<dxm:VectorLayer.Data >
<dxm:ShapefileDataAdapter FileUri="DXMapShapeFile1;component/ShapeFile/Countries.shp" />
</dxm:VectorLayer.Data>
wpf-map_implement-custom-map-projection/CS/CustomProjection/MainWindow.xaml#L18
<dxm:VectorLayer>
<dxm:ShapefileDataAdapter FileUri="Data/Countries.shp" />
</dxm:VectorLayer>
map-wpf-manually-load-a-cartesian-map-shapefile/CS/BuildInCoordinateConverters/MainWindow.xaml#L105
<dxm:VectorLayer ShapeFill="#40FF8800">
<dxm:ShapefileDataAdapter
SourceCoordinateSystem="{Binding Path=SelectedValue.CoordinateSystem, ElementName=lbMapData}"
Object DispatcherObject DependencyObject Freezable MapDependencyObject MapDataAdapterBase CoordinateSystemDataAdapterBase ShapefileDataAdapter
See Also