SharpMap and WPF

A few weeks ago, I blogged about the end of the line for MapObjects. I waxed nostalgic about how fun it was to develop with MO and how, although I haven’t used it in a while, I’ll still be sad to see it go.

Well, I’m glad I’m over that! I been working with SharpMap for the last few weeks and I’m feeling that old MO vibe again. It started a few weeks ago with developing a data provider for SQLite (read here) but I’ve continued to look under the hood.

Lately, I’ve been working a project where we need to feed some spatial data into native WPF display. WPF offers high performance and great graphics quality. In addition, there are numerous other types of data involved that also need to be displayed. We didn’t want dedicated display components for each type of data so we decided to bring the spatial data into WPF.

I started looking at SharpMap because it gives us quite a few data options, has a robust geometry model and also includes a decent set of spatial operations. In addition, it’s open source and free. The open source nature of SharpMap was a huge plus and I’m having fun doing things that I always wanted to do in MO. One thing is extend it support a new data source (ala SQLite). Another thing is to redirect layer rendering elsewhere.

SharpMap includes ASP.NET 2.0 and Winforms 2.0 controls. It features rendering objects that are distinct from the UI on which they are rendering. It’s a model that allows for great flexibility.

In my current project, I am collaborating with a group outstanding developers working different pieces who already had a strong application framework in place. There already existed rendering and display components so I just had to extend those to understand geometry objects coming out of SharpMap. Being open source, it was really easy to dig under the hood to see what the objects were doing so I could integrate better.

So I read from the database, create the geometry objects and then feed them into a renderer that transforms them to screen space and converts them to WPF geometries for rendering. Pretty straightforward and, at a high level, exactly what you would do in COM and WinForms but still kinda neat given that I don’t need an AxMapControl or some such other thing to pull off a free-standing app.

This is where I would normally post some code but I just got it working and my code is a) still ugly and b) still intertwined with a lot of other people’s code. Once I get it cleaned up some, I can post some samples. But here’s a little map…

WPF Canvas

This depicts one layer loaded into a WPF canvas control. It’s still a little skewed and need some other work but I was excited to see it on the screen. It’s been a while since I’ve had to deal with the nitty gritty of device rendering. ESRI always handled that for me 😀

It’s been quite fun coming up to speed on two APIs with which I’m not terribly familiar (SharpMap and WPF). Again, the SharpMap source code was a lifesaver. It didn’t have anything to help with WPF per se but it was great reference as I was trying figure out behaviors. If you browse the SVN trunk for SharpMap 2.0, you’ll see that they’re planning to handle WPF but there’s no code there yet. I can’t wait see what they com up with. Anyway, here’s one for the SharpMap team…

The beer you’ve been practicing for.


Posted

in

, , ,

by

Tags:

Comments

6 responses to “SharpMap and WPF”

  1. SharpMap is the new MapObjects? Avatar

    […] Bill Dollins is talking about how SharpMap is giving him back his “old MO vibe again”. What caught me eye was: The open source nature of SharpMap was a huge plus and I’m having fun doing things that I always wanted to do in MO. […]

  2. […] (XAML) which is also used by Windows Presentation Framework (WPF) – check out Bill Dollins post on SharpMap and WPF for a usecase example of GIS and WPF. If you have ever looked at XAML, it resembles Scalar Vector […]

  3. Going a different direction Avatar

    […] find it interesting to see another ESRI developer look outside the ESRI stable for a replacement to MapObjects. There was some concern among many […]

  4. GeoMusings Is SharpMap Viable? « Avatar

    […] SharpMap and WPF […]

  5. Dave Lowther Avatar

    Bill,

    Interested in chatting with you about the WPF+SharpMap work you’ve done. I’m about to head in that same direction.

    Drop me an email.

  6. MSDN Article on Mapping with WPF « GeoMusings Avatar

    […] been using WPF with SharpMap on a project for a while but my mapping code is about 5% of the overall project and I haven’t had a chance to extract […]