geoai-py 0.4.0__py2.py3-none-any.whl → 0.4.2__py2.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.
geoai/__init__.py CHANGED
@@ -2,34 +2,96 @@
2
2
 
3
3
  __author__ = """Qiusheng Wu"""
4
4
  __email__ = "giswqs@gmail.com"
5
- __version__ = "0.4.0"
5
+ __version__ = "0.4.2"
6
6
 
7
7
 
8
8
  import os
9
9
  import sys
10
10
 
11
11
 
12
- def set_proj_lib_path():
13
- """Set the PROJ_LIB environment variable based on the current conda environment."""
12
+ def set_proj_lib_path(verbose=False):
13
+ """
14
+ Set the PROJ_LIB and GDAL_DATA environment variables based on the current conda environment.
15
+
16
+ This function attempts to locate and set the correct paths for PROJ_LIB and GDAL_DATA
17
+ by checking multiple possible locations within the conda environment structure.
18
+
19
+ Args:
20
+ verbose (bool): If True, print additional information during the process.
21
+
22
+ Returns:
23
+ bool: True if both paths were set successfully, False otherwise.
24
+ """
14
25
  try:
15
26
  # Get conda environment path
16
27
  conda_env_path = os.environ.get("CONDA_PREFIX") or sys.prefix
17
28
 
29
+ # Define possible paths for PROJ_LIB
30
+ possible_proj_paths = [
31
+ os.path.join(conda_env_path, "share", "proj"),
32
+ os.path.join(conda_env_path, "Library", "share", "proj"),
33
+ os.path.join(conda_env_path, "Library", "share"),
34
+ ]
35
+
36
+ # Define possible paths for GDAL_DATA
37
+ possible_gdal_paths = [
38
+ os.path.join(conda_env_path, "share", "gdal"),
39
+ os.path.join(conda_env_path, "Library", "share", "gdal"),
40
+ os.path.join(conda_env_path, "Library", "data", "gdal"),
41
+ os.path.join(conda_env_path, "Library", "share"),
42
+ ]
43
+
18
44
  # Set PROJ_LIB environment variable
19
- proj_path = os.path.join(conda_env_path, "share", "proj")
20
- gdal_path = os.path.join(conda_env_path, "share", "gdal")
21
-
22
- # Check if the directory exists before setting
23
- if os.path.exists(proj_path):
24
- os.environ["PROJ_LIB"] = proj_path
25
- if os.path.exists(gdal_path):
26
- os.environ["GDAL_DATA"] = gdal_path
45
+ proj_set = False
46
+ for proj_path in possible_proj_paths:
47
+ if os.path.exists(proj_path) and os.path.isdir(proj_path):
48
+ # Verify it contains projection data
49
+ if os.path.exists(os.path.join(proj_path, "proj.db")):
50
+ os.environ["PROJ_LIB"] = proj_path
51
+ if verbose:
52
+ print(f"PROJ_LIB set to: {proj_path}")
53
+ proj_set = True
54
+ break
55
+
56
+ # Set GDAL_DATA environment variable
57
+ gdal_set = False
58
+ for gdal_path in possible_gdal_paths:
59
+ if os.path.exists(gdal_path) and os.path.isdir(gdal_path):
60
+ # Verify it contains the header.dxf file or other critical GDAL files
61
+ if os.path.exists(
62
+ os.path.join(gdal_path, "header.dxf")
63
+ ) or os.path.exists(os.path.join(gdal_path, "gcs.csv")):
64
+ os.environ["GDAL_DATA"] = gdal_path
65
+ if verbose:
66
+ print(f"GDAL_DATA set to: {gdal_path}")
67
+ gdal_set = True
68
+ break
69
+
70
+ # If paths still not found, try a last-resort approach
71
+ if not proj_set or not gdal_set:
72
+ # Try a deep search in the conda environment
73
+ for root, dirs, files in os.walk(conda_env_path):
74
+ if not gdal_set and "header.dxf" in files:
75
+ os.environ["GDAL_DATA"] = root
76
+ if verbose:
77
+ print(f"GDAL_DATA set to: {root} (deep search)")
78
+ gdal_set = True
79
+
80
+ if not proj_set and "proj.db" in files:
81
+ os.environ["PROJ_LIB"] = root
82
+ if verbose:
83
+ print(f"PROJ_LIB set to: {root} (deep search)")
84
+ proj_set = True
85
+
86
+ if proj_set and gdal_set:
87
+ break
88
+
27
89
  except Exception as e:
28
- print(e)
90
+ print(f"Error setting projection library paths: {e}")
29
91
  return
30
92
 
31
93
 
32
- if "google.colab" not in sys.modules:
33
- set_proj_lib_path()
94
+ # if ("google.colab" not in sys.modules) and (sys.platform != "windows"):
95
+ # set_proj_lib_path()
34
96
 
35
97
  from .geoai import *