viewtif 0.1.6__py3-none-any.whl → 0.1.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
viewtif/tif_viewer.py CHANGED
@@ -52,6 +52,33 @@ try:
52
52
  except Exception:
53
53
  HAVE_GEO = False
54
54
 
55
+ def warn_if_large(tif_path, scale=1):
56
+ """Warn and confirm before loading very large rasters (GeoTIFF, GDB, or HDF)."""
57
+ from osgeo import gdal
58
+ import os
59
+
60
+ try:
61
+ gdal.UseExceptions()
62
+ info = gdal.Info(tif_path, format="json")
63
+ width, height = info.get("size", [0, 0])
64
+ total_pixels = (width * height) / (scale ** 2) # account for downsampling
65
+ size_mb = None
66
+ if os.path.exists(tif_path):
67
+ size_mb = os.path.getsize(tif_path) / (1024 ** 2)
68
+
69
+ # Only warn if the *effective* pixels remain large
70
+ if total_pixels > 20_000_000 and scale <= 5:
71
+ print(
72
+ f"[WARN] Large raster detected ({width}×{height}, ~{total_pixels/1e6:.1f}M effective pixels"
73
+ + (f", ~{size_mb:.1f} MB" if size_mb else "")
74
+ + "). Loading may freeze. Consider rerunning with --scale (e.g. --scale 10)."
75
+ )
76
+ ans = input("Proceed anyway? [y/N]: ").strip().lower()
77
+ if ans not in ("y", "yes"):
78
+ print("Cancelled.")
79
+ sys.exit(0)
80
+ except Exception as e:
81
+ print(f"[WARN] Could not pre-check raster size: {e}")
55
82
 
56
83
  # -------------------------- QGraphicsView tweaks -------------------------- #
57
84
  class RasterView(QGraphicsView):
@@ -143,6 +170,8 @@ class TiffViewer(QMainWindow):
143
170
  self.tif_path = self.tif_path or (os.path.commonprefix([red, green, blue]) or red)
144
171
 
145
172
  elif tif_path:
173
+ # --- Universal size check before loading ---
174
+ warn_if_large(tif_path, scale=self._scale_arg)
146
175
  # --------------------- Detect HDF/HDF5 --------------------- #
147
176
  if tif_path.lower().endswith((".hdf", ".h5", ".hdf5")):
148
177
  try:
@@ -222,6 +251,9 @@ class TiffViewer(QMainWindow):
222
251
 
223
252
  # --------------------- Regular GeoTIFF --------------------- #
224
253
  else:
254
+ if os.path.dirname(tif_path).endswith(".gdb"):
255
+ tif_path = f"OpenFileGDB:{os.path.dirname(tif_path)}:{os.path.basename(tif_path)}"
256
+
225
257
  with rasterio.open(tif_path) as src:
226
258
  self._transform = src.transform
227
259
  self._crs = src.crs
@@ -507,7 +539,13 @@ class TiffViewer(QMainWindow):
507
539
  def load_band(self, band_num: int):
508
540
  if self.rgb_mode:
509
541
  return
510
- with rasterio.open(self.tif_path) as src:
542
+
543
+ tif_path = self.tif_path
544
+
545
+ if os.path.dirname(self.tif_path).endswith(".gdb"):
546
+ tif_path = f"OpenFileGDB:{os.path.dirname(self.tif_path)}:{os.path.basename(self.tif_path)}"
547
+
548
+ with rasterio.open(tif_path) as src:
511
549
  self.band = band_num
512
550
  arr = src.read(self.band).astype(np.float32)
513
551
  nd = src.nodata
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: viewtif
3
- Version: 0.1.6
4
- Summary: Simple GeoTIFF viewer with optional shapefile overlay.
3
+ Version: 0.1.8
4
+ Summary: Lightweight GeoTIFF, HDF/HDF5, and Esri File Geodatabase (.gdb) viewer with shapefile overlay and large-raster safeguard.
5
5
  Project-URL: Homepage, https://github.com/nkeikon/tifviewer
