Archive

Author Archives: underdark

Martin Dobias’ weekly reports on his project to speed up QGIS [1] are being published on QGIS wiki.

Currently, we’re in week #4 and things look good! Thumbs up!

[1] http://blog.qgis.org/node/144

It sounds incredible, but it’s true: OGC Filter Encoding in it’s current version 1.1 lacks an IN operator [1]. Combining multiple PropertyIsEqualTo using ORs performs really badly both on Arcgis Server [2] and Geoserver [3]. That calls for the implementation of this standard-exceeding IN operator. Maybe PropertyIsIn?

[1] http://www.opengeospatial.org/standards/filter
[2] http://viswaug.wordpress.com/2009/01/20/filter-encoding-standard-11-and-the-curious-case-of-the-missing-in-operator/
[3] https://underdark.wordpress.com/2010/06/10/dynamic-styling-and-filtering-of-a-geoserver-wms-using-openlayers-layer-wms-post/

There is a new layer class in OpenLayers API: OpenLayers.Layer.WMS.Post [1]. – Great work!

While the “normal” OpenLayers.Layer.WMS class requests maps via HTTP GET, this new class sends the request via HTTP POST. This way, we can now send big client-side created SLD files in our GetMap requests that used to exceed size limits of GET.

This code snippet shows the basic use of OpenLayers.Layer.WMS.Post with a client-side created SLD. You’ll need at least OpenLayers 2.9 to test this on your server. (A full example can be found at http://www.openlayers.org/dev/examples/wms-long-url.html)

var sld = 'define your SLD here';

wms = new OpenLayers.Layer.WMS.Post(
  "name",
  "http://localhost:8080/geoserver/wms",
  {
    'layers': 'myNs:layername',
    format: 'image/jpeg',
    sld_body: sld
  },
  {
    unsupportedBrowsers: []
  }
);

Setting unsupportedBrowsers to an empty list is important! This list by default contains [“mozilla”, “firefox”, “opera”]. These browsers support long GET requests so the developers argued that these browsers wouldn’t need to use POST. Well, turns out that they do ;)

I performed a small stress test using an SLD with approximately 1,000 rules being applied on a big city road network. While my browser would willingly send a GET request of that size, Apache doesn’t want to accept it. So, I tried the POST way and it turns out that it really works! (But it’s slow, very slow …)

Thanks to the developers for yet another great feature!

[1] http://trac.openlayers.org/ticket/2224

During this year’s Google Summer of Code Martin Dobias will work on speeding up QGIS [1]. His goals are:

  1. Introduce parallelism into rendering
  2. Improve user experience when browsing map
  3. Optimization of map rendering
  4. Miscellaneous optimizations

[1] http://blog.qgis.org/node/144

Usually, I use CQL filter statements to dynamically filter features in a Geoserver WMS. These CQL filters can be added easily to the URL and Geoserver responds accordingly. There’s just one problem: There is a size limit for URLs and (very!) long filter statements won’t fit in. (And I’m not talking about the limit imposed by IE, but the more serious one in Apache.) This makes it necessary to switch from HTTP GET to POST. An easy way to send POST requests is using curl:

curl --data-binary @getMap.xml -H "Content-Type: text/xml" -o map.png "http://localhost:8080/geoserver/wms/GetMap"

I found that it’s important to use –data-binary to avoid that the text in getMap.xml is interpreted in any way. The “@” tells curl that a filename follows. Furthermore it’s necessary to specify the Content-Type. This results in the PNG map being stored in the current directory. My getMap.xml looks like follows:

<?xml version="1.0" encoding="UTF-8"?>
<ogc:GetMap
xmlns:ogc="http://www.opengis.net/ows"
xmlns:gml="http://www.opengis.net/gml"
version="1.1.1" service="WMS">

<StyledLayerDescriptor version="1.0.0">
<NamedLayer>
 <Name>myNs:roads</Name>
 <NamedStyle>
  <Name>simple_roads</Name>
 </NamedStyle>
</NamedLayer>
</StyledLayerDescriptor>

<BoundingBox srsName="http://www.opengis.net/gml/srs/epsg.xml#31287">
<gml:coord>
<gml:X>621005.1594799113</gml:X>
<gml:Y>471313.0306986364</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>635174.7245025429</gml:X>
<gml:Y>484404.226939031</gml:Y>
</gml:coord>
</BoundingBox>

<Output>
 <Format>image/png</Format>
 <Size>
 <Width>600</Width>
 <Height>320</Height>
 </Size>
</Output>

<Exceptions>application/vnd.ogc.se+xml</Exceptions>

</ogc:GetMap>

It’s also pretty straightforward to add a filter to the NamedLayer element. Basically it can be copied from any SLD you have at hand.

Today I’ve been fighting again with how to get GetFeatureInfo working in my Geoserver, Apache, Tomcat environment. It’s pretty simple actually: One needs a proxy which I put in
/usr/lib/cgi-bin/proxy.cgi.

Proxy code can be found in OpenLayers-2.9/examples/proxy.cgi (Download the full package of OpenLayers and use it instead of the package that ships with Geoserver). Add all necessary hosts to allowedHosts list.

Don’t forget to set it executable:
sudo chmod +x /usr/lib/cgi-bin/proxy.cgi

To tell your website to use the proxy, add the following javascript line:
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

Geoserver and Mapserver are both quite powerful but their developers pursued different goals.

To make the choice easier for you (I hope), here comes a general feature comparison:

Geoserver Mapserver
WMS both are good maybe a bit better [1]
WFS better, supports WFS-T [1] no WFS-T [1]
Technology J2EE [1] CGI [1]
Project start 2003 [1] 1996 [1]
Administration Web tool Mapfile generation can be aided by QGIS, but not comparable to Geoserver’s web admin tool
Extensibility good for Java developers [1] PHP Mapscript, good for PHP developers [1]
Cartography uses standardized SLDs powerful; styles are part of mapfile
Services one WMS/WFS/WCS service for all users [1] a mapfile means a service [1]
Querying CQL and OGC filters embedded SQL statements

New benchmarking results should be available soon [2]. Meanwhile, you might wanna watch last years results [3].

[1] http://osgeo-org.1803224.n2.nabble.com/Mapserver-vs-Geoserver-td4905798.html

[2] http://wiki.osgeo.org/wiki/Benchmarking_2010

[3] http://www.slideshare.net/gatewaygeomatics.com/wms-performance-shootout

Openstreetmap offers a handy API for querying their database: XAPI. You’ll find the docs on their wiki at http://wiki.openstreetmap.org/wiki/Xapi.

To download all traffic signals within a certain bounding box:
http://xapi.openstreetmap.org/api/0.6/node[highway=traffic_signals][bbox=16.26,48.18,16.31,48.20]