I know this thread is a bit stale, but I really liked Bordaigorl's answer above. Yet I am lazy, so I wrote a little perl script that translates the Inkscape-output into a nice macro source, along the lines of Bordaigorl's example above.
Steps to do:
- Download the SVG-map from Wikipedia. I used the World Map and also the "compact" version, which is a bit more flat and excludes the polar regions. So that is https://commons.wikimedia.org/wiki/File:BlankMap-World6.svg and https://commons.wikimedia.org/wiki/File:BlankMap-World6,_compact.svg.
- Open the SVG-file is Inkscape and export it as Tikz. In the export options, enable "verbose" mode, as this puts in all the object names as comments.
- Now path it through the perl script I add below, such as
cat Worldmap-raw.tex | ./Map2tikz.pl >Worldmap.tex
- Include the file in TeX. An example is below as well. Depending on the Inkscape output, the "ocean" may be caught as a path and would end up with a style option [Map/state, Map/xx], which gives an error in the first TeX-run. In this case, open the Workmap.tex file, find the Map/xx text (somewhere around line 8 usually) and remove the whole "[Map/state, Map/SD]" part – or replace by a nice ocean style if you prefer.
- Exhibit happiness!
Here the perl-part:
#!/usr/bin/perl
# First written: Mon 2018-05-07 11:37:16 UTC+0200 (CEST) by Hendrik G. Seliger
# Last changes: Mon 2018-05-07 14:36:54 UTC+0200 (CEST) by Hendrik G. Seliger
# A script to read a map exported by Inkscape as verbose tikz
# and set proper path names so we can highlight countries/states
# by using their identifier
###
$, = ' '; # set output field separator
$\ = "\n"; # set output record separator
# While reading the file, we create three variables
# Set_Defaults: contains the command to set defaults for all regions
# Set_Commands: contains the code to set up commands to change each regions style
# Create_Map: The outline of the actual map. This changes the tikzpicture into a scope
$Set_Defaults = "\\tikzset{Map/.cd, state/.style={fill, draw=white, ultra thick}";
$Set_Commands = "\\tikzset{every state/.style={Map/state/.style={#1}}";
$Create_Map = "\\newcommand{\\Map}[1][]{";
# The we use a variable to always catch the current path name = state identifier
# We use "xx" to mark an unset state
$Current_State = "xx";
while ( <STDIN> ) {
# chomp; # strip record separator
# Remember current line, as we will change it further down
$Current_Line = $_;
# Get the current state/country identifier
if ( $Current_Line =~ /% (\w\w)$/) {
$Current_State = $1;
# Make it upper case
$Current_State =~ s/(.)/\u$1/g;
$Set_Defaults .= ", " . $Current_State . "/.style={}";
$Set_Commands .= ", " . $Current_State . "/.style={Map/" . $Current_State . "/.style={#1}}";
}
# rewrite path commands
# \path -> \path[Map/state, Map/XX]
# checking for "path " with space at end keeps the global/ocean background
# which is exactly what we want
if ( $Current_Line =~ /\\path /) {
# Determine current style
$Style = "[Map/state, Map/" . $Current_State . "] ";
$Current_Line =~ s/path /path$Style/g;
}
# rewrite start if tikzpicture
# \begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt] -> [y=0.80pt,x=0.80pt,yscale=-1, inner sep=0pt, outer sep=0pt,#1]
if ($Current_Line =~ /\\begin{tikzpicture}\[(.*)\](.*)$/ ) {
$Current_Line = "\\begin{scope}[" . $1 .",#1]" . $2 . "\n";
}
if ($Current_Line =~ /\\end{tikzpicture}/ ) {
$Current_Line =~ s/\\end{tikzpicture}//g;
}
$Create_Map .= $Current_Line;
}
$Set_Defaults .= '}';
$Set_Commands .= '}';
$Create_Map .= "\\end{scope}}";
print $Set_Defaults;
print $Set_Commands;
print $Create_Map;
##### END OF MAIN, SUBROUTINES NEXT #####
Beware that the perl script does no error checking, so if you twiddle with the Inkscape output, it's not going to fly. And, it also may not work with other map files, e.g. if the country/state areas are not names properly.
BTW, I check on two-letter-identifiers for states/countries only, as this collects countries with several regions, such as MI on the US map, or France on the world map. The latter is a good example of breakdown at the next level, as all the departments are not names, so just exported by Inkscape as e.g. "path2168".
And a sample TeX-file (I use lualatex, as my normal pdflatex exceeds its memory on the world map):
% !TeX TS-program = lualatex
\documentclass{standalone}
\usepackage{tikz}
\input{Worldmap.tex}
\begin{document}
\begin{tikzpicture}
\Map[every state={draw=white, ultra thick, fill=black!10},DE={fill=blue},US={fill=red}]
\end{tikzpicture}
\end{document}
And per request, a screenshot of the resulting map:

Maybe this helps the one or the other.