{"id":354,"date":"2009-01-05T00:47:40","date_gmt":"2009-01-05T05:47:40","guid":{"rendered":"http:\/\/crschmidt.net\/blog\/?p=354"},"modified":"2009-01-05T00:47:40","modified_gmt":"2009-01-05T05:47:40","slug":"polyshp2osm","status":"publish","type":"post","link":"https:\/\/crschmidt.net\/blog\/archives\/354\/polyshp2osm\/","title":{"rendered":"polyshp2osm"},"content":{"rendered":"<p>For ages, people have been asking me to help them with shapefile to OSM conversion, because I wrote one of the scripts that got used a lot for different conversion projects. Since I get a fair amount of email on this, I figured it was worth blogging that I&#8217;ve actually put together a newer script from scratch that does something similar, though for Polygons instead of lines.<\/p>\n<p>One of the benefits of this script is that it was written ahead of time with the intention of sharing it &#8212; which was never meant for the other script that I wrote. This means that it is slightly more readable; at least, the unreadable parts are better separated. (I will admit that there are several aspects of it that are terribly un-Pythonic.)<\/p>\n<p>You can find the code in OSM&#8217;s <a href=\"http:\/\/svn.openstreetmap.org\/applications\/utils\/import\/shp2osm\/\">shp2osm<\/a> directory. <\/p>\n<p>Some aspects of this code:  <\/p>\n<ul>\n<li>It is designed to help you create .osm files you can read\/merge in JOSM, so it has the ability to do vertical striping across a dataset in order to create geographically ordered smaller datasets.<\/li>\n<li> It has an option to limit the number of objects per .osm file; this defaults to 50,000, which in some cases was about JOSM&#8217;s limit. (In others, it seemed lower; it&#8217;s adjustable via a command line switch.)<\/li>\n<li>Uses optparse, which means &#8211;help does help you (once you read the initial docstring and get yourself started.)<\/li>\n<li>Supports both direct tag mappings (shapefile-attr -> OSM-attr) as well as custom functions to add more tags based on multiple attributes of a feature. It was built for the <a href=\"http:\/\/wiki.openstreetmap.org\/wiki\/MassGis_Layer_Openspace\">MassGis OpenSpace Layer<\/a> upload (which is now in progress), so it needed more advanced tagging possibilities.<\/li>\n<li> Supports saving the original shapefile data &#8216;automatically&#8217;, to create the possibility of recreating the original shapefile attribtes. These attributes are namespaced so as to minimize collisions.<\/li>\n<\/ul>\n<p>The script was also used to convert the MassGIS buildings layer, which means that there are now <a href=\"http:\/\/openstreetmap.org\/?lat=42.38971&#038;lon=-71.10772&#038;zoom=17&#038;layers=0B00FTF\">building outlines<\/a> for metro Boston slowly appearing on the map.<\/p>\n<p>If you have polygon data, this tool may be helpful to you. If you don&#8217;t have polygon data, this tool also may be helpful to you, as a better demonstration of how to map shapefiles into OSM data without writing all the code yourself.<\/p>\n<p>I&#8217;m not likely to be doing a lot of support for this, but I wanted to let people know, because I personally think the code is much much more readable than the last shapefile conversion tool I wrote. (Also, it&#8217;s not every day I get to collaborate on OSM with Tim Berners-Lee.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For ages, people have been asking me to help them with shapefile to OSM conversion, because I wrote one of the scripts that got used a lot for different conversion projects. Since I get a fair amount of email on this, I figured it was worth blogging that I&#8217;ve actually put together a newer script [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44],"tags":[126],"class_list":["post-354","post","type-post","status-publish","format-standard","hentry","category-locality-and-space","tag-openstreetmap"],"_links":{"self":[{"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/posts\/354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/comments?post=354"}],"version-history":[{"count":0,"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/posts\/354\/revisions"}],"wp:attachment":[{"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/media?parent=354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/categories?post=354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crschmidt.net\/blog\/wp-json\/wp\/v2\/tags?post=354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}