Back to Devexpress

How to: Load a Vector Cartesian Map from a Shapefile

windowsforms-17743-controls-and-libraries-map-control-examples-vector-data-customize-data-appearance-how-to-load-a-vector-cartesian-map-from-a-shapefile.md

latest1.9 KB
Original Source

How to: Load a Vector Cartesian Map from a Shapefile

  • Nov 13, 2018

To load a vector Cartesian map, do the following.

  1. Crete a ShapefileDataAdapter object.
  2. Set its CoordinateSystemDataAdapterBase.SourceCoordinateSystem property to a CartesianSourceCoordinateSystem object.
  3. Specify its FileDataAdapterBase.FileUri property.
  4. Assign this object to the VectorItemsLayer.Data property.
csharp
// Create a vector layer and add it to the map.
    VectorItemsLayer hotelLayer = new VectorItemsLayer() {
        Data = CreateData(),
        Colorizer = CreateColorizer()
    };
    map.Layers.Add(hotelLayer);
// Creates a shapefile data adapter.
private IMapDataAdapter CreateData() {
    Uri baseUri = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location);

    ShapefileDataAdapter adapter = new ShapefileDataAdapter() {
        SourceCoordinateSystem = new CartesianSourceCoordinateSystem(),
        FileUri = new Uri(baseUri, filepath)
    };

    return adapter;
}
vb
' Create a vector layer and add it to the map.
    Dim hotelLayer As New VectorItemsLayer() With {.Data = CreateData(), .Colorizer = CreateColorizer()}
    map.Layers.Add(hotelLayer)
' Creates a shapefile data adapter.
Private Function CreateData() As IMapDataAdapter
    Dim baseUri As New Uri(System.Reflection.Assembly.GetEntryAssembly().Location)

    Dim adapter As New ShapefileDataAdapter() With {.SourceCoordinateSystem = New CartesianSourceCoordinateSystem(), .FileUri = New Uri(baseUri, filepath)}

    Return adapter
End Function