HomeHome ArchiveArchive

Ubuntu PostGIS package for PostgreSQL 9.0

A while ago I’ve compiled PostGIS 1.5.2 for PostgreSQL 9.0.

To install it on Ubuntu the following steps are required:

apt-get install python-software-properties

add-apt-repository ppa:ubuntugis/ubuntugis-unstable
add-apt-repository ppa:pitti/postgresql
add-apt-repository ppa:pi-deb/gis

apt-get update

apt-get install postgresql-9.0-postgis

A basic template database can be created with the following commands:

sudo su - postgres

createdb template_postgis
psql -q -d template_postgis -f /usr/share/postgresql/9.0/contrib/postgis-1.5/postgis.sql
psql -q -d template_postgis -f /usr/share/postgresql/9.0/contrib/postgis-1.5/spatial_ref_sys.sql
psql -q -d template_postgis -f /usr/share/postgresql/9.0/contrib/postgis_comments.sql
cat <<EOS | psql -d template_postgis
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';
REVOKE ALL ON SCHEMA public FROM public;
GRANT USAGE ON SCHEMA public TO public;
GRANT ALL ON SCHEMA public TO postgres;
GRANT SELECT, UPDATE, INSERT, DELETE
  ON TABLE public.geometry_columns TO PUBLIC;
GRANT SELECT, UPDATE, INSERT, DELETE
  ON TABLE public.spatial_ref_sys TO PUBLIC;
EOS

To test database creation you can do the following:

createdb --template template_postgis test_gis
psql -d test_gis -c "select postgis_lib_version();"

Ubuntu supports parallel installations of different PostgreSQL versions. So if you have already PostgreSQL 8.x installed, PostgreSQL 9.0 will probably be configured to listen on port 5433. So you have to add the option -p 5433 to each command and to specify the full path for the executables. For example:

/usr/lib/postgresql/9.0/bin/psql -p 5433 -d test_gis -c "select postgis_lib_version();"

OpenLayers plugin visits code sprint

A short visit and 7 hours train ride to the OpenLayers code sprint mainly for a presentation at the Swiss MapFish user group meeting in Lausanne, resulted in a new release of the QGIS OpenLayers plugin. The OpenLayers plugin adds WebKit based layers to QGIS and ships with OpenStreetMap-, Google- and Yahoo-Layers.

Changes in this release:

  • Update to OpenLayers trunk
  • Google Layers using API V3 (no API key necessary)
  • Code refactoring for adding new layer types with one line of code (and some HTML…)

The next planned step is integrating this plugin with the very nice Openlayers Overview plugin from Luiz Motta.

Information for adding your own layers and a bug tracker is now available at hub.qgis.org/projects/openlayers

Web based printing with QGIS server

QGIS server is already known as a full featured, WMS 1.3 compliant map server (see e.g. ETHZ, Linfiniti or 3LIZ).

For the city of Uster, Switzerland, Sourcepole recently extended QGIS server with the possibility to use the print composer via WMS in order to offer printing functionality for web maps. A very nice GeoExt based client can be found at http://gis.uster.ch/webgis/. Andreas Neumann used and extended the GeoExt PrintProvider and PrintExtent classes which allows the user to intuitively select a layout, extent, scale, rotation and resolution for printing. The widget then sends a GetPrint request to QGIS server and a printable PDF is returned.

Now to the technical details: in order to use the print capability of QGIS server, the published project needs to contain one or more print compositions. QGIS server includes information about the available composer templates in the GetCapabilities response:

<WMS_Capabilities> … <ComposerTemplates xsi:type=”wms:_ExtendedCapabilities”> <ComposerTemplate width=”297” height=”210” name=”Composer 1”> <ComposerMap width=”102” height=”95” name=”map0”/> <ComposerMap width=”133” height=”79.87912087912088” name=”map1”/> <ComposerLabel name=”hello_world”/> </ComposerTemplate> </ComposerTemplates> …

With a ‘GetPrint’ request, the client may now request printable output in png or pdf format. The client needs to select an available composer template and needs to pass the selected extents for the composer maps. Additionally, there is the possibility to replace the text of composer labels. An example for a ‘GetPrint’ request is (note the new ‘TEMPLATE’ and ‘map0:extent’ Parameters):

http://localhost/fcgi-bin/qgis_mapserver/qgis_mapserv.fcgi?MAP=/home/marco/geodaten/projekte/composertest.qgs&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetPrint&TEMPLATE=Composer 1&map0:extent=693457.466131,227122.338236,700476.845177,230609.807051&BBOX=693457.466131,227122.338236,700476.845177,230609.807051&CRS=EPSG:21781&WIDTH=1467&HEIGHT=729&LAYERS=layer0,layer1&STYLES=,&FORMAT=pdf&DPI=300&TRANSPARENT=true

In detail, the following parameters can be used to set properties for composer maps:

  • <mapname>:EXTENT=<xmin,ymin,xmax, ymax> //mandatory
  • <mapname>:ROTATION=<double> //optional, defaults to 0
  • <mapname>:SCALE=<double> //optional. Forces scale denominator as server and client may have different scale calculations
  • <mapname>:LAYERS=<comma separated list with layer names> //optional. Defaults to all layer in the WMS request
  • <mapname>:STYLES=<comma separated list with style names> //optional
  • <mapname>:GRID_INTERVAL_X=<double> //set the grid interval in x-direction for composer grids
  • <mapname>:GRID_INTERVAL_Y=<double> //set the grid interval in x-direction for composer grids

To replace text in composer labels, the label needs to have a text id (can be assigned in the print composer user interface of the composer label). The text to insert into the label can be passed in the GetPrint request with an additional parameter =text (of course, the label id should be different to the standard WMS parameters…).

Besides printing, an additional nice feature in the most recent developer version is the possibility to also use relative pathes in published project files. Like this, it’s possible to conveniently export a project file recursively together with the corresponding data.

Finally, I’d like to thank the city of Uster and Andreas Neumann for the generous support and the creative ideas during the implementation of the printing functionality.

Working with big files/calling external scripts in JMeter

(This article is part of the JMeter Series)

JMeter’s “HTTP Request Sampler” will read the whole input (the downloaded page, pdf, movie etc.) into its main memory. That means that working with larger (f.ex. movies) files will bring JMeter, the JVM and/or many machines to their memory limits.

If you do not not need to do more than making sure that something gets downloaded, then you can “offload” the download work to an outside process, f.ex. to curl or wget:

Downloading with curl Screenshot

A few things to note:

  • I used the “BeanShell Sampler” module, since both the “BeanShell Pre-“ and the “PostProcessors” are only executed when there’s something to process after another sampler produced some data.

  • As you can see, we are passing a JMeter variable to the script

  • Aparently JMeter or the BeanShell do not care much about the output of the exec’ed script, thus you won’t see anything inside the “Response data” in the “View Results Tree Sampler”. I don’t know whether that behaveour is a missing feature, a bug or for some unknown reason intended as such.

You can download this JMeter test from here

Tomáš Pospíšek, 30.12.2010