<div dir="ltr"><div dir="ltr">Another error I got with another file, africa-latest.osm.pbf is as follows.</div><div dir="ltr"><br><div><span style="background-color:rgb(217,234,211)"><font color="#0000ff">Traceback (most recent call last):</font></span></div><div><span style="background-color:rgb(217,234,211)"><font color="#0000ff">  File "D:\test.py", line 42, in <module></font></span></div><div><span style="background-color:rgb(217,234,211)"><font color="#0000ff">    ShapeConverter().apply_file(fi, locations=True)</font></span></div><div><span style="background-color:rgb(217,234,211)"><font color="#0000ff">  File " D:\test.py", line 41, in way</font></span></div><div><span style="background-color:rgb(217,234,211)"><font color="#0000ff">    outfile.write(rec)</font></span></div><div><span style="background-color:rgb(217,234,211)"><font color="#0000ff">  File "C:\Python27\lib\site-packages\fiona\collection.py", line 341, in write</font></span></div><div><span style="background-color:rgb(217,234,211)"><font color="#0000ff">    self.writerecords([record])</font></span></div><div><span style="background-color:rgb(217,234,211)"><font color="#0000ff">  File "C:\Python27\lib\site-packages\fiona\collection.py", line 335, in writerecords</font></span></div><div><span style="background-color:rgb(217,234,211)"><font color="#0000ff">    self.session.writerecs(records, self)</font></span></div><div><span style="background-color:rgb(217,234,211)"><font color="#0000ff">  File "fiona\ogrext.pyx", line 1074, in fiona.ogrext.WritingSession.writerecs</font></span></div><div><span style="background-color:rgb(217,234,211)"><font color="#0000ff">RuntimeError: Failed to write record: {'geometry': {'type': 'LineString', 'coordinates': [[-15.6476295, 11.8897502], [-15.6475324, 11.889773], [-15.647507, 11.8896699], [-15.6476042, 11.8896471], [-15.6476295, 11.8897502]]}, 'properties': {'kind': 'yes', 'id': 130159705.0, 'name': None}}</font></span></div><br>please help me guys.</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Nov 1, 2018 at 12:13 PM koji higuchi <<a href="mailto:koji51guchi@gmail.com">koji51guchi@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div><span style="background-color:rgb(255,255,255)"><b><font color="#0000ff">I tried to extract data from </font><span style="color:rgb(0,0,255)">.osm.pbf file and write to shapefile as follows:</span></b></span></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"><br></font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">import os, osmium, fiona</font></div><div><span style="background-color:rgb(217,234,211);color:rgb(0,0,255)"><br></span></div><div><span style="background-color:rgb(217,234,211);color:rgb(0,0,255)">fi = 'europe-latest.osm.pbf'</span><br></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">fo = 'europe-latest.shp' </font><span style="background-color:rgb(217,234,211);color:rgb(0,0,255)">   </span></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"><br></font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">drv = 'ESRI Shapefile'</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"><br></font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">crs = {'no_defs': True, 'ellps': 'WGS84', 'datum': 'WGS84', 'proj': 'longlat'}</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"><br></font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"> schema = {'geometry': 'LineString',</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">                   'properties': {'id': 'float', 'name' : 'str', 'kind' : 'str'}}</font><span style="background-color:rgb(217,234,211);color:rgb(0,0,255)">    </span></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"> </font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">outfile = fiona.open(fo, 'w', driver=drv, crs=crs, schema=schema)</font><span style="background-color:rgb(217,234,211);color:rgb(0,0,255)">    </span></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"> </font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">geomfab = osmium.geom.GeoJSONFactory()</font><span style="background-color:rgb(217,234,211);color:rgb(0,0,255)">    </span></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"> </font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">class ShapeConverter(osmium.SimpleHandler):</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">      def way(self, w):</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">           if 'place' in w.tags: </font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">               rec = {'geometry' : eval(geomfab.create_linestring(w)),</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">                      'properties' : {'id' : float(<a href="http://w.id" target="_blank">w.id</a>),</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">                                     'name' : w.tags.get('name'),</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">                                       'kind' : w.tags['place']}}   </font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">               outfile.write(rec)</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"> </font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">ShapeConverter().apply_file(fi, locations=True)</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"><br></font></div><div><font color="#0000ff" style="background-color:rgb(255,255,255)">I got the following error after extracting several contents:</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"><br></font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)"> rec = {'geometry' : eval(geomfab.create_linestring(w)),</font></div><div><font color="#0000ff" style="background-color:rgb(217,234,211)">RuntimeError: need at least two points for linestring (way_id=619453148)</font></div><div><font color="#0000ff" style="background-color:rgb(255,255,255)"><br></font></div><div><font color="#0000ff" style="background-color:rgb(255,255,255)">How could I skip that erroneous id and extract data for other working ids?</font></div><div><font color="#0000ff" style="background-color:rgb(255,255,255)"><br></font></div><div><font color="#0000ff" style="background-color:rgb(255,255,255)">Your help is appreciated.</font></div><div><font color="#0000ff" style="background-color:rgb(255,255,255)">Thank you so much.</font></div><div><font color="#0000ff" style="background-color:rgb(255,255,255)"><br></font></div><div><font color="#0000ff" style="background-color:rgb(255,255,255)">Koji</font></div></div></div>
</blockquote></div>