6
6
  Project-URL: Source, https://github.com/nkeikon/tifviewer
7
7
  Project-URL: Issues, https://github.com/nkeikon/tifviewer/issues
@@ -70,7 +70,7 @@ viewtif --rgbfiles \
70
70
  viewtif ECOSTRESS_LST.tif \
71
71
  --shapefile Zip_Codes.shp
72
72
  ```
73
- ### Update in v1.0.6
73
+ ### Update in v1.0.6: HDF/HDF5 support
74
74
  `viewtif` can open `.hdf`, `.h5`, and `.hdf5` files that contain multiple subdatasets. When opened, it lists available subdatasets and lets you view one by index. You can also specify a band to display (default is the first band) or change bands interactively with '[' and ']'.
75
75
  ```bash
76
76
  # List subdatasets
@@ -85,6 +85,20 @@ viewtif AG100.v003.33.-107.0001.h5 --subset 1 --band 3
85
85
  > **Note:** Some datasets (perhaps the majority of .hdf files) lack CRS information encoded, so shapefile overlays may not work. In that case, viewtif will display:
86
86
  `[WARN] raster lacks CRS/transform; cannot place overlays.`
87
87
 
88
+ ### Update in v1.0.7: File Geodatabase (.gdb) support
89
+ `viewtif` can now open raster datasets stored inside Esri File Geodatabases (`.gdb`), using the GDAL `OpenFileGDB` driver.
90
+
91
+ ```bash
92
+ # Example
93
+ viewtif "OpenFileGDB:/path/to/geodatabase.gdb:RasterName"
94
+ ```
95
+ > **Note:** Requires GDAL 3.7 or later with the OpenFileGDB driver enabled. The .gdb path and raster name must be separated by a colon (:).
96
+
97
+ ### Update in v1.0.7: Large raster safeguard
98
+ As of v1.0.7, `viewtif` automatically checks the raster size before loading.
99
+ If the dataset is very large (e.g., >20 million pixels), it will pause and warn that loading may freeze your system.
100
+ You can proceed manually or rerun with the `--scale` option for a smaller, faster preview.
101
+
88
102
  ## Controls
89
103
  | Key | Action |
90
104
  | -------------------- | --------------------------------------- |
@@ -120,4 +134,4 @@ This project is released under the MIT License.
120
134
 
121
135
  ## Contributors
122
136
  - [@HarshShinde0](https://github.com/HarshShinde0) — added mouse-wheel and trackpad zoom support
123
-
137
+ - [@p-vdp](https://github.com/p-vdp) — added File Geodatabase (.gdb) raster support
@@ -0,0 +1,5 @@
1
+ viewtif/tif_viewer.py,sha256=DR9yvZMfxQWbhVYGuFdrEvMkaV3glH2yeFTpG4D2WAs,28385
2
+ viewtif-0.1.8.dist-info/METADATA,sha256=_AgokpNDSWK-MbgS2igM4pTYsD_bCfBSajtjrwFkWUo,5942
3
+ viewtif-0.1.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
4
+ viewtif-0.1.8.dist-info/entry_points.txt,sha256=NVEjlRyJ7R7hFPOVsZJio3Hl0VqlX7_oVfA7819XvHM,52
5
+ viewtif-0.1.8.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- viewtif/tif_viewer.py,sha256=30Z4fHz5F630lcM1C5a7AM_qBJNhyqP7tCjx5nBwN9g,26716
2
- viewtif-0.1.6.dist-info/METADATA,sha256=SJwnxmRREta33rWBsLAGfgY6m0DeokLZb7PhTNxiQa8,5037
3
- viewtif-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
4
- viewtif-0.1.6.dist-info/entry_points.txt,sha256=NVEjlRyJ7R7hFPOVsZJio3Hl0VqlX7_oVfA7819XvHM,52
5
- viewtif-0.1.6.dist-info/RECORD,,