SourceForge Logo

Example

Here is a small sample xml project file. It assumes you have a shp vector map (but it maybe a grass vector map) "usa", describing the States and a table "usa_states" in a postgres database somewhere whith the following fields:

  1. id: a number which link the row in the dbf (or the category for the grass case) to an area in the map "usa".
  2. state_names: with the name of the states in a printable form.
  3. voters: number of voters in the corresponding state.
  4. democrat: the current number of votes for the democrat in a generic election.
  5. republican: as above.
The result would be a map of the USA, and every state would be tiled with the symbol of the leading party. It would be possible to add the name of the states, or click on a state to know the actual numbers. The map would be kept up to date every 10 minutes.

<?xml version="1.0" ?><!DOCTYPE chapter SYSTEM "grules.dtd">
  <project id="us_demo"
          directory="/home/grules/projects/us_demo">
    <db id="default" dbms="postgres" host="somewhere.usa.org"
        user="nobody" passwd="none" database="elections"/>

    <theme id="usa_political">
       <layer id="states">
          <geo kind="shapes" file="/home/grules/maps/usa/states.shp">
          <table>
             <filler kind="dbf" file="/home/grules/maps/states.dbf">
                <field id="name" db="STATE_NAME" default=""/>
             </filler>

             <filler kind="database" db="default">
                <key id="id" db="id"/>
                <field id="voters" db="voters" default=""/>
                <field id="republicans" db="republicans" default=""/>
                <field id="democrats" db="democrats" default=""/>
                <all>
                 <![CDATA[select id, voters, democrats, republican,
                                    'REPUBLICAN' as winner
		          from usa_states where republicans > democrats union
		          select id, voters, democrats, republican, 'DEMOCRAT' as winner
		          from usa_states where republicans < democrats;]]>
               </all>
               <single>
                 <![CDATA[select id, voters, democrats, republican,
                                    'REPUBLICAN' as winner
      	             from usa_states where republicans > democrats
                     and <id>=id  union
	             select id, voters, democrats, republican, 'DEMOCRAT' as winner
	             from usa_states where republicans < democrats
                     and <id>=id;]]>
               </single>
             </filler>
           </table>
         
           <graphic>
             <rule kind="default" attr="BORDER" default="127:127:127:255"/>
             <rule kind="map" attr="TILE">
                <pair key="REPUBLICAN" value="republican.png"/>
                <pair key="DEMOCRAT" value="democrat.png"/>
             </rule>
	     <rule kind="default" ATTR="LABEL_FRONT" default="10:10:10:255"/>
	     <rule kind="default" ATTR="LABEL_SIZE" default="8"/>
             <rule kind="default" ATTR="LABEL_FONT" 
                      default="/usr/share/fonts/times.ttf"/>
             <rule kind="direct" attr="LABEL_TEXT" field="name"/>
           </graphic>
       </layer>
    </theme>
 </project>

Table of contents Home