Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For info only (unsupported use case). Shapefile type 960051513 produced when sDNA is run with Iron Python. #11

Closed
JamesParrott opened this issue Jun 9, 2022 · 1 comment

Comments

@JamesParrott
Copy link
Contributor

This is not a request for a fix. I'm just raising this issue in case it assists anyone else who has (also accidentally) tried to run sDNA using Iron Python (and maybe to provide some useful test code and an example shapefile to sdna_open).

Description: On the example shapefile attached (15x15randomGrid), sDNA Integral produces a shapefile that can be read, e.g. with QGIS, but QGIS fails to open the shapefile output from sDNA run with Iron Python. On closer inspection with PyShp 2.2, the Iron Python shapefile is of shapefile type 960051513 but the cPython one is correctly of type 13 (13 is the code for POLYLINEZ in the shapefile spec)

Instructions to reproduce:
Install Iron Python 2.7 and Python 2.7
Run test_sDNA_iron_v_cPython.py (you may need to check the directories in pythons_dict to the Python interpreters and sDNA are correct for your machine)
test_sDNA.zip

The test script starts new external Python interpreter instances to run sDNA on the same shapefile in each specified Python version. Paths to the python executables to be tested should be added to pythons_dict. As hoped, the results are the same when the test script is run in any Python version (Iron Python and Python 3 have been tested and both show the same shapefile type when the output is inspected using PyShp), so reading using PyShp may not be the issue.

JamesParrott added a commit to JamesParrott/sdna_open that referenced this issue Sep 23, 2022
…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.
@JamesParrott
Copy link
Contributor Author

Fixed by d82d37e of #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant