Skip to content

Add method to close file connection#70

Open
MattArran wants to merge 3 commits intoKipCrossing:mainfrom
MattArran:main
Open

Add method to close file connection#70
MattArran wants to merge 3 commits intoKipCrossing:mainfrom
MattArran:main

Conversation

@MattArran
Copy link
Copy Markdown

@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