Back to Devexpress

ShapefileDataAdapter Class

wpf-devexpress-dot-xpf-dot-map-c72946c4.md

latest8.7 KB
Original Source

ShapefileDataAdapter Class

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

Declaration

csharp
public class ShapefileDataAdapter :
    CoordinateSystemDataAdapterBase,
    ISupportDataLoading
vb
Public Class ShapefileDataAdapter
    Inherits CoordinateSystemDataAdapterBase
    Implements ISupportDataLoading

Remarks

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 .shp file that contains data about geometries.
  • The .dbf file that contains data associated with geometries (for example, names and GDP values for countries).

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).

|

MapDot

| |

PolyLine,
PolylineM (the M value is ignored),
PolylineZ (the Z value is ignored).

|

MapPolyline

| |

Polygon,
PolygonM (the M value is ignored),
PolygonZ (the Z value is ignored).

|

MapPolygon

|

For more information about shapefile element types, refer to ERSI Shapefile Technical Description.

Load Data

Follow the steps below to load data from a shapefile:

xaml
<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.

Access and Customize Map Items

When vector items are loaded, the MapGeoDataAdapter.ShapesLoaded event occurs. Use the e.Shapes property to access loaded shapes.

xaml
<dxm:MapControl>
  <dxm:VectorLayer>
    <dxm:ShapefileDataAdapter FileUri="Data/Countries.shp"
                              ShapesLoaded="ShapefileDataAdapter_ShapesLoaded"/>
  </dxm:VectorLayer>
</dxm:MapControl>
csharp
private void ShapefileDataAdapter_ShapesLoaded(object sender, DevExpress.Xpf.Map.ShapesLoadedEventArgs e) {
  foreach (MapPath item in e.Shapes) {
      item.Fill = Brushes.Gray;
  }
}
vb
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.

xaml
<dxm:MapControl x:Name="mapControl">
 <dxm:VectorLayer DataLoaded="VectorLayer_DataLoaded">
   <dxm:ShapefileDataAdapter FileUri="Data/countries.shp" />
 </dxm:VectorLayer>
</dxm:MapControl>
csharp
private void VectorLayer_DataLoaded(object sender, DataLoadedEventArgs e) {
  mapControl.ZoomToFitLayerItems(new LayerBase[] { mapLayer });
}
vb
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

xml
</dxm:VectorLayer.Colorizer>
<dxm:ShapefileDataAdapter FileUri="Data/Hotel1.shp">
    <dxm:ShapefileDataAdapter.SourceCoordinateSystem>

wpf-map-use-ray-casting-algorithm-to-check-if-point-is-inside-polygon/CS/DXMapShapeFile1/MainWindow.xaml#L9

xml
<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

xml
<dxm:VectorLayer>
    <dxm:ShapefileDataAdapter FileUri="Data/Countries.shp" />
</dxm:VectorLayer>

map-wpf-manually-load-a-cartesian-map-shapefile/CS/BuildInCoordinateConverters/MainWindow.xaml#L105

xml
<dxm:VectorLayer ShapeFill="#40FF8800">
    <dxm:ShapefileDataAdapter
        SourceCoordinateSystem="{Binding Path=SelectedValue.CoordinateSystem, ElementName=lbMapData}"

Inheritance

Object DispatcherObject DependencyObject Freezable MapDependencyObject MapDataAdapterBase CoordinateSystemDataAdapterBase ShapefileDataAdapter

See Also

ShapefileDataAdapter Members

Load Vector Items from Vector Format Source

DevExpress.Xpf.Map Namespace