This project has moved and is read-only. For the latest updates, please go here.

GetFeatureInfo in v0.9

Topics: SharpMap v0.9 / v1.x
Apr 8, 2010 at 9:46 AM

Hi guys,

I'm currently busy adding the GetFeatureInfo functionality to the SharpMap WMS (I really needed it for my project). I'm using the latest 0.9 code, because, according to the Features, the 2.0 has no complete WMS functionality, and the latest 0.9 code offers some nice functionality for styling rasterlayers.

It's already accepting the GetFeatureInfo requests and sending back plain text  as a response, both from vectorlayers as from GDalrasterlayer, so I'm making progress. 

I'm not a crack in programming and new to sharing open source code, so I don't know how to share and discuss this new functionality with you.

can you give me some help and explain me how I could share and discuss this?



Apr 8, 2010 at 12:14 PM

Hello PeaceNLove,

people who want to share their work for sharpmap are always welcome to do so via the SourceCode | UploadPatch page here on codeplex. Please announce this patch on the forum, too, since most people do not regularilly scan the patches section.

It is then being discussed in this forum or on the page created for the patch page, where users leave comments or can vote for it to be implemented.

Other than that you may find some developers on in the channel #sharpmap.

Hth FObermaier

Apr 8, 2010 at 3:55 PM

Thanks. I'll upload the patch tomorrow.


Apr 9, 2010 at 3:21 PM

I've added the patch with the GetFeatureInfo request possibility.

I've made the following changes.

ICanQueryLayer .cs: Added a boolean in ICanQueryLayer to set layers queryable for the WMS

VectorLayer.cs, GdalRasterLayer.cs, Layergroup.cs: implemented this boolean of ICanQueryLayer

WmsServer.cs: added the getFeatureInfo thing

capabilities.cs: added the required getfeature information for the capabilities


The code added to wmsserver works as follows:

A getfeatureinfo request is received

Checks on all necessary parameters

The map size and boundingbox are set according to the settings of the client and the point clicked in the map of the client is translated to the coordinates of the projection using this new map size and bbox

The optional parameter FEATURES_COUNT is checked whether the client requests one or more features per layer

For each requested layer, it is checked whether the layer is queryable. When true, the layer is queried and all found features are placed in the featuredataset.

This featuredataset is then sorted on area size, because when the client requests a limited number of features, the user is more likely to be interested in the feature with the smallest bbox (imagine a very curved polygon like the character C and a small polygon within the bbox of the 'C' polygon. If the user clicks the small polygon, both the 'C' polygon bbox and the small polygon bbox will be returned. When the FEATURES_COUNT is set to 1, only the feature attributes of the 'C' polygon might be send back, instead of the small polygon attributes the user wanted to see. By sorting on bboxarea from small to large, the small polygon attribute information will be send back. If the user wants to see attribute information of the 'C' polygon, he will click the 'C' polygon and the click will only be within the 'C' polygon bbox and not within the small polygon bbox (hope this is clear to you;-))

Then for each feature that will be returned to the user (as set by FEATURES_COUNT) all the ItemArrays from the featuredataset are placed in the string.

I've added exceptions where necessary. I should have added an exception for quering layers which are set WMSQueryable= false, but I forgot ;-)

A difference between the WMS1.1.1 spec and the WMS 1.3.0 spec is the parameter name of the point clicked by the user. It used to be X and Y in 1.1.1, but this has changed to I and J in 1.3.0. In order to make life a little bit easy for myself in OpenLayers and for others which might not know about this change, I added support for X and Y as well. If both are within the Request, the I and J will overwrite values set by X and Y. Including neither X&Y nor I&J will result in an exception.

These are the major changes.


Because somebody might not want queries on his WMS, I've added a variable to VectorLayer.cs, GdalRasterLayer.cs, Layergroup.cs, which sets querying by the WMS on or off. This is checked in wmsserver.cs to allow a query and in capabilities to set the query attribute of the layer.

And off course the capabilties.cs is modified to include the GetFeatureInfo in the GetCapabilities.


I tested the functionality using polygon data (shapefile) and rasterdata(ASCII) using EPSG:28992 Dutch Rijksdriehoekstelsel


Hth, PeaceNlove





Apr 12, 2010 at 10:08 AM



I've found a bug in ExecuteIntersectionQuery of GdalRasterLayer.

//Test if raster ordinates are within bounds
if (x < 0 || y < 0) return;
if (x >= _imagesize.Width) return; <--the 'x' was a 'y'  and therefore, things went wrong later on, because a point outside the map area could be queried
if (y >= _imagesize.Height) return;

I already uploaded the new version of GdalRasterLayer which fixes this.




Apr 12, 2010 at 3:11 PM

Thanks for the patches! 

I have little time right now but will look at it somewhere in the next week.


Apr 20, 2010 at 9:52 PM

I applied both. Thanks a lot!