Tag: WMS

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’.


Custom legend icons in MapServer.

Posted by – Thursday 2012-07-05

As seen in a recent post in this blog, MapServer implements the optional WMS request GetLegendGraphic.

You can find that the generated icons do not fit your needs, and prefer that MapServer returns custom legend icons provided by you. Let’s see how can it be accomplished.

First, is convenient that in your LEGEND object you supply the icons size; in our example, it will be 20×20 pixels.

    KEYSIZE 20 20
END # end of legend object


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: