geoai-py 0.4.0__py2.py3-none-any.whl → 0.4.1__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.1"
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 *
geoai/utils.py CHANGED
@@ -32,13 +32,6 @@ from shapely.geometry import MultiPolygon, Polygon, box, mapping, shape
32
32
  from torchvision.transforms import RandomRotation
33
33
  from tqdm import tqdm
34
34
 
35
- try:
36
- from torchgeo.datasets import RasterDataset, unbind_samples
37
- except ImportError as e:
38
- raise ImportError(
39
- "Your torchgeo version is too old. Please upgrade to the latest version using 'pip install -U torchgeo'."
40
- )
41
-
42
35
 
43
36
  def view_raster(
44
37
  source: str,
@@ -53,7 +46,7 @@ def view_raster(
53
46
  zoom_to_layer: Optional[bool] = True,
54
47
  visible: Optional[bool] = True,
55
48
  opacity: Optional[float] = 1.0,
56
- array_args: Optional[Dict] = {},
49
+ array_args: Optional[Dict] = None,
57
50
  client_args: Optional[Dict] = {"cors_all": False},
58
51
  basemap: Optional[str] = "OpenStreetMap",
59
52
  basemap_args: Optional[Dict] = None,
@@ -94,6 +87,9 @@ def view_raster(
94
87
  if basemap_args is None:
95
88
  basemap_args = {}
96
89
 
90
+ if array_args is None:
91
+ array_args = {}
92
+
97
93
  m = leafmap.Map()
98
94
 
99
95
  if isinstance(basemap, str):
@@ -277,6 +273,14 @@ def plot_batch(
277
273
  Returns:
278
274
  None
279
275
  """
276
+
277
+ try:
278
+ from torchgeo.datasets import unbind_samples
279
+ except ImportError as e:
280
+ raise ImportError(
281
+ "Your torchgeo version is too old. Please upgrade to the latest version using 'pip install -U torchgeo'."
282
+ )
283
+
280
284
  # Get the samples and the number of items in the batch
281
285
  samples = unbind_samples(batch.copy())
282
286
 
@@ -316,9 +320,7 @@ def plot_batch(
316
320
  )
317
321
 
318
322
 
319
- def calc_stats(
320
- dataset: RasterDataset, divide_by: float = 1.0
321
- ) -> Tuple[np.ndarray, np.ndarray]:
323
+ def calc_stats(dataset, divide_by: float = 1.0) -> Tuple[np.ndarray, np.ndarray]:
322
324
  """
323
325
  Calculate the statistics (mean and std) for the entire dataset.
324
326
 
@@ -5667,11 +5669,14 @@ def orthogonalize(
5667
5669
  crs = src.crs
5668
5670
 
5669
5671
  # Extract shapes from the raster mask
5670
- shapes = features.shapes(mask, transform=transform)
5672
+ shapes = list(features.shapes(mask, transform=transform))
5673
+
5674
+ # Initialize progress bar
5675
+ print(f"Processing {len(shapes)} features...")
5671
5676
 
5672
5677
  # Convert shapes to GeoJSON features
5673
5678
  features_list = []
5674
- for shape, value in shapes:
5679
+ for shape, value in tqdm(shapes, desc="Converting features", unit="shape"):
5675
5680
  if value > 0: # Only process non-zero values (actual objects)
5676
5681
  # Convert GeoJSON geometry to Shapely polygon
5677
5682
  polygon = Polygon(shape["coordinates"][0])
@@ -5811,6 +5816,8 @@ def orthogonalize(
5811
5816
 
5812
5817
  # Save to file if output_path is provided
5813
5818
  if output_path:
5819
+ print(f"Saving to {output_path}...")
5814
5820
  gdf.to_file(output_path)
5821
+ print("Done!")
5815
5822
 
5816
5823
  return gdf
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: geoai-py
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: A Python package for using Artificial Intelligence (AI) with geospatial data
5
5
  Author-email: Qiusheng Wu <giswqs@gmail.com>
6
6
  License: MIT License
@@ -36,13 +36,8 @@ Requires-Dist: torch
36
36
  Requires-Dist: torchgeo
37
37
  Requires-Dist: tqdm
38
38
  Requires-Dist: transformers
39
- Provides-Extra: download
40
- Requires-Dist: pystac_client; extra == "download"
41
- Requires-Dist: planetary_computer; extra == "download"
42
- Requires-Dist: tqdm; extra == "download"
43
- Requires-Dist: overturemaps; extra == "download"
44
- Provides-Extra: all
45
- Requires-Dist: geoai[download]; extra == "all"
39
+ Provides-Extra: extra
40
+ Requires-Dist: overturemaps; extra == "extra"
46
41
 
47
42
  # GeoAI: Artificial Intelligence for Geospatial Data
48
43
 
@@ -1,4 +1,4 @@
1
- geoai/__init__.py,sha256=rtBuAkA1JMtY_o_PE3kdaFftrp5K9YBQxdi5y99ktPU,923
1
+ geoai/__init__.py,sha256=lZ5LYzlwjX-TuvVtvuk0TC0le80P83lfUUOXBY0MPoU,3592
2
2
  geoai/download.py,sha256=eqMecJqvqyrIVFViNA7pW8a5EIhqYJzRILmxQoFHG2k,13095
3
3
  geoai/extract.py,sha256=CCXjUcGC4ZOKOKKjvElp8VFmTz46b0ATvGitbOPgTwE,95506
4
4
  geoai/geoai.py,sha256=L1jkozDcjqJXvqT6i8oW04Ix9x4cc2-LNYi9_564ABQ,163
@@ -6,10 +6,10 @@ geoai/hf.py,sha256=mLKGxEAS5eHkxZLwuLpYc1o7e3-7QIXdBv-QUY-RkFk,17072
6
6
  geoai/segment.py,sha256=g3YW17ftr--CKq6VB32TJEPY8owGQ7uQ0sg_tUT2ooE,13681
7
7
  geoai/segmentation.py,sha256=AtPzCvguHAEeuyXafa4bzMFATvltEYcah1B8ZMfkM_s,11373
8
8
  geoai/train.py,sha256=VaeFzIkVUNTdre8ImgUNhmbpA42qijSXaajLpmBF_Ic,36248
9
- geoai/utils.py,sha256=Q5f-mFVjer7BKipt4GOI9QFvTRsdB8V48LpkqlfBg2o,223437
10
- geoai_py-0.4.0.dist-info/LICENSE,sha256=vN2L5U7cZ6ZkOHFmc8WiGlsogWsZc5dllMeNxnKVOZg,1070
11
- geoai_py-0.4.0.dist-info/METADATA,sha256=xRCruLClbNxRuXn3A-729IWqiyO-B08VFbpMvrN-ErI,6297
12
- geoai_py-0.4.0.dist-info/WHEEL,sha256=SrDKpSbFN1G94qcmBqS9nyHcDMp9cUS9OC06hC0G3G0,109
13
- geoai_py-0.4.0.dist-info/entry_points.txt,sha256=uGp3Az3HURIsRHP9v-ys0hIbUuBBNUfXv6VbYHIXeg4,41
14
- geoai_py-0.4.0.dist-info/top_level.txt,sha256=1YkCUWu-ii-0qIex7kbwAvfei-gos9ycyDyUCJPNWHY,6
15
- geoai_py-0.4.0.dist-info/RECORD,,
9
+ geoai/utils.py,sha256=oBNhk73_Owv-pmaRyBKkq0HinnqnMgP3U5CUAQx6ln0,223700
10
+ geoai_py-0.4.1.dist-info/LICENSE,sha256=vN2L5U7cZ6ZkOHFmc8WiGlsogWsZc5dllMeNxnKVOZg,1070
11
+ geoai_py-0.4.1.dist-info/METADATA,sha256=0JZwrVh1EtR3mJIu8cumnafbCnElW70iBa77hSDwXHk,6078
12
+ geoai_py-0.4.1.dist-info/WHEEL,sha256=SrDKpSbFN1G94qcmBqS9nyHcDMp9cUS9OC06hC0G3G0,109
13
+ geoai_py-0.4.1.dist-info/entry_points.txt,sha256=uGp3Az3HURIsRHP9v-ys0hIbUuBBNUfXv6VbYHIXeg4,41
14
+ geoai_py-0.4.1.dist-info/top_level.txt,sha256=1YkCUWu-ii-0qIex7kbwAvfei-gos9ycyDyUCJPNWHY,6
15
+ geoai_py-0.4.1.dist-info/RECORD,,