SharpGIS

#GIS from a .NET developer's perspective

SharpMap v0.9 release moving closer

A lot have been happening to SharpMap lately. Several new features are already available in the alpha release. Here are some of the features that now readily are available:

  • Gradient Theme now works on not only fill-color, but all numeric style properties, giving even greater flexibility for controlling font-sizes, pen and outline color and widths etc. based on a numeric attribute.
  • Custom Theme: Define your own method that determines the style of a feature based on geometry and feature attribute. Ex. "Make all polygons with an area>100 and whose name starts with "S" green with a blue outline.
  • Symbols can now be scaled.
  • Create a WMS server with only very few lines of code.
  • Labels can now follow lines, or be rotated based on an attribute.
  • Lots of bug-fixes and optimizations.
  • Use any OleDb datasource that holds X and Y columns for creating a point layer.

Diego Guidi - who is the developer of NetTopologySuite has also created a link between SharpMap and NTS. This means that you instantly get all the great functionality of NTS inside SharpMap, including on-the-fly transformation, buffering etc. You can apply any custom method that performs NTS operations on any SharpMap datasource and render the result with SharpMap. Get it at the download section.

Download at http://sharpmap.iter.dk

Using GDAL from C#

Recently Frank Warmerdam and Michael Paul posted some examples on calling GDAL from .NET. This is pretty cool, since this enables you to access a great set of tools that I for one have been accessing by generating batch-files in a .NET application and then running them using the shell-commands (not pretty but it worked :-)

Their posts used several links to pointers and didn't have automatical garbage collection. Since disposing objects is very important when calling unmanaged code, and .NET developers isn't that used to pointers, I decided to wrap some of the GDAL functionaly into a few classes with automatic disposer etc. It still needs some brushing off and to include some more GDAL functionality, but let me know what you think. You can download it here.

MapServer Enterprise

Yesterday The MapServer Foundation announced the availability of the new (and free!) MapServer Enterprise sponsored by AutoDesk.
They state that it also supports .NET, which sounds like goodies for a .NET/GIS guy like me, so I definitely had to check it out.

I must admit that their ASP.NET examples shocked my completely. I can’t recall seeing that poor .NET code the last couple of years. It’s all ASP-style spaghetti-code and ridiculously poor implemented. I wouldn’t be surprised that if you rename the file-extensions to .asp, it would still run :-) Although I’m still exited by this new release, I can’t help thinking that if this is the best they can do in a .NET environment, what does the actual server-code look like?

SharpMap as a WMS server

Today I was trying to make a WMS implementation using SharpMap, and it turned out to be quite easy. I’ve implemented some helper classes in SharpMap, which I will include in the next release of SharpMap. Actually now you can create a WMS service using only a few lines of code. Here’s an example:

protected void Page_Load(object sender, EventArgs e)
{
    SharpMap.Map myMap = InitializeMap(); //Call method that sets up your map
    SharpMap.Web.Wms.WmsServer.ParseQueryString(Request.QueryString,Response,myMap);
}
And that’s it !!! (well at least besides the InitializeMap method where you set up layers etc…)

It even returns nice little XML exceptions according to the specification. I still need to do some work on the GetCapabilities request, but I think it’s more or less safe to say that SharpMap will work as an OpenGIS compliant WMS Server in the next release.

SharpMap Sourcecode and WMS support

The source code for SharpMap is now available too, as well as some feature changes. Biggest change is support for using WMS layers. I you don’t have access to vector data or a PostGreSQL database, you can still aggregate data from several WMS servers and display them in you very own map application. I’m still working on shape file and raster support.

Rendering maps using .NET

Last night I was, just for fun, fooling around with creating my own mapserver engine using native .NET and GDI+ methods, combined with a PostGreSQL/PostGIS database. Until now I got Points, Labels and Line layertypes implemented.
I didn’t expect much of the speed, but it turned out that GDI+’s drawing methods and anti-aliasing rendering combined with .NETs automatic connection pooling provided me with an ultra fast map render engine. And just by exposing LineStyles as System.Drawing.Pen you get a vast amount of options for customizing the look of the rendered output. And it even looks great! I’m all ecstatic about the result, and will probably follow this further with more geometry types and additional data-providers (shapefile, Oracle etc). I’ll post some results here later.