Archive for June, 2011

WPF is making a lot of noise these days, I was wondering what this new technology is all about and decided to give it a try.

Coming from WinForm world, describing GUIs in text (XAML) seemed awkward to me, I struggled a bit  getting my first window up and running but managed to do so at the end.

In order to understand what is laying underneath WPF, I thought I should write my proper user control that can display something like a map.

Here is a screenshot of my first attempt to write such a control.

This control is based on SharpMap (http://sharpmap.codeplex.com/), reads and displays ESRI shape files.

For now, I am using SharpMap as it is. All what I did is to use the library, load some shape files and display them in an image control.

// Event handler for button click
public void OpenShapeFileClicked(object sender, EventArgs e){
      // ... ask the user to provide a shape file using a file open dialog control
public void LoadShapeFile(string fileName){
      SharpMap.Layers.VectorLayer myLayer = new SharpMap.Layers.VectorLayer("ShapeFiles");
      myLayer.DataSource = new SharpMap.Data.Providers.ShapeFile("path_to_file", true);
      myLayer.Style.Fill = System.Drawing.Brushes.GreenYellow;
      myLayer.Style.Outline = new System.Drawing.Pen(System.Drawing.Brushes.Gray);
      myLayer.Style.Line.Width = 2;
      myLayer.Style.Line = new System.Drawing.Pen(System.Drawing.Brushes.Black);
private void DrawImage(){
      // Convert System.Drawing.Image to ImageSource to wich an image is bound
      using (Bitmap bitmap = new Bitmap(myMap.GetMap())){
             IntPtr hBitmap = bitmap.GetHbitmap();
             // Use System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap
             BitmapSource bitmapSource = CreateBitmapSourceFromHBitmap(
             // Set image1 control data source
             image1.Source = bitmapSource;

This project is not about rewriting a new SharpMap library for WPF but rather build up a WPF application from scratch based on SharpMap which I strongly believe will give me a great insight of the WPF technology and how GIS applications work.

In this little introduction, we demonstrated how easy it is to create a basic GIS application using WPF.

To be continued…

Read Full Post »