Skip to content

Commit

Permalink
call .close() on shapefile.Writer objects properly. Don't just rely o…
Browse files Browse the repository at this point in the history
…n del ing them.

Fixes fiftysevendegreesofrad#11

File writer objects were being relied on to close themselves.
In Iron Python relying on del to call .close()
or some other error meant Shapefile headers were
not being written properly - this should happen in the __exit__ of the
context manager but can be called in .close() if preferred.  del is
known to result in wierd behaviour in cPython, and it's certainly no
better in Iron Python, so ought not be relied on to call .close()

The curious number 960051513 that made its way into the shapefile type
in the header, is 39393939 in base 16.  39 happens to be b'9'.hex().  In
shapefile.Writer.__init__ long before the header is constructed
properly (as the length of the file is not yet known) is the following line
of code:
if self.shp: self.shp.write(b'9'*100)
This just reserves the 100 bytes of space required at the start of the file
according to the ESRI shapefile spec.
  • Loading branch information
JamesParrott committed Sep 23, 2022
1 parent 7e6a0d9 commit d82d37e
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions arcscripts/sdna_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ def AddRowGeomItem(self,geomitem):

def Close(self):
self.env.SetProgressorPosition(self.numitems)
self.writer.close()
del self.writer

class SdnaArcpyEnvironment(SdnaEnvironment):
Expand Down

0 comments on commit d82d37e

Please sign in to comment.