New to Telerik UI for WPF? Download free 30-day trial

Shapefiles Support

The ESRI Shapefiles or simply the shapefiles are popular format for storing geographical data. The files spatially describe geometries like lines, polylines and polygons. These geometries may represent different geographical objects such as countries, roads, rivers, lakes etc. Via a software that supports the format, the geometries can be translated properly on a map.

To learn more about the shapefiles, read this article.

This topic will explain the following:

Reading Shapefiles with RadMap

To read your data you have to use the MapShapeReader class. To learn more about its general usage read the Shape Reader topic.

To pass the desired shapefile you have to use the Source property of the MapShapeReader and pass the Uri to the desired .shp file to it. The shape file can be accompanied by additional files containing information which is related to the shapes. Example for such file is the .dbf, which holds attribute related to the shapes in the main file. The RadMap allows you to use these types of files. To pass one to the reader use the DataSource property and set it to the respective Uri.

<telerik:RadMap x:Name="radMap"> 
    <telerik:InformationLayer x:Name="informationLayer"> 
        <telerik:InformationLayer.Reader> 
            <telerik:MapShapeReader DataSource="/Silverlight.Help.RadMapSamples;component/Data/world.dbf" 
                                    Source="/Silverlight.Help.RadMapSamples;component/Data/world.shp" /> 
        </telerik:InformationLayer.Reader> 
    </telerik:InformationLayer> 
</telerik:RadMap> 

this.informationLayer.Reader = new MapShapeReader(); 
this.informationLayer.Reader.Source = new Uri( "/Silverlight.Help.RadMapSamples;component/Data/world.shp", UriKind.RelativeOrAbsolute ); 
this.informationLayer.Reader.DataSource = new Uri( "/Silverlight.Help.RadMapSamples;component/Data/world.dbf", UriKind.RelativeOrAbsolute ); 
Me.informationLayer.Reader = New MapShapeReader() 
Me.informationLayer.Reader.Source = New Uri( "/Silverlight.Help.RadMapSamples;component/Data/world.shp", UriKind.RelativeOrAbsolute ) 
Me.informationLayer.Reader.DataSource = New Uri( "/Silverlight.Help.RadMapSamples;component/Data/world.dbf", UriKind.RelativeOrAbsolute ) 

Manual Shape Reading

The RadMap allows you to manually read the file, by which you are able to get the shapes collection, without to automatically insert it into the layer. For this purpose you have to use the ShapeFileReader static class.

First of all read the Shapefile as a resource stream. Note that the file must have its BuildAction set to Resource. After that call the static Read() method of the ShapefileReader class and pass the resource stream to it. It returns a list of FrameworkElement objects, which you can directly add to the InformationLayer of the RadMap.

StreamResourceInfo shapeResourceInfo = Application.GetResourceStream( new Uri( "/Silverlight.Help.RadMapSamples;component/Data/world.shp", UriKind.RelativeOrAbsolute ) ); 
StreamResourceInfo dbfResourceInfo = Application.GetResourceStream( new Uri( "/Silverlight.Help.RadMapSamples;component/Data/world.dbf", UriKind.RelativeOrAbsolute ) ); 
List<FrameworkElement> shapes = ShapeFileReader.Read( shapeResourceInfo.Stream, dbfResourceInfo.Stream ); 
foreach ( var shape in shapes ) 
{ 
    this.informationLayer.Items.Add( shape ); 
} 
Dim shapeResourceInfo As StreamResourceInfo = Application.GetResourceStream(New Uri("/Silverlight.Help.RadMapSamples;component/Data/world.shp", UriKind.RelativeOrAbsolute)) 
Dim dbfResourceInfo As StreamResourceInfo = Application.GetResourceStream(New Uri("/Silverlight.Help.RadMapSamples;component/Data/world.dbf", UriKind.RelativeOrAbsolute)) 
Dim shapes As List(Of FrameworkElement) = ShapeFileReader.Read(shapeResourceInfo.Stream, dbfResourceInfo.Stream) 
For Each shape In shapes 
 Me.informationLayer.Items.Add(shape) 
Next shape 

RadMap provides built-in converters for the following coordinate systems EPSG:4326 (Mercator, degrees) <-> OSGB36 (National Grid UK), EPSG:4326 (Mercator, degrees) <-> EPSG:900913 (Mercator, meters). This allows you to use shapefiles created for OSGB36 or EPSG:900913 with map providers that use EPSG:4326 so it is possible to show such shapefiles "as is" over the BingMaps or OpenStreetMap imagery data. The converter (OSGB36Converter/ EPSG900913Converter) can be specified by setting the MapShapeReader.CoordinateConverter property.

See Also

In this article