Jump to content

File:SwedishGeneralElection2010-map.svg

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Original file (SVG file, nominally 290 × 654 pixels, file size: 262 KB)

Description
English: Swedish general election 2010 relative coalition support breakdown by municipality. Although the Red-Greens are dominant on a wider area, the urban population of South decided the election for the Alliance. The data has been fed through a Laplace distribution function to make the regional differences seem more pronounced. Support is relative to all votes cast to one of the seven coalition parties. Open the image in browser for overall statistics.

Key: 00 The Alliance dominance 00 Red-Green dominance 00 Equal dominance

Based on SWE-Map Kommuner2007.svg by Lokal_Profil, scripted with Nokogiri  by Hydrox.
Date
Source Own work based on: SWE-Map Kommuner2007.svg by Lokal_Profil
Author Hydrox
Permission
(Reusing this file)
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 2.5 Generic license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Other versions File:SwedishGeneralElection2010-map-SwedenDemocrats.svg – Breakdown of relative support to Sweden Democrats, the only elected non-coalition party.
SVG development
InfoField
 
The source code of this SVG is invalid due to 290 errors.
 
This W3C-invalid map was created with Inkscape.

Source code

SweMap.rb
require "SweMapDB.rb"

# How to use this script in Ubuntu:
# 1) sudo aptitude install ruby1.8 libnokogiri-ruby
# 2) Place SweMapDB.rb and the source map in the same directory as this script.
# 3) Download regional ballots from the Election Authority:
#   for i in `seq 1 9`; do
#     wget -O $i.html "http://www.val.se/val/val2010/slutresultat/R/rvalkrets/0$i/index.html"
#   done
#   for i in `seq 10 29`; do
#     wget -O $i.html "http://www.val.se/val/val2010/slutresultat/R/rvalkrets/$i/index.html"
#   done
# 4) ruby1.8 SweMap.rb


# Set source map
MAP = SweMap.load "SWE-Map_Kommuner2007.svg"

# Laplace function parameters
MU = 0.5
B = 0.15
def lcdf(x)
  return 0.5 * Math.exp((x-MU) / B) if x < MU
  return 1 - 0.5 * Math.exp((-x+MU)/B)
end

def color(kommun, right, left, total)
  r = 0xff * lcdf((left.to_f / total))
  b = 0xff * lcdf((right.to_f / total))
  MAP.style kommun, "fill", "rgb(#{r.round}, 0, #{b.round})"
end

kommunf = Hash.new { |hash, key| key }
kommunf['Malung-Sälen'] = 'Malung'
kommunf['I vallokal ej räknade röster'] = false

parties = %w(M, C, FP, KD, S, V, MP, SD, ÖVR, BLANK, OG)

(1..29).each do |v|
  fn = "#{v}.html"
  doc = Nokogiri::HTML(open(fn))
  doc.errors.each { |e| raise "Parse error in #{fn}" if e.fatal? }
  if [1,9,11,16].include? v
    table = doc.css('table [class="sorteringsbar_tabell"]')[1].css "tbody:last-child"
    summa = true
  else
    table = doc.css('table >tbody[class="sorteringsbara_rader"]')[1]
    summa = false
  end
  raise "No table!" if not table
  table.children.each do |row|
    if row.elem?
      if summa
        kommun = kommunf[row.at_css('td:first-child').inner_text]
        if v >= 10
          link = "http://www.val.se/val/val2010/slutresultat/R/rvalkrets/#{v}/index.html"
        else
          link = "http://www.val.se/val/val2010/slutresultat/R/rvalkrets/0#{v}/index.html"
        end
      else
        a = row.at_css('td:first-child a')
        kommun = kommunf[]["title"]
        link = "http://www.val.se/val/val2010/slutresultat/R/rvalkrets/#{v}/" + a["href"]
      end
      if kommun
        right = left = sd = ovr = blank = og = total = 0
        row.css("td.relativ_nej").each_with_index do |e,i|
          n = e.inner_text.to_i
          if i <= 3
            right += n
          elsif i <= 6
            left += n
          elsif i == 7
            sd = n
          elsif i == 8
            ovr = n
          elsif i == 9
            blank = n
          elsif i == 10
            og = n
          elsif i == 11
            total = n
          end
        end
        color kommun, right, left, total-blank-og-sd-ovr
        MAP.link kommun, link, "#{kommun} / "+
            "AL: #{(1000.0 * right/(total-blank-og)).round / 10.0}% " +
            "RG: #{(1000.0 *  left/(total-blank-og)).round / 10.0}%"
      end
    end
  end
