-
Notifications
You must be signed in to change notification settings - Fork 213
Extend MemoryFile and ZipMemoryFile #901
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
Conversation
|
@rbuffat yesterday I finished a refactor of rasterio's MemoryFile after it was reported that its seek method was broken, preventing unordered multipart writes: https://github.com/mapbox/rasterio/pull/1935/files. I'd like to do the same for fiona's MemoryFile. After which, let's try to overlay this PR on top, and then I'll see able copying the directory support to rasterio :) |
ce5cfbe to
b021aca
Compare
7b3e403 to
ac0dd38
Compare
|
@sgillies I will update this PR once you merge these changes. I had a look at MemoryFileBase.exists(). It looks as CPLCheckForFile does more reliably detect the existence of a dataset when a name without extension is used. However, there are still a few issues:
A solution would be to set the appropriate extension in the initializationMemoryFile. However, this is a bit tricky because at this point it is unknown which driver will be used (or even written with write()). |
|
@sgillies I merged the new MemoryFile and tried to extend the test coverage using as many drivers as possible. This revealed some bugs and segfaults I need to look at (see TODOs in tests/test_memoryfile.py). The most common issue is that drivers have problems opening filenames without the proper extension. Also, the OGR_GMT/, GMT seems to add ".gmt" to filenames without a proper extension. The extensions of a driver can be accessed using GDALGetMetadataItem(cogr_driver, DMD_EXTENSION, NULL) if the driver is known. GDALGetMetadataItem should be available for > GDAL 2.0. I would suggest refactoring MemoryFile to use the proper extension for the filenames when possible (= the driver is known). |
|
Thank you! That's super useful. Fiona should certainly respect the GDAL/OGR driver capability API. |
|
FWIW, ZipMemoryFile.listdir() and ZipMemoryFile.listlayers() would be really helpful, I came here to raise an issue but it looks like its already in processes? these methods would be helpful for me :) |
This PR extends the functionality of MemoryFile and ZipMemoryFile:
Not all drivers seem to support MemoryFiles. The tests are extended to use all drivers available on the CI. A mechanism similar to drvsupport.driver_mode_mingdal is introduced to guard not supported drivers and modes.
Issues:
Relevant issues: #830 #754
This PR is probably best suited for Fiona 1.9. I created it against 1.8, as this branch includes a more complete drvsupport list. Once 1.9 catches up it should be possible to change the PR to 1.9.