zhikrullah / pyshp

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

Cannot create shapefile with no field data #59

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Two related issues.  The following code

import shapefile
writer = shapefile.Writer(shapefile.POLYLINE)
writer.line([[(0,0),(1,1)]])
#writer.record()
writer.save("out.shp")

Produces a shapefile that cannot be opened by ArcMAP.

If keen on writing a shape-only file, with no field data, 
you might think it sensible to uncomment the writer.record line.  This results 
in a different error during python runtime:

Traceback (most recent call last):
  File "D:\sdnacrip\arcscripts\nodatafail.py", line 4, in <module>
    writer.record()
  File "D:\sdnacrip\arcscripts\shapefile.py", line 957, in record
    if self.fields[0][0].startswith("Deletion"): fieldCount -= 1
IndexError: list index out of range

So how are we to handle this case?

Shapefile 1.20, Python 2.7.2, Windows 7 x64.

Original issue reported on code.google.com by crispin....@gmail.com on 19 Nov 2013 at 5:10

GoogleCodeExporter commented 8 years ago
Unfortunately dbf files associated with shapefiles must have at least one 
field.  ArcMap and to my knowledge all other GIS software won't read such a 
file.

Original comment by jlawh...@geospatialpython.com on 20 Nov 2013 at 3:33