Skip to content

Commit e8b48fc

Browse files
committed
Added checks for necessary python libraries
1 parent 6eafbd1 commit e8b48fc

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

scripts/geotiff2scad.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,29 @@
2424
# Some planetary datasets use planetocentric or planetographic projections — still usable for 2D mapping.
2525

2626

27+
import sys
28+
29+
def require_module(name, alias=None, install_hint=None):
30+
try:
31+
module = __import__(name)
32+
if alias:
33+
globals()[alias] = module
34+
else:
35+
globals()[name] = module
36+
except ImportError:
37+
print(f"Error: This script requires the '{name}' package.")
38+
if install_hint:
39+
print(f"Install it using: {install_hint}")
40+
else:
41+
print(f"Try: pip install {name}")
42+
sys.exit(1)
43+
44+
# Require necessary modules
45+
require_module('rasterio', install_hint='pip install rasterio')
46+
require_module('numpy', alias='np', install_hint='pip install numpy')
47+
48+
# Standard, should always be available:
2749
import argparse
28-
import numpy as np
29-
import rasterio
30-
from rasterio.enums import Resampling
3150
import json
3251

3352
# ----------------------------

0 commit comments

Comments
 (0)