tarsh / pyshp

Automatically exported from code.google.com/p/pyshp
MIT License
0 stars 0 forks source link

Deleting all shapes #24

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
try to save an empty shape

w = shapefile.Writer(shapefile.POLYGON)
w.field('ID','N','16')
w.field('Name','C','40')
w.save('polygon.shp')

What is the expected output? What do you see instead?
get an empty shapefile
get an error because pyshp is trying to calculate the bbox of nothing

File "shapefile.py", line 529, in __bbox
    return [min(x), min(y), max(x), max(y)]
ValueError: min() arg is an empty sequence

What version of the product are you using? On what operating system?
Windows Vista SP2
Python 2.6.5
Pyshp 1.1.4

Original issue reported on code.google.com by frank.th...@gmail.com on 7 Dec 2011 at 3:32

GoogleCodeExporter commented 9 years ago
Sorry Title should be: Saving empty file

Original comment by frank.th...@gmail.com on 7 Dec 2011 at 4:25

GoogleCodeExporter commented 9 years ago

Original comment by geospati...@gmail.com on 7 Dec 2011 at 6:28

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. It lead me in the right direction to finding what 
was going wrong.

Have discovered that at this time, as a workaround, you can check the number of 
shapes in the instance and then decide whether or not to save.

if len(w._shapes) > 0:
   w.save('polygon.shp')
else:
   #Don't save
   None;

Original comment by fusionst...@gmail.com on 15 Aug 2014 at 2:36