end

MAP.write("SwedishGeneralElection2010-map.svg")
SweMapDB.rb
begin
  require "rubygems"
rescue LoadError
end
require "nokogiri"

SCB = {
  "AB" => {
    "0114" => "Upplands Väsby",
    "0115" => "Vallentuna",
    "0117" => "Österåker",
    "0120" => "Värmdö",
    "0123" => "Järfälla",
    "0125" => "Ekerö",
    "0126" => "Huddinge",
    "0127" => "Botkyrka",
    "0128" => "Salem",
    "0136" => "Haninge",
    "0138" => "Tyresö",
    "0139" => "Upplands-Bro",
    "0140" => "Nykvarn",
    "0160" => "Täby",
    "0162" => "Danderyd",
    "0163" => "Sollentuna",
    "0180" => "Stockholm",
    "0181" => "Södertälje",
    "0182" => "Nacka",
    "0183" => "Sundbyberg",
    "0184" => "Solna",
    "0186" => "Lidingö",
    "0187" => "Vaxholm",
    "0188" => "Norrtälje",
    "0191" => "Sigtuna",
    "0192" => "Nynäshamn"
  },
  "C" => {
    "0305" => "Håbo",
    "0319" => "Älvkarleby",
    "0330" => "Knivsta",
    "0331" => "Heby",
    "0360" => "Tierp",
    "0380" => "Uppsala",
    "0381" => "Enköping",
    "0382" => "Östhammar"
  },
  "D" => {
    "0428" => "Vingåker",
    "0461" => "Gnesta",
    "0480" => "Nyköping",
    "0481" => "Oxelösund",
    "0482" => "Flen",
    "0483" => "Katrineholm",
    "0484" => "Eskilstuna",
    "0486" => "Strängnäs",
    "0488" => "Trosa"
  },
  "E" => {
    "0509" => "Ödeshög",
    "0512" => "Ydre",
    "0513" => "Kinda",
    "0560" => "Boxholm",
    "0561" => "Åtvidaberg",
    "0562" => "Finspång",
    "0563" => "Valdemarsvik",
    "0580" => "Linköping",
    "0581" => "Norrköping",
    "0582" => "Söderköping",
    "0583" => "Motala",
    "0584" => "Vadstena",
    "0586" => "Mjölby"
  },
  "F" => {
    "0604" => "Aneby",
    "0617" => "Gnosjö",
    "0642" => "Mullsjö",
    "0643" => "Habo",
    "0662" => "Gislaved",
    "0665" => "Vaggeryd",
    "0680" => "Jönköping",
    "0682" => "Nässjö",
    "0683" => "Värnamo",
    "0684" => "Sävsjö",
    "0685" => "Vetlanda",
    "0686" => "Eksjö",
    "0687" => "Tranås"
  },
  "G" => {
    "0760" => "Uppvidinge",
    "0761" => "Lessebo",
    "0763" => "Tingsryd",
    "0764" => "Alvesta",
    "0765" => "Älmhult",
    "0767" => "Markaryd",
    "0780" => "Växjö",
    "0781" => "Ljungby"
  },
  "H" => {
    "0821" => "Högsby",
    "0834" => "Torsås",
    "0840" => "Mörbylånga",
    "0860" => "Hultsfred",
    "0861" => "Mönsterås",
    "0862" => "Emmaboda",
    "0880" => "Kalmar",
    "0881" => "Nybro",
    "0882" => "Oskarshamn",
    "0883" => "Västervik",
    "0884" => "Vimmerby",
    "0885" => "Borgholm"
  },
  "I" => {
    "0980" => "Gotland"
  },
  "K" => {
    "1060" => "Olofström",
    "1080" => "Karlskrona",
    "1081" => "Ronneby",
    "1082" => "Karlshamn",
    "1083" => "Sölvesborg"
  },
  "M" => {
    "1214" => "Svalöv",
    "1230" => "Staffanstorp",
    "1231" => "Burlöv",
    "1233" => "Vellinge",
    "1256" => "Östra Göinge",
    "1257" => "Örkelljunga",
    "1260" => "Bjuv",
    "1261" => "Kävlinge",
    "1262" => "Lomma",
    "1263" => "Svedala",
    "1264" => "Skurup",
    "1265" => "Sjöbo",
    "1266" => "Hörby",
    "1267" => "Höör",
    "1270" => "Tomelilla",
    "1272" => "Bromölla",
    "1273" => "Osby",
    "1275" => "Perstorp",
    "1276" => "Klippan",
    "1277" => "Åstorp",
    "1278" => "Båstad",
    "1280" => "Malmö",
    "1281" => "Lund",
    "1282" => "Landskrona",
    "1283" => "Helsingborg",
    "1284" => "Höganäs",
    "1285" => "Eslöv",
    "1286" => "Ystad",
    "1287" => "Trelleborg",
    "1290" => "Kristianstad",
    "1291" => "Simrishamn",
    "1292" => "Ängelholm",
    "1293" => "Hässleholm"
  },
  "N" => {
    "1315" => "Hylte",
    "1380" => "Halmstad",
    "1381" => "Laholm",
    "1382" => "Falkenberg",
    "1383" => "Varberg",
    "1384" => "Kungsbacka"
  },
  "O" => {
    "1401" => "Härryda",
    "1402" => "Partille",
    "1407" => "Öckerö",
    "1415" => "Stenungsund",
    "1419" => "Tjörn",
    "1421" => "Orust",
    "1427" => "Sotenäs",
    "1430" => "Munkedal",
    "1435" => "Tanum",
    "1438" => "Dals-Ed",
    "1439" => "Färgelanda",
    "1440" => "Ale",
    "1441" => "Lerum",
    "1442" => "Vårgårda",
    "1443" => "Bollebygd",
    "1444" => "Grästorp",
    "1445" => "Essunga",
    "1446" => "Karlsborg",
    "1447" => "Gullspång",
    "1452" => "Tranemo",
    "1460" => "Bengtsfors",
    "1461" => "Mellerud",
    "1462" => "Lilla Edet",
    "1463" => "Mark",
    "1465" => "Svenljunga",
    "1466" => "Herrljunga",
    "1470" => "Vara",
    "1471" => "Götene",
    "1472" => "Tibro",
    "1473" => "Töreboda",
    "1480" => "Göteborg",
    "1481" => "Mölndal",
    "1482" => "Kungälv",
    "1484" => "Lysekil",
    "1485" => "Uddevalla",
    "1486" => "Strömstad",
    "1487" => "Vänersborg",
    "1488" => "Trollhättan",
    "1489" => "Alingsås",
    "1490" => "Borås",
    "1491" => "Ulricehamn",
    "1492" => "Åmål",
    "1493" => "Mariestad",
    "1494" => "Lidköping",
    "1495" => "Skara",
    "1496" => "Skövde",
    "1497" => "Hjo",
    "1498" => "Tidaholm",
    "1499" => "Falköping"
  },
  "S" => {
    "1715" => "Kil",
    "1730" => "Eda",
    "1737" => "Torsby",
    "1760" => "Storfors",
    "1761" => "Hammarö",
    "1762" => "Munkfors",
    "1763" => "Forshaga",
    "1764" => "Grums",
    "1765" => "Årjäng",
    "1766" => "Sunne",
    "1780" => "Karlstad",
    "1781" => "Kristinehamn",
    "1782" => "Filipstad",
    "1783" => "Hagfors",
    "1784" => "Arvika",
    "1785" => "Säffle"
  },
  "T" => {
    "1814" => "Lekeberg",
    "1860" => "Laxå",
    "1861" => "Hallsberg",
    "1862" => "Degerfors",
    "1863" => "Hällefors",
    "1864" => "Ljusnarsberg",
    "1880" => "Örebro",
    "1881" => "Kumla",
    "1882" => "Askersund",
    "1883" => "Karlskoga",
    "1884" => "Nora",
    "1885" => "Lindesberg"
  },
  "U" => {
    "1904" => "Skinnskatteberg",
    "1907" => "Surahammar",
    "1960" => "Kungsör",
    "1961" => "Hallstahammar",
    "1962" => "Norberg",
    "1980" => "Västerås",
    "1981" => "Sala",
    "1982" => "Fagersta",
    "1983" => "Köping",
    "1984" => "Arboga"
  },
  "W" => {
    "2021" => "Vansbro",
    "2023" => "Malung",
    "2026" => "Gagnef",
    "2029" => "Leksand",
    "2031" => "Rättvik",
    "2034" => "Orsa",
    "2039" => "Älvdalen",
    "2061" => "Smedjebacken",
    "2062" => "Mora",
    "2080" => "Falun",
    "2081" => "Borlänge",
    "2082" => "Säter",
    "2083" => "Hedemora",
    "2084" => "Avesta",
    "2085" => "Ludvika"
  },
  "X" => {
    "2101" => "Ockelbo",
    "2104" => "Hofors",
    "2121" => "Ovanåker",
    "2132" => "Nordanstig",
    "2161" => "Ljusdal",
    "2180" => "Gävle",
    "2181" => "Sandviken",
    "2182" => "Söderhamn",
    "2183" => "Bollnäs",
    "2184" => "Hudiksvall"
  },
  "Y" => {
    "2260" => "Ånge",
    "2262" => "Timrå",
    "2280" => "Härnösand",
    "2281" => "Sundsvall",
    "2282" => "Kramfors",
    "2283" => "Sollefteå",
    "2284" => "Örnsköldsvik"
  },
  "Z" => {
    "2303" => "Ragunda",
    "2305" => "Bräcke",
    "2309" => "Krokom",
    "2313" => "Strömsund",
    "2321" => "Åre",
    "2326" => "Berg",
    "2361" => "Härjedalen",
    "2380" => "Östersund"
  },
  "AC" => {
    "2401" => "Nordmaling",
    "2403" => "Bjurholm",
    "2404" => "Vindeln",
    "2409" => "Robertsfors",
    "2417" => "Norsjö",
    "2418" => "Malå",
    "2421" => "Storuman",
    "2422" => "Sorsele",
    "2425" => "Dorotea",
    "2460" => "Vännäs",
    "2462" => "Vilhelmina",
    "2463" => "Åsele",
    "2480" => "Umeå",
    "2481" => "Lycksele",
    "2482" => "Skellefteå"
  },
  "BD" => {
    "2505" => "Arvidsjaur",
    "2506" => "Arjeplog",
    "2510" => "Jokkmokk",
    "2513" => "Överkalix",
    "2514" => "Kalix",
    "2518" => "Övertorneå",
    "2521" => "Pajala",
    "2523" => "Gällivare",
    "2560" => "Älvsbyn",
    "2580" => "Luleå",
    "2581" => "Piteå",
    "2582" => "Boden",
    "2583" => "Haparanda",
    "2584" => "Kiruna"
  }
}

LAN = {
  "stockholm" => "A",
  "uppsala" => "C",
  "södermanland" => "D",
  "östergötland" => "E",
  "jönköping" => "F",
  "kronoberg" => "G",
  "kalmar" => "H",
  "gotland" => "I",
  "blekinge" => "K",
  "skåne" => "M",
  "halland" => "N",
  "västra götaland" => "O",
  "värmland" => "S",
  "örebro" => "T",
  "västmanland" => "U",
  "dalarna" => "W",
  "gävleborg" => "X",
  "västernorrland" => "Y",
  "jämtland" => "Z",
  "västerbotten" => "AC",
  "norrbotten" => "BD"
}

class SweMap
  
  public
  def self.load(filename, mode=:kommuns)
    begin
      return self.new(filename, mode)
    rescue
      error
    end
  end

  def style(name, attribute, value)
    begin
      set_style(get_element(name), attribute, value)
    rescue
      error
    end
  end
  
  def link(name, url, title=nil)
    begin
      link_to(get_element(name), url, title)
    rescue
      error
    end
  end
 
  def write(filename)
    begin
      open(filename, "w") { |f| @doc.write_to(f, :encoding => 'UTF-8') }
    rescue
      error
    end
  end

  private
  def initialize(filename, mode)
    @mode = mode
    open(filename) { |f| @doc = Nokogiri::XML(f) }
    raise "Could not find #{filename}" if @doc === nil

    @doc.errors.each { |e| raise "Parse error in #{filename}" if e.fatal? }

    @doc.root['xmlns:xlink'] = "http://www.w3.org/1999/xlink"

    if @mode == :kommuns
      @BCS = {}
      SCB.each_value {|h| h.each_pair { |c,k| @BCS[k.downcase] = c } }
    end
  end

  def get_element(name)
    if @mode == :kommuns
      id = get_kommun_id(name)
    else
      id = get_county_id(name)
    end

    el = @doc.at_css "*[id=\"#{id}\"]"
    if not (el and el.elem?)
      raise "Could not find id=\"#{id}\" in the SVG!"
    end

    return el
  end

  def get_kommun_id(kommun)
    if kommun.is_a? Fixnum
      id = "0" * (4-Math.log10(kommun+1).ceil) + kommun.to_s
    else
      id = @BCS[kommun.to_s.strip.downcase]
    end

    if not id
      raise "Where is '#{kommun}'? Check that you have the right name."
    end

    return id
  end

  def get_county_id(county)
    county = county.to_s
    
    if county.length > 2
      s = county.downcase
      id = LAN[s]
      id = LAN["#{s}s"] if not id
      if not id
        raise "Where is '#{county}'? Check that you have the right name."
      end
      return id
    else
      return county
    end
  end
  
  def set_style(group, attribute, value)
    re = Regexp.new "#{Regexp.quote(attribute)}\s*:[^;]*;"
    group.traverse do |el|
      if el.elem?
        if el.has_attribute? "style" and el["style"].strip.length > 0
          style = el["style"]
          if style.match re
            style = style.sub(re, "#{attribute}: #{value};")
          else
            style += " #{attribute}: #{value};"
          end
          el["style"] = style
        else
          el["style"] = "#{attribute}: #{value};"
        end
      end
    end
  end

  def link_to(el, url, title)
    par = @doc.create_element 'a'
    par["xlink:href"] = url
    par["xlink:title"] = title if title
    par.parent = el.parent
    el.parent = par
  end

  def error
    STDERR.puts "Error: #{$!}"
  end
end

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

26 September 2010

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current06:25, 26 September 2010Thumbnail for version as of 06:25, 26 September 2010290 × 654 (262 KB)Hydrox{{Information |Description={{en|1=Swedish general election 2010 relative coalition support breakdown by municipality. Although the Red-Greens are dominant on a wider area, the urban population in South decided the election for the Alliance. The data has b

Global file usage

The following other wikis use this file:

  • Usage on ast.wikipedia.org