This project has moved. For the latest updates, please go here.

ESRI Shapefiles and XAML Map Control

Sep 21, 2015 at 12:44 PM

Is it possible to add ESRI shapefiles as an overlay to BingMapsTileLayer? And is it possible to apply opacity property to it once added?

I need to show shapefile boundaries to an area of study with Bing Maps as my map.

Appreciate your help.
Sep 22, 2015 at 5:45 AM
Edited Sep 22, 2015 at 5:45 AM
You can add arbitrary overlays to the map. However, you have to load the shapefile and create a geometry from its content yourself. It is not supported out of the box.
Sep 24, 2015 at 8:11 PM
I've researched some ways to load a shapefile into XAML Map Control but I still can't quite figure it. Steps taken:
  1. Open the shapefile specify the path and name (I used OpenFileDialog to navigate to the file).
  2. Then I added a method "AddShapefile" to the Mapbase. I simply wanted to get the Extent of the shapefile.
  3. Then it should load the shapefile!
Unfortunately, opening the shapefile is more complex than I thought. I created a ShapeFile "library" (sort of) the shapefile. Below is my OpenShapefile code that I'm struggling with:

private ShapeFile OpenShapeFile(string path, string name, string renderFieldName)
        if (path.EndsWith(".shp", StringComparison.OrdinalIgnoreCase))
            path = path.Substring(0, path.Length - 4);
            throw new ArgumentException("path does not end in \".shp\"");

        ShapeFile sf = new ShapeFile();

        sf.Name = name;
        sf.MapProjectionType = this.projectionType;
        if (sf.RenderSettings != null) sf.RenderSettings.Dispose();
        sf.RenderSettings = new ShapefileLib.RenderSettings(path, renderFieldName, new System.Drawing.Font("Segoe UI", 6f));


        return sf;

     /// <summary>
    /// Load optimal render settings
    /// </summary>
    /// <param name="sf"></param>
    protected static void LoadOptimalRenderSettings(ShapeFile sf)
        System.Drawing.RectangleF r = sf.Extent;
        if (r.Top > 90 || r.Bottom < -90)
            //assume projected coordinates
            sf.RenderSettings.PenWidthScale = 5;
            System.Drawing.PointF pt = new System.Drawing.PointF(r.Left + r.Width / 2, r.Top + r.Height / 2);
            ShapefileLib.UtmCoordinate utm1 = ShapefileLib.ConversionFunctions.LLToUtm(ShapefileLib.ConversionFunctions.RefEllipse, pt.Y, pt.X);
            ShapefileLib.UtmCoordinate utm2 = utm1;
            utm2.Northing += 15;
            ShapefileLib.LatLongCoordinate ll = ShapefileLib.ConversionFunctions.UtmToLL(ShapefileLib.ConversionFunctions.RefEllipse, utm2);
            sf.RenderSettings.PenWidthScale = (float)Math.Abs(ll.Latitude - pt.Y);
private void RenderShapefiles()
        if (this.ActualWidth <= 0 || this.ActualHeight <= 0) return;
        if (screenBuf == null || (screenBuf.Size.Width != this.ActualWidth && screenBuf.Size.Height != this.ActualHeight))
            if (screenBuf != null)

            int newWidth = (int)this.ActualWidth;
            int newHeight = (int)this.ActualHeight;

            var newScreenBuf = GetBitmap();

            screenBuf = new System.Drawing.Bitmap(newWidth, newHeight);
        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(screenBuf);

            int width = (int)this.ActualWidth;
            int height = (int)this.ActualHeight;


            foreach (ShapeFile sf in myShapefiles)
                sf.Render(g, screenBuf.Size, this._centrePoint, this._zoomLevel, this.projectionType);
Sep 24, 2015 at 9:02 PM
Edited Sep 24, 2015 at 9:02 PM
I'm sorry, but reading the content of an ESRI shape file hasn't got anything to do with the map control.

Please ask that question somewhere else.
Sep 25, 2015 at 3:40 PM

Got it. Now, I'm able to read and overlay the shapefile into MapControl. However, it's not "projecting" into the map. It just sits on top of it and doesn't scale when I zoom-in or zoom-out.

Is this still a shapefile issue? Or, is there any more settings or methods I need to do to make it align with the boundaries of the map?
Sep 25, 2015 at 3:45 PM
Edited Sep 25, 2015 at 3:46 PM
I don't know, as you haven't shown what exactly your shapefile object is. But of course it will only transform from world to view coordinates if you use it in conjuction with e.g. a MapPolyline, or a MapOverlay or something like that. Take a look at the sample application that comes with the map control download to get an idea about which map elements are available and how they are added to a map.
Sep 25, 2015 at 9:03 PM

I'm almost there. Is there an equivalent code for the following in MapControl:

//Set the map view for the data set

The above snippet is taken from:
Sep 25, 2015 at 10:20 PM
Edited Sep 25, 2015 at 10:22 PM
In order to transform the bounding box from view to world coordinates, you would use the Map's ViewportPointToLocation method with two corners of the bounding box. An equivalent of SetView might be the ZoomMap method. Not sure if that's what you need. Again, please take a look at the sample application and the source code of the map control to get an idea of how it works.
Sep 29, 2015 at 1:52 PM

Finally figured it out. Somehow, the shapefile projection has to be in geographic coordinate system and WGS84. I was using NAD83 shapefiles and they were not showing in the map. With GCS-WGS84, they are showing. I think both Bing and Google maps are using WGS84 (World Mercator) projection. Thought others may find this helpful.
Marked as answer by DamaDeNoche on 9/30/2015 at 11:45 AM