File talk:BlankMap-Equirectangular.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Natural Earth Vectors in the Cloud[edit]

I made this map, after I found this post on Bjørn Sandvik's Mapping Blog. Hey took the data from Natural Earth and converted it to various formats, including SVG. You can find all the data in this Google Fusion Table (therefore "the cloud"), there's also a link on the blog. Now these data contain not only borders of states but much much much much more. Take a look yourself.

Anyway, I downloaded only the borders of sovereign states, with full name, 3-letter-acronym and the svg-data (in exactly this order as CSV).

Then I wrote the following python script, to convert it to an SVG file:

source = open('downloaded.csv', 'r')
result = open('result.svg', 'w')

source.readline() # throw away first line with headers
paths = source.readlines()

# xml-svg-header stuff
result.write('<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n\n<svg xmlns="http://www.w3.org/2000/svg"\n     xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events"\n     version="1.1" baseProfile="full"\n     width="360" height="180">\n\n\n<g id="positioner" transform="translate(180, 90) scale(1, -1)">\n\n')

paths2 = []
# split up each line in a vector containing the 3 fields name, acronym and svg-path-data
for path in paths:
	temp = path.rstrip("\n").split(",")
	paths2.append(temp[1:2] + temp[2:3]) # only use acronym and path-data

paths2.sort() # sort according to alphabetical order of acronyms

oldname = ""
result.write('<g id="dummy">')

# go through the paths and group them if the acronyms are the same (different parts of a country)
for path in paths2:
	if(path[0] != oldname):
		result.write('\n</g>\n\n<g id="' + path[0] + '">\n')

	result.write('<path d="' + path[1] + '" style="opacity:1;fill:#444444;fill-opacity:1;fill-rule:evenodd;stroke:none;" />\n')


result.write('\n</g>\n\n</g>\n\n\n</svg>')

source.close()
result.close()

As you can see in the tables, there's much more information in the tables. Even the names of different islands. You could integrate all this into the SVG-file, if you want e.g. every single path having a meaningful ID.


Alternative: GMT[edit]

The data from Natural Earth is in the ESRI format, which is a special format for map data. But you can convert it. Credit goes to Tentotwo. Have a look at [a map he created] and scroll down, there's the script he used. As well as a link to GMT. Installing it is a pain, but it's really worth it. You can actually choose a map projection and export everything as Postscript file. Open it with Inkscape and save it as SVG.

Problem is, you loose all the information, like names of the countries. But the order of the path-elements is still the same as the order of the shapes in the .gmt-file, which is created in an intermediate step. Is is a plaintext format and still contains all the information. With some regular expressions and stuff, you can surely get then into the SVG.

I needed an equirectangular projection with not to much independent paths (but grouped as counties), so I used the already prepared data from Bjørn Sandvik. But if you need some other projection, GMT your way to go.

Script for colorizing selected countries[edit]

I have written an awk script (wrapped in shell) that takes as its input the original SVG file and a list of country codes (one per line, as used in the SVG file) and outputs a modified version of the SVG file with the selected countries shown in another color (dark green in this example):

cat BlankMap-Equirectangular.svg | awk 'BEGIN { while((getline CODE < "codelist") > 0) CODES[CODE]=1; NEXT=0 } NEXT { sub(/#444444/, "#008000", $0); NEXT=0 } /<g/ { split($0, PARTS, "\""); if(length(PARTS) == 3) { if(PARTS[2] in CODES) NEXT=1 } } 1' > MyMap-Equirectangular.svg

Maybe somebody will find it useful. I have used it to produce File:International Youth Congress of Esperanto host countries equirectangular.svg. Marek BLAHUŠ (talk) 21:23, 1 August 2012 (UTC)[reply]

New version[edit]

I edited the SVG file to fix a couple of issues I found with it.

First of all, ids in XML (and SVG) must be unique within the document. Repeated ids made the original SVG file invalid.

Also, that awkward script to change country colors. Such concoction shouldn't be necessary in this day and age. SVG elements can be styled with CSS, you know.

  • Replaced all ISO 3166-1 alpha-3 ids with classes, e.g. <g id="AFG"> with <g class="country AFG">
  • Removed all inline styles, replaced by a single class .country, defined at an inline style sheet.
  • Added different ids for territories, and grouped them in a class for each country.
  • Added an example of how to change the color of a given country.

Example: All U.S. territories had the same id #US1, replaced with #US1, #US2, #US3... and added the class .USA for ease of styling.

Also, I added a comment for each .GBR territory I could identify. Someone might want to identify all other dependencies and territories, or maybe change those opaque #XXn ids with something more reasonable.

Locoluis (talk) 04:07, 6 August 2014 (UTC)[reply]

I can't find the country Tuvalu on the map. I think it is missing. Is it possible to have a corrected version of the map? I don't have the skills to use the script, and the data is no longer available. Arospide (talk) 16:06, 13 March 2022 (UTC)[reply]