Re: [OSM-dev] RuntimeError: need at least two points for linestring (way_id=619453148)
Hi, On Fri, Nov 02, 2018 at 11:36:49AM +0900, koji higuchi wrote: > Hi Sarah, > It stopped working with the following error, though I used try and > exception: > > Traceback (most recent call last): > File "D:\test.py", line 47, in > ShapeConverter().apply_file(fi, locations=True) > RuntimeError: Read failed: The data is invalid. This means that one of your input files is broken. You need to find out which one and repair it. Sarah > > Please help me. > > On Thu, Nov 1, 2018 at 7:59 PM koji higuchi wrote: > > > Hi Sarah, > > Your answer was great and it helped me to correct my code. > > I think that it's okay to use class and definition. > > Thank you very much for your help. > > > > Best regards > > Koji > > > > > > On Thu, Nov 1, 2018 at 7:07 PM koji higuchi wrote: > > > >> Hi Sarah, > >> Thank you so much for your help! > >> Writing speed for GPKG format with fiona has been very slow. > >> I wanted to extract one by one ids and write geom and tag using > >> ogr/python. > >> Could you help me how to extract geom and tag of each id in a for loop > >> without using class and definitions? > >> > >> On Thu, Nov 1, 2018 at 6:07 PM Sarah Hoffmann wrote: > >> > >>> Hi, > >>> > >>> On Thu, Nov 01, 2018 at 12:13:40PM +0900, koji higuchi wrote: > >>> > *I tried to extract data from .osm.pbf file and write to shapefile as > >>> > follows:* > >>> > > >>> > import os, osmium, fiona > >>> > > >>> > fi = 'europe-latest.osm.pbf' > >>> > fo = 'europe-latest.shp' > >>> > > >>> > drv = 'ESRI Shapefile' > >>> > > >>> > crs = {'no_defs': True, 'ellps': 'WGS84', 'datum': 'WGS84', 'proj': > >>> > 'longlat'} > >>> > > >>> > schema = {'geometry': 'LineString', > >>> >'properties': {'id': 'float', 'name' : 'str', > >>> 'kind' : > >>> > 'str'}} > >>> > > >>> > outfile = fiona.open(fo, 'w', driver=drv, crs=crs, schema=schema) > >>> > > >>> > geomfab = osmium.geom.GeoJSONFactory() > >>> > > >>> > class ShapeConverter(osmium.SimpleHandler): > >>> > def way(self, w): > >>> >if 'place' in w.tags: > >>> >rec = {'geometry' : eval(geomfab.create_linestring(w)), > >>> > 'properties' : {'id' : float(w.id), > >>> > 'name' : w.tags.get('name'), > >>> >'kind' : w.tags['place']}} > >>> >outfile.write(rec) > >>> > > >>> > ShapeConverter().apply_file(fi, locations=True) > >>> > > >>> > I got the following error after extracting several contents: > >>> > > >>> > rec = {'geometry' : eval(geomfab.create_linestring(w)), > >>> > RuntimeError: need at least two points for linestring > >>> (way_id=619453148) > >>> > > >>> > How could I skip that erroneous id and extract data for other working > >>> ids? > >>> > >>> You need to do this manually yourself in the handler. I recommend > >>> simply catching the exception as there are some other error > >>> conditions besides too few points: > >>> > >>> def way(self, w): > >>> if 'place' in w.tags: > >>> try: > >>> geom = geomfab.create_linestring(w) > >>> except: > >>> print("Skipping way with bad geometry") > >>> return > >>> > >>> rec = {'geometry' : eval(geom), > >>>'properties' : {'id' : float(w.id), > >>>'name' : w.tags.get('name'), > >>>'kind' : w.tags['place']}} > >>> outfile.write(rec) > >>> > >>> Kind regards > >>> > >>> Sarah > >>> > >> ___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev
Re: [OSM-dev] RuntimeError: need at least two points for linestring (way_id=619453148)
Here is full code I was working with: https://drive.google.com/open?id=1NclLve4I5C05DqiOAWZQHhuyVk4ilx0g On Fri, Nov 2, 2018 at 11:36 AM koji higuchi wrote: > Hi Sarah, > It stopped working with the following error, though I used try and > exception: > > Traceback (most recent call last): > File "D:\test.py", line 47, in > ShapeConverter().apply_file(fi, locations=True) > RuntimeError: Read failed: The data is invalid. > > Please help me. > > On Thu, Nov 1, 2018 at 7:59 PM koji higuchi wrote: > >> Hi Sarah, >> Your answer was great and it helped me to correct my code. >> I think that it's okay to use class and definition. >> Thank you very much for your help. >> >> Best regards >> Koji >> >> >> On Thu, Nov 1, 2018 at 7:07 PM koji higuchi >> wrote: >> >>> Hi Sarah, >>> Thank you so much for your help! >>> Writing speed for GPKG format with fiona has been very slow. >>> I wanted to extract one by one ids and write geom and tag using >>> ogr/python. >>> Could you help me how to extract geom and tag of each id in a for loop >>> without using class and definitions? >>> >>> On Thu, Nov 1, 2018 at 6:07 PM Sarah Hoffmann wrote: >>> Hi, On Thu, Nov 01, 2018 at 12:13:40PM +0900, koji higuchi wrote: > *I tried to extract data from .osm.pbf file and write to shapefile as > follows:* > > import os, osmium, fiona > > fi = 'europe-latest.osm.pbf' > fo = 'europe-latest.shp' > > drv = 'ESRI Shapefile' > > crs = {'no_defs': True, 'ellps': 'WGS84', 'datum': 'WGS84', 'proj': > 'longlat'} > > schema = {'geometry': 'LineString', >'properties': {'id': 'float', 'name' : 'str', 'kind' : > 'str'}} > > outfile = fiona.open(fo, 'w', driver=drv, crs=crs, schema=schema) > > geomfab = osmium.geom.GeoJSONFactory() > > class ShapeConverter(osmium.SimpleHandler): > def way(self, w): >if 'place' in w.tags: >rec = {'geometry' : eval(geomfab.create_linestring(w)), > 'properties' : {'id' : float(w.id), > 'name' : w.tags.get('name'), >'kind' : w.tags['place']}} >outfile.write(rec) > > ShapeConverter().apply_file(fi, locations=True) > > I got the following error after extracting several contents: > > rec = {'geometry' : eval(geomfab.create_linestring(w)), > RuntimeError: need at least two points for linestring (way_id=619453148) > > How could I skip that erroneous id and extract data for other working ids? You need to do this manually yourself in the handler. I recommend simply catching the exception as there are some other error conditions besides too few points: def way(self, w): if 'place' in w.tags: try: geom = geomfab.create_linestring(w) except: print("Skipping way with bad geometry") return rec = {'geometry' : eval(geom), 'properties' : {'id' : float(w.id), 'name' : w.tags.get('name'), 'kind' : w.tags['place']}} outfile.write(rec) Kind regards Sarah >>> ___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev
Re: [OSM-dev] RuntimeError: need at least two points for linestring (way_id=619453148)
Hi Sarah, It stopped working with the following error, though I used try and exception: Traceback (most recent call last): File "D:\test.py", line 47, in ShapeConverter().apply_file(fi, locations=True) RuntimeError: Read failed: The data is invalid. Please help me. On Thu, Nov 1, 2018 at 7:59 PM koji higuchi wrote: > Hi Sarah, > Your answer was great and it helped me to correct my code. > I think that it's okay to use class and definition. > Thank you very much for your help. > > Best regards > Koji > > > On Thu, Nov 1, 2018 at 7:07 PM koji higuchi wrote: > >> Hi Sarah, >> Thank you so much for your help! >> Writing speed for GPKG format with fiona has been very slow. >> I wanted to extract one by one ids and write geom and tag using >> ogr/python. >> Could you help me how to extract geom and tag of each id in a for loop >> without using class and definitions? >> >> On Thu, Nov 1, 2018 at 6:07 PM Sarah Hoffmann wrote: >> >>> Hi, >>> >>> On Thu, Nov 01, 2018 at 12:13:40PM +0900, koji higuchi wrote: >>> > *I tried to extract data from .osm.pbf file and write to shapefile as >>> > follows:* >>> > >>> > import os, osmium, fiona >>> > >>> > fi = 'europe-latest.osm.pbf' >>> > fo = 'europe-latest.shp' >>> > >>> > drv = 'ESRI Shapefile' >>> > >>> > crs = {'no_defs': True, 'ellps': 'WGS84', 'datum': 'WGS84', 'proj': >>> > 'longlat'} >>> > >>> > schema = {'geometry': 'LineString', >>> >'properties': {'id': 'float', 'name' : 'str', >>> 'kind' : >>> > 'str'}} >>> > >>> > outfile = fiona.open(fo, 'w', driver=drv, crs=crs, schema=schema) >>> > >>> > geomfab = osmium.geom.GeoJSONFactory() >>> > >>> > class ShapeConverter(osmium.SimpleHandler): >>> > def way(self, w): >>> >if 'place' in w.tags: >>> >rec = {'geometry' : eval(geomfab.create_linestring(w)), >>> > 'properties' : {'id' : float(w.id), >>> > 'name' : w.tags.get('name'), >>> >'kind' : w.tags['place']}} >>> >outfile.write(rec) >>> > >>> > ShapeConverter().apply_file(fi, locations=True) >>> > >>> > I got the following error after extracting several contents: >>> > >>> > rec = {'geometry' : eval(geomfab.create_linestring(w)), >>> > RuntimeError: need at least two points for linestring >>> (way_id=619453148) >>> > >>> > How could I skip that erroneous id and extract data for other working >>> ids? >>> >>> You need to do this manually yourself in the handler. I recommend >>> simply catching the exception as there are some other error >>> conditions besides too few points: >>> >>> def way(self, w): >>> if 'place' in w.tags: >>> try: >>> geom = geomfab.create_linestring(w) >>> except: >>> print("Skipping way with bad geometry") >>> return >>> >>> rec = {'geometry' : eval(geom), >>>'properties' : {'id' : float(w.id), >>>'name' : w.tags.get('name'), >>>'kind' : w.tags['place']}} >>> outfile.write(rec) >>> >>> Kind regards >>> >>> Sarah >>> >> ___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev
Re: [OSM-dev] RuntimeError: need at least two points for linestring (way_id=619453148)
Hi Sarah, Your answer was great and it helped me to correct my code. I think that it's okay to use class and definition. Thank you very much for your help. Best regards Koji On Thu, Nov 1, 2018 at 7:07 PM koji higuchi wrote: > Hi Sarah, > Thank you so much for your help! > Writing speed for GPKG format with fiona has been very slow. > I wanted to extract one by one ids and write geom and tag using ogr/python. > Could you help me how to extract geom and tag of each id in a for loop > without using class and definitions? > > On Thu, Nov 1, 2018 at 6:07 PM Sarah Hoffmann wrote: > >> Hi, >> >> On Thu, Nov 01, 2018 at 12:13:40PM +0900, koji higuchi wrote: >> > *I tried to extract data from .osm.pbf file and write to shapefile as >> > follows:* >> > >> > import os, osmium, fiona >> > >> > fi = 'europe-latest.osm.pbf' >> > fo = 'europe-latest.shp' >> > >> > drv = 'ESRI Shapefile' >> > >> > crs = {'no_defs': True, 'ellps': 'WGS84', 'datum': 'WGS84', 'proj': >> > 'longlat'} >> > >> > schema = {'geometry': 'LineString', >> >'properties': {'id': 'float', 'name' : 'str', 'kind' >> : >> > 'str'}} >> > >> > outfile = fiona.open(fo, 'w', driver=drv, crs=crs, schema=schema) >> > >> > geomfab = osmium.geom.GeoJSONFactory() >> > >> > class ShapeConverter(osmium.SimpleHandler): >> > def way(self, w): >> >if 'place' in w.tags: >> >rec = {'geometry' : eval(geomfab.create_linestring(w)), >> > 'properties' : {'id' : float(w.id), >> > 'name' : w.tags.get('name'), >> >'kind' : w.tags['place']}} >> >outfile.write(rec) >> > >> > ShapeConverter().apply_file(fi, locations=True) >> > >> > I got the following error after extracting several contents: >> > >> > rec = {'geometry' : eval(geomfab.create_linestring(w)), >> > RuntimeError: need at least two points for linestring (way_id=619453148) >> > >> > How could I skip that erroneous id and extract data for other working >> ids? >> >> You need to do this manually yourself in the handler. I recommend >> simply catching the exception as there are some other error >> conditions besides too few points: >> >> def way(self, w): >> if 'place' in w.tags: >> try: >> geom = geomfab.create_linestring(w) >> except: >> print("Skipping way with bad geometry") >> return >> >> rec = {'geometry' : eval(geom), >>'properties' : {'id' : float(w.id), >>'name' : w.tags.get('name'), >>'kind' : w.tags['place']}} >> outfile.write(rec) >> >> Kind regards >> >> Sarah >> > ___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev
Re: [OSM-dev] RuntimeError: need at least two points for linestring (way_id=619453148)
Hi Sarah, Thank you so much for your help! Writing speed for GPKG format with fiona has been very slow. I wanted to extract one by one ids and write geom and tag using ogr/python. Could you help me how to extract geom and tag of each id in a for loop without using class and definitions? On Thu, Nov 1, 2018 at 6:07 PM Sarah Hoffmann wrote: > Hi, > > On Thu, Nov 01, 2018 at 12:13:40PM +0900, koji higuchi wrote: > > *I tried to extract data from .osm.pbf file and write to shapefile as > > follows:* > > > > import os, osmium, fiona > > > > fi = 'europe-latest.osm.pbf' > > fo = 'europe-latest.shp' > > > > drv = 'ESRI Shapefile' > > > > crs = {'no_defs': True, 'ellps': 'WGS84', 'datum': 'WGS84', 'proj': > > 'longlat'} > > > > schema = {'geometry': 'LineString', > >'properties': {'id': 'float', 'name' : 'str', 'kind' : > > 'str'}} > > > > outfile = fiona.open(fo, 'w', driver=drv, crs=crs, schema=schema) > > > > geomfab = osmium.geom.GeoJSONFactory() > > > > class ShapeConverter(osmium.SimpleHandler): > > def way(self, w): > >if 'place' in w.tags: > >rec = {'geometry' : eval(geomfab.create_linestring(w)), > > 'properties' : {'id' : float(w.id), > > 'name' : w.tags.get('name'), > >'kind' : w.tags['place']}} > >outfile.write(rec) > > > > ShapeConverter().apply_file(fi, locations=True) > > > > I got the following error after extracting several contents: > > > > rec = {'geometry' : eval(geomfab.create_linestring(w)), > > RuntimeError: need at least two points for linestring (way_id=619453148) > > > > How could I skip that erroneous id and extract data for other working > ids? > > You need to do this manually yourself in the handler. I recommend > simply catching the exception as there are some other error > conditions besides too few points: > > def way(self, w): > if 'place' in w.tags: > try: > geom = geomfab.create_linestring(w) > except: > print("Skipping way with bad geometry") > return > > rec = {'geometry' : eval(geom), >'properties' : {'id' : float(w.id), >'name' : w.tags.get('name'), >'kind' : w.tags['place']}} > outfile.write(rec) > > Kind regards > > Sarah > ___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev
Re: [OSM-dev] RuntimeError: need at least two points for linestring (way_id=619453148)
Hi, On Thu, Nov 01, 2018 at 12:13:40PM +0900, koji higuchi wrote: > *I tried to extract data from .osm.pbf file and write to shapefile as > follows:* > > import os, osmium, fiona > > fi = 'europe-latest.osm.pbf' > fo = 'europe-latest.shp' > > drv = 'ESRI Shapefile' > > crs = {'no_defs': True, 'ellps': 'WGS84', 'datum': 'WGS84', 'proj': > 'longlat'} > > schema = {'geometry': 'LineString', >'properties': {'id': 'float', 'name' : 'str', 'kind' : > 'str'}} > > outfile = fiona.open(fo, 'w', driver=drv, crs=crs, schema=schema) > > geomfab = osmium.geom.GeoJSONFactory() > > class ShapeConverter(osmium.SimpleHandler): > def way(self, w): >if 'place' in w.tags: >rec = {'geometry' : eval(geomfab.create_linestring(w)), > 'properties' : {'id' : float(w.id), > 'name' : w.tags.get('name'), >'kind' : w.tags['place']}} >outfile.write(rec) > > ShapeConverter().apply_file(fi, locations=True) > > I got the following error after extracting several contents: > > rec = {'geometry' : eval(geomfab.create_linestring(w)), > RuntimeError: need at least two points for linestring (way_id=619453148) > > How could I skip that erroneous id and extract data for other working ids? You need to do this manually yourself in the handler. I recommend simply catching the exception as there are some other error conditions besides too few points: def way(self, w): if 'place' in w.tags: try: geom = geomfab.create_linestring(w) except: print("Skipping way with bad geometry") return rec = {'geometry' : eval(geom), 'properties' : {'id' : float(w.id), 'name' : w.tags.get('name'), 'kind' : w.tags['place']}} outfile.write(rec) Kind regards Sarah ___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev
Re: [OSM-dev] RuntimeError: need at least two points for linestring (way_id=619453148)
Another error I got with another file, africa-latest.osm.pbf is as follows. Traceback (most recent call last): File "D:\test.py", line 42, in ShapeConverter().apply_file(fi, locations=True) File " D:\test.py", line 41, in way outfile.write(rec) File "C:\Python27\lib\site-packages\fiona\collection.py", line 341, in write self.writerecords([record]) File "C:\Python27\lib\site-packages\fiona\collection.py", line 335, in writerecords self.session.writerecs(records, self) File "fiona\ogrext.pyx", line 1074, in fiona.ogrext.WritingSession.writerecs 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}} please help me guys. On Thu, Nov 1, 2018 at 12:13 PM koji higuchi wrote: > *I tried to extract data from .osm.pbf file and write to shapefile as > follows:* > > import os, osmium, fiona > > fi = 'europe-latest.osm.pbf' > fo = 'europe-latest.shp' > > drv = 'ESRI Shapefile' > > crs = {'no_defs': True, 'ellps': 'WGS84', 'datum': 'WGS84', 'proj': > 'longlat'} > > schema = {'geometry': 'LineString', >'properties': {'id': 'float', 'name' : 'str', 'kind' : > 'str'}} > > outfile = fiona.open(fo, 'w', driver=drv, crs=crs, schema=schema) > > geomfab = osmium.geom.GeoJSONFactory() > > class ShapeConverter(osmium.SimpleHandler): > def way(self, w): >if 'place' in w.tags: >rec = {'geometry' : eval(geomfab.create_linestring(w)), > 'properties' : {'id' : float(w.id), > 'name' : w.tags.get('name'), >'kind' : w.tags['place']}} >outfile.write(rec) > > ShapeConverter().apply_file(fi, locations=True) > > I got the following error after extracting several contents: > > rec = {'geometry' : eval(geomfab.create_linestring(w)), > RuntimeError: need at least two points for linestring (way_id=619453148) > > How could I skip that erroneous id and extract data for other working ids? > > Your help is appreciated. > Thank you so much. > > Koji > ___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev