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

Add method to close file connection #70

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MattArran
Copy link

@MattArran MattArran commented Mar 1, 2024

New method .close() closes any connection opened by e.g. read_box, to the ZarrTiffStore corresponding to the GeoTiff. Fixes #69.

>>> import geotiff
>>> import os
>>> geo_tiff = geotiff.GeoTiff('o41078a7.tif')
>>> geo_tiff.read()[:10,:10]
array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=uint8)
>>> os.remove('o41078a7.tif')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'o41078a7.tif'
>>> geo_tiff.close()
>>> os.remove('o41078a7.tif')
>>>

@MattArran MattArran changed the title Add function to close file connection to fix #69 Add function to close file connection, fixing KipCrossing/geotiff#69 Mar 1, 2024
@MattArran MattArran changed the title Add function to close file connection, fixing KipCrossing/geotiff#69 Add method to close file connection Mar 1, 2024
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

Successfully merging this pull request may close these issues.

File connection opened by read_box is not subsequently closed
1 participant