At FOSS4G 2006 in Lausanne, I presented a technical talk titled “Mapping election results with CartoWeb” in the Webmapping / Location Based Services (LBS) session.
The presentation was based on a project built for the communal elections in the Canton of Vaud, Switzerland, held on 12 March 2006. The goal of the project was to publish election results online as thematic maps while the official results were arriving during the day.
The application was built with CartoWeb 3.2, MapServer, PostgreSQL and PostGIS.
Project Context
The project had several constraints:
- election results had to be published as soon as they became available;
- data-entry errors had to be minimized;
- many similar thematic layers had to be generated quickly;
- class intervals had to adapt automatically to the values being published;
- the site had to handle a peak in traffic on election day;
- the application had to be built in a short timeframe.
The cartographic part was thematic mapping. The operational part was the publication workflow: transforming official results into updated maps with limited manual work while users were accessing the site.
Software Choice
CartoWeb was chosen because it was accessible from the browser without requiring a plugin, and because it could be adapted to the needs of the project.
The application combined CartoWeb and MapServer for map rendering, with PostgreSQL/PostGIS as the data backend.
Generating The Thematic Layers
One part of the project was the generation of multiple thematic layers.
CartoWeb’s autolayer functionality made it possible to generate similar layers from a template. This was useful for election maps, where the same mapping logic had to be repeated across multiple political parties and indicators.
The application also used pseudo-dynamic MapServer mapfile generation. The mapfile was produced from a PHP template, and CartoWeb’s makemaps.php script was used to regenerate it when new values entered the database.
The script could compute the minimum and maximum values for a layer, derive the thematic class intervals, and write the corresponding MapServer expressions into the generated mapfile.
When new election results were imported, the classification logic and map publication tables could be regenerated.
Reducing Manual Work On Election Day
On election day, human intervention had to be limited mainly to acquiring and importing the official data.
The workflow used OpenOffice Calc macros to generate SQL insert commands from the official result sheets. This reduced the risk of manual typing errors and made it possible to copy the generated commands into the database import process.
After import, publication tables and the mapfile were regenerated.
Designing For Traffic
Traffic was a central concern.
A normal interactive web map can generate a very large number of possible map images because users can freely pan and zoom. Every different extent, layer combination or map size can produce a new image.
For this election application, the interaction model was deliberately constrained. Free pan and free zoom were disabled. Instead, users could select predefined areas from a drop-down menu.
This reduced the possible number of map outputs to a defined set:
- 14 thematic maps;
- 2 years;
- 20 predefined areas;
- 2 image sizes.
That produced 1,120 possible cached maps and allowed CartoWeb’s image caching mechanism to be used more effectively.
Whenever the database was updated, the cache could be cleaned so that new maps would be generated with the latest results.
Database Tuning
The initial database design used views to compute percentages, identify winners, join data and calculate evolutions between election years.
View access became a bottleneck with many public visitors. The application needed simple select operations during peak usage.
The solution was to materialize the views used by the application. A PL/pgSQL script generated tables from the normalized structure, so the public web mapping application could query precomputed data instead of repeating joins and calculations for every request.
What Happened On Election Day
The website was unknown before election day, but it was linked by major Swiss media during the event, including TSR, RSR, Le Temps and Rouge FM.
The traffic was significant:
- Sunday: 1,614,810 hits, 5,518 visitors, 50,333 page views, 6.9 GB bandwidth;
- Monday: 664,277 hits, 3,079 visitors, 19,834 page views, 2.8 GB bandwidth.
For a regional election mapping application, these traffic figures were significant and comparable to those of major Swiss media websites at the time.
Edit 2026: Looking Back
Looking back from 2026, this project already contained many themes that still matter in geospatial digital products today:
- open-source GIS as practical infrastructure;
- rapid delivery under the constraints of a public event;
- automated data publication workflows;
- thematic cartography with adaptive classification;
- performance engineering for public traffic;
- data modelling versus publication optimization;
- making official information accessible through spatial interfaces.
It was also an early reminder that a good geospatial product is not only about maps. It is about the full chain: data acquisition, quality control, automation, classification, rendering, caching, infrastructure, user access and operational pressure.
This remains one of the main lessons I take from the project.