We present here an application of SVG to the on-line production of maps for the analysis of results of elections. We use Cocoon -from the Apache foundation- to facilitate this production. The used method is easily generalizable for different data source.
We wanted to supply a Web site ( http://shadok.enst.fr:8080/election/) which allows every guest to produce his own spatial analysis of the results of the presidential elections 2002 in France. For each of 36000 French administrative divisions (municipalities), we have the percentage obtained by every candidate, the percentage of voters, the percentage of abstentions, the percentage of blanks or invalids votes. We authorize all the combinations of these results to produce a map. Furthermore, the proposed method can be easily modified to process other data.
The most difficult part of the process is to get the data. Then, the only step in our process which is not easily generalizable is the initial production of the data in our XML format. However, the necessary converters are rather simple to produce.
The interface is a simple form which allows:
to choose a geographic zone,
to decide how to combine the results of the candidates; for each, we decide either to spread the results, or to count them positively, or to count them negatively; for example, if we count Mamere positively and Lepage negatively, we are going to highlight the balance between these two candidates.
Every map mainly consists of a path by municipality. A sample of SVG code for a municipality is:
<path id="C04006-1" fill="rgb(0,0,0)" onmouseover="zin('C04006')" onmouseout="zou('C04006')" d="M414 299 L418 289L427 293L429 298... L414 299z"/>
The 'id' field allows to do the link
with the names of municipality which appear when the mouse is over the corresponding path
and with the results of the municipality (as it is discussed below).
Base maps were once prepared for every geographic zone. A possible evolution consists in putting the coordinates of the municipalities in a geographic database and to build the map on demand according to a request in the database.
The results of the calculation defined by the form are calculated. So a value is associated to every municipality of the selection. We sort out the municipalities following this value. We separate the municipalities in N classes having the same number of municipalities. For every class, we get the minimum and maximum value. This interval is going to serve us for choosing a colour: cold colours for the negative values, warm colours for the positive values; colours poorly saturated near zeros, colours darker and\or more saturated far from zero. Once a colour is linked to each class and knowing the value associated to every municipality, we make an XSLT transformation to give the good value to the 'fill' field in the path associated with each municipality.
Cocoon parse the calling URL to choose some processing to do to generate a document as the URL response.
Cocoon allows us quite easily:
to chain XSLT transformations,
to use parameters from the calling URL as parameters for the XSLT transformations,
to aggregate some XML sources befor applying an XSLT transformation.
For our maps, we have the following chain of processing:
- data of the chosen geographic zone are processed by an XSLT transformation to apply them the chosen calculation; it gives an XML representation of the results of the calculation,
- a transformation is then applied which allocates a class to every municipality, a color is associated with each obtained class,
- results of the calculation, classes/colours association and the SVG 'source' map are aggregated,
an XSLT transformation is applied to produce the map from this aggregate,
then the map is sent to the user after a GZIP compression.
Every stage produces an XML representation, which move from step to step by SAX events. So, an XML file is not really created for each step. A file is created only if it could be used in the cache.
The XSLT transformations are compiled once during their first use.
Cocoon allows to benefit from a powerful caching mechanism. Cocoon allows us to internationalize easily our maps generation by using a list of all textual messages shown on a map contained in an XML file for each supported language.
Afterward, we have planed to::
- generalize the method and make it accessible (WebService?),
exploit the possibilities offered by SVG 1.2 when 1.2 will be available (facilitated for selectively zoom parts of a SVG document SVG, text flow...)
from a user point of view, we would like to give the possibility to store his parameters and a comment to constitute a best-of of the produced maps.