Convert vmap0 layers into shapefiles

The vmap0 dataset is a slightly dated, but anyhow often usable dataset of maps of all of the world in scale 1:1 000 000. It can be downloaded at e.g. mapability.com. The problem shows up as soon as one tries to use the dataset as it is in a quite unique format. Luckily, the format is known by ogr, so the data can be converted to something usable. When downloaded and unzipped, the dataset contains a lot of layers with various types of information. To get an overview, use ogrinfo:

ogrinfo -ro -summary gltp:/vrf/osgeo4w/share/maps/v0eur_5/vmaplv0/eurnasia

gltp is the protocol, vrf is the format. I unzipped my dataset (v0eur.tar.gz) into c:\osgeo4w\share\maps and the catalog structure below that point was made. The ogrinfo should list approximately 60 data sets. Each of those may be converted using ogr2ogr like

ogr2ogr landicea.shp gltp:/vrf/osgeo4w/share/maps/v0eur_5/vmaplv0/eurnasia landicea@phys(*)_area landicea 

To repeat this 60 times is a bit tedious, so let’s use the information from ogrinfo which makes a line like

33: landicea@phys(*)_area (Polygon)

for each dataset.

running this through the regexp

/[0-9]*\: \(\(.*\)@\(.*\)(.*\) (.*)/

gives out the the two strings we needs for ogr2ogr. (The regexp throws away any number of numbers followed by a colon and space then captures the following string, the part of that string which is before an @-sign and the part of the string between the 2 and the next opening paranthesis then throws away a space and something inside a pair of parantesies). if we use sed to run this, the command

sed 's![0-9]*\: \(\(.*\)@\(.*\)(.*\) (.*)!ogr2ogr v0\2\3.shp gltp:/vrf/osgeo4w/share/maps/v0eur_5/vmaplv0/eurnasia \1 \2!' < vmap0layers 

will return the ogr2ogr command lines needed to do the conversion to shape files.

So let's put it all together:

set uri=gltp:/vrf/osgeo4w/share/maps/v0eur_5/vmaplv0/eurnasia
ogrinfo -ro -summary %uri% > vmap0layers
sed 's![0-9]*\: \(\(.*\)@\(.*\)(.*\) (.*)!ogr2ogr v0\2\3.shp %uri% \1 \2!' < vmap0layers  > converts.bat

(I was using ! to mark the regexp to avoid problems with the slashes in the directory) The script above was tested in cmd and 4nt on windows xp. a slightly changed version should work in /bin/sh or compatibles;

export uri=gltp:/vrf/osgeo4w/share/maps/v0eur_5/vmaplv0/eurnasia
ogrinfo -ro -summary $uri > vmap0layers
sed 's![0-9]*\: \(\(.*\)@\(.*\)(.*\) (.*)!ogr2ogr v0\2\3.shp  $uri \1 \2!' < vmap0layers  > converts.bat

Just remember to adjust the uri variable to whereever your maps are stored.

Thanks to grymoire for some reminders on sed and to blacksworld.net for explanation to extract the layers one by one.

sed (stream editor) is a standard unix / linux utility. It can be installed on windows as a part of the osgeo4w suite.

This entry was posted in Diverse, mapserver. Bookmark the permalink.