Tag: Web Map Service

Beware of decimal pixel values in OpenLayers.

Posted by – Wednesday 2012-12-19

So you are programming an OpenLayers based map viewer and attempt to make a WMS GetFeatureInfo request. The response will later be pretty-formatted and displayed to the user. In order to to accomplish this you create JavaScript code like the shown below:

var parameters = {
    srs: map.getProjection(),
    bbox: map.getExtent().toBBOX(6),
    width: map.getSize().w,
    height: map.getSize().h,
    x: evt.xy.x,
    y: evt.xy.y,
    layers: 'municipalities',
    query_layers: 'municipalities'

    method: 'get',
    url: this.getFeatureInfoUrl,
    async: false,
    params: parameters,
    success: function(data) {
       var responseText = data.responseText;
       // ...

where evt (lines 6 and 7) represents the mouse click event that triggered the GetFeatureInfo request.


GeoServer SQL views.

Posted by – Monday 2012-08-20

In this post we will see a simple example of how GeoServer’s SQL views [note 1] can be used to derive multiple layers from a single SQL table.

1. The arena.

I had a table in a PostGIS database that stores the geometries of all roads in the province of Lugo. Each road has a geometry and a set of attributes. One of these attributes is ‘owner’, which stores the road owner: a municipality, a province, a regional government or the central government.

From this table I needed to generate four WMS layers: roads owned by municipalities, roads owned by the the province, and so on.


Annotation layers in GeoServer.

Posted by – Saturday 2012-07-21

Currently I am working in a project that requires switching from MapServer to GeoServer. As a newcomer to the latter, one of the things I miss is MapServer’s annotation layers. An annotation layer is one that just shows labels, like names of towns or countries. In this post we will see how annotation layers can be implemented using GeoServer.

1. The arena.

In our example there is already an existing WMS layer named ‘municipalities’, that contains the borders of some municipalities of Galicia and whose geometry type is multipolygon. The data source is a shapefile. The following screenshot – taken from GeoServer’s administration application – shows the attributes the municipalities have.

GeoServer screenshot

Our goal is showing the municipalities names in a different WMS layer, so an user of the WMS service can toggle the visibility of this annotation layer, that is, being able to show or hide, in every moment, the municipalities’ names. The names of the municipalities are stored in the attribute ‘NOMBRE’.


WMS cascading with MapServer.

Posted by – Saturday 2012-06-30

MapServer supports WMS cascading. Recently I have used this feature to serve an ortophoto layer which was already being served from an old WMS service. This feature has allowed me to avoid copying the ortophoto to the new server. Given that orthopotos usually demand lots of hard disk space – even when they are compressed in formats like ECW or MrSID -, I have saved time and storage capacity.

Cascading WMS is easy with MapServer. Just edit the mapfile and add a new layer like the one shown below:


Implementing the WMS GetLegendGraphic request with MapServer.

Posted by – Thursday 2012-05-10

UNM’s MapServer supports the WMS request GetLegendGraphic, which according to the WMS specification is not mandatory [note 1].

Fortunately, configuring MapServer to get the WMS server returning the legend graphic for each layer is easy. Unfortunately, the manual section explaining how to do it seems, at least to me, a bit hidden; here is the link: http://bit.ly/Kp3xQx.


[note 1] While UNM’s MapServer – which is free and open source software – as of version 5.2.1, released in January 2009, supported the GetLegendGraphic request, ArcGIS Server – commercial software – did not do it (http://bit.ly/JCcynz) until version 10, released circa October 2011.