{"id":706,"date":"2010-02-17T13:13:32","date_gmt":"2010-02-17T12:13:32","guid":{"rendered":"http:\/\/sickel.net\/blogg\/?p=706"},"modified":"2010-11-16T12:21:57","modified_gmt":"2010-11-16T10:21:57","slug":"convert-vmap0-datasets-into-shapefiles","status":"publish","type":"post","link":"https:\/\/sickel.net\/blogg\/?p=706","title":{"rendered":"Convert vmap0 layers into shapefiles"},"content":{"rendered":"<p>The vmap0 dataset is a slightly dated, but anyhow often usable dataset of maps of all of the world in scale 1:1&nbsp;000&nbsp;000. It can be downloaded at e.g. <a href=http:\/\/www.mapability.com\/info\/vmap0_index.html>mapability.com<\/a>. 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:<\/p>\n<pre>\r\nogrinfo -ro -summary gltp:\/vrf\/osgeo4w\/share\/maps\/v0eur_5\/vmaplv0\/eurnasia\r\n<\/pre>\n<p>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<\/p>\n<pre>\r\nogr2ogr landicea.shp gltp:\/vrf\/osgeo4w\/share\/maps\/v0eur_5\/vmaplv0\/eurnasia landicea@phys(*)_area landicea \r\n<\/pre>\n<p>To repeat this 60 times is a bit tedious, so let&#8217;s use the information from ogrinfo which makes a line like <\/p>\n<p>33: landicea@phys(*)_area (Polygon)<\/p>\n<p>for each dataset.<\/p>\n<p>running this through the regexp <\/p>\n<p> \/[0-9]*\\: \\(\\(.*\\)@\\(.*\\)(.*\\) (.*)\/ <\/p>\n<p>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 <\/p>\n<pre>\r\nsed 's![0-9]*\\: \\(\\(.*\\)@\\(.*\\)(.*\\) (.*)!ogr2ogr v0\\2\\3.shp gltp:\/vrf\/osgeo4w\/share\/maps\/v0eur_5\/vmaplv0\/eurnasia \\1 \\2!' < vmap0layers \r\n<\/pre>\n<p>will return the ogr2ogr command lines needed to do the conversion to shape files.<\/p>\n<p>So let's put it all together:<\/p>\n<pre>\r\nset uri=gltp:\/vrf\/osgeo4w\/share\/maps\/v0eur_5\/vmaplv0\/eurnasia\r\nogrinfo -ro -summary %uri% > vmap0layers\r\nsed 's![0-9]*\\: \\(\\(.*\\)@\\(.*\\)(.*\\) (.*)!ogr2ogr v0\\2\\3.shp %uri% \\1 \\2!' < vmap0layers  > converts.bat\r\n<\/pre>\n<p>(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;<\/p>\n<pre>\r\nexport uri=gltp:\/vrf\/osgeo4w\/share\/maps\/v0eur_5\/vmaplv0\/eurnasia\r\nogrinfo -ro -summary $uri > vmap0layers\r\nsed 's![0-9]*\\: \\(\\(.*\\)@\\(.*\\)(.*\\) (.*)!ogr2ogr v0\\2\\3.shp  $uri \\1 \\2!' < vmap0layers  > converts.bat\r\n<\/pre>\n<p>Just remember to adjust the uri variable to whereever your maps are stored.<\/p>\n<p>Thanks to <a href=\"http:\/\/www.grymoire.com\/Unix\/Sed.html\">grymoire<\/a> for some reminders on sed and to <a href=\"http:\/\/www.blacksworld.net\/blog\/2006\/11\/25\/importing-vmap0-into-a-useful-format\/\">blacksworld.net<\/a> for explanation to extract the layers one by one.<\/p>\n<p>sed (stream editor) is a standard unix \/ linux utility. It can be installed on windows as a part of the <a href=\"http:\/\/osgeo4w.osgeo.org\/\">osgeo4w suite<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The vmap0 dataset is a slightly dated, but anyhow often usable dataset of maps of all of the world in scale 1:1&nbsp;000&nbsp;000. It can be downloaded at e.g. mapability.com. The problem shows up as soon as one tries to use &hellip; <a href=\"https:\/\/sickel.net\/blogg\/?p=706\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1,20],"tags":[],"class_list":["post-706","post","type-post","status-publish","format-standard","hentry","category-div","category-mapserver"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pnVtD-bo","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=706"}],"version-history":[{"count":11,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/706\/revisions"}],"predecessor-version":[{"id":841,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/706\/revisions\/841"}],"wp:attachment":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}