You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "Kontinuation (via GitHub)" <gi...@apache.org> on 2026/03/05 08:48:39 UTC

[PR] feat(sedonadb): add Python GDAL configuration API [sedona-db]

Kontinuation opened a new pull request, #689:
URL: https://github.com/apache/sedona-db/pull/689

   ## Summary
   
   - Adds a `configure_gdal()` Python API to the `sedonadb` package that automatically locates and loads GDAL's shared library at import time
   - Supports multiple presets: `auto`, `pyogrio`, `rasterio`, `conda`, `homebrew`, `system` — covering common GDAL installation methods
   - Exposes a `configure_gdal_shared` Rust/pyo3 function that uses `GdalApiBuilder` from `sedona-gdal` to configure the global GDAL API
   
   ## Changed Files
   
   - `python/sedonadb/Cargo.toml` — Added `sedona-gdal` workspace dependency
   - `python/sedonadb/src/lib.rs` — Added `configure_gdal_shared` pyo3 function using `GdalApiBuilder`
   - `python/sedonadb/python/sedonadb/context.py` — Added `configure_gdal()` and helper functions for GDAL library discovery
   - `python/sedonadb/python/sedonadb/__init__.py` — Auto-configure GDAL on import via `configure_gdal(preset="auto")`
   
   ## Dependencies
   
   > **Stacked PR**: This PR depends on #681 (`feat/sedona-gdal-ffi`) and should be merged after it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(python/sedonadb): add Python GDAL configuration API [sedona-db]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #689:
URL: https://github.com/apache/sedona-db/pull/689#discussion_r2888760315


##########
python/sedonadb/python/sedonadb/__init__.py:
##########
@@ -15,16 +15,17 @@
 # specific language governing permissions and limitations
 # under the License.
 from sedonadb import _lib
-from sedonadb.context import connect, configure_proj
+from sedonadb.context import connect, configure_proj, configure_gdal
 
 __version__ = _lib.sedona_python_version()
 
 __features__ = _lib.sedona_python_features()
 
 __all__ = ["connect", "options"]
 
-# Attempt to configure PROJ on import. This will warn if PROJ
-# can't be configured but should never error. The auto-configured
+# Attempt to configure PROJ and GDAL on import. This will warn if PROJ
+# or GDAL can't be configured but should never error. The auto-configured
 # value can be overridden as long as the call to configure_proj()
-# occurs before actually creating a transform.
+# and configure_gdal() occurs before actually creating a transform.

Review Comment:
   The module-level comment says `configure_gdal()` must occur before "actually creating a transform", but GDAL configuration isn’t related to creating PROJ transforms. This looks like a copy/paste from the PROJ note and could mislead users about when GDAL configuration needs to happen.
   
   Recommend updating the wording to reference GDAL-backed operations (e.g., raster/vector IO) rather than transforms.



##########
python/sedonadb/python/sedonadb/context.py:
##########
@@ -604,3 +604,184 @@ def _configure_proj_prefix(prefix: str):
         database_path=Path(prefix) / "share" / "proj" / "proj.db",
         search_path=Path(prefix) / "share" / "proj",
     )
+
+
+def configure_gdal(
+    preset: Optional[
+        Literal["auto", "pyogrio", "rasterio", "conda", "homebrew", "system"]
+    ] = None,
+    *,
+    shared_library: Optional[Union[str, Path]] = None,
+    verbose: bool = False,
+) -> None:
+    """Configure GDAL source
+
+    SedonaDB loads GDAL dynamically at runtime. This is normally configured
+    on package load but may need additional configuration (particularly if the
+    automatic configuration fails).
+
+    This function may be called at any time; however, once a GDAL-backed
+    operation has been performed, subsequent configuration has no effect.
+
+    Args:
+        preset: One of:
+            - None: Use a custom `shared_library` path.
+            - auto: Try all presets in the order pyogrio, rasterio, conda,
+              homebrew, system and warn if none succeeded.
+            - pyogrio: Attempt to use the GDAL shared library bundled with
+              pyogrio. This aligns the GDAL version with the one used by
+              `read_pyogrio()` / `geopandas.read_file()`.
+            - rasterio: Attempt to use the GDAL shared library bundled with
+              rasterio.
+            - conda: Attempt to load libgdal installed via
+              `conda install libgdal`.
+            - homebrew: Attempt to load libgdal installed via
+              `brew install gdal`.
+            - system: Attempt to load libgdal from a directory already on
+              LD_LIBRARY_PATH (Linux), DYLD_LIBRARY_PATH (macOS), or PATH
+              (Windows).
+
+        shared_library: Path to a GDAL shared library.
+        verbose: If True, print information about the configuration process.
+
+    Examples:
+
+        >>> sedona.db.configure_gdal("auto")
+    """
+    if preset is not None:
+        if preset == "pyogrio":
+            _configure_gdal_pyogrio()
+            return
+        elif preset == "rasterio":
+            _configure_gdal_rasterio()
+            return
+        elif preset == "conda":
+            _configure_gdal_conda()
+            return
+        elif preset == "homebrew":
+            prefix = os.environ.get("HOMEBREW_PREFIX", "/opt/homebrew")
+            shared_library = Path(prefix) / "lib" / _gdal_lib_name()
+        elif preset == "system":
+            shared_library = _gdal_lib_name()
+        elif preset == "auto":
+            tried = ["pyogrio", "rasterio", "conda", "homebrew", "system"]

Review Comment:
   In the Windows "system" preset, `shared_library` is set to the bare filename `gdal.dll`, and `ctypes.CDLL` is then called on it. On Windows this can load from the current working directory depending on DLL search order, which is a common DLL hijacking vector—especially since `__init__.py` calls `configure_gdal(preset="auto")` on import.
   
   Consider either (a) removing/skip the `system` preset on win32 from the `auto` preset, (b) requiring an absolute path for user-provided/shared-library presets on win32, or (c) using the safer Windows loading APIs/flags (e.g., `ctypes.CDLL(..., winmode=...)` on Python 3.8+ and/or `os.add_dll_directory`) to avoid searching the CWD.
   ```suggestion
               if sys.platform == "win32":
                   # On Windows, avoid trying the "system" preset from "auto" to
                   # prevent loading a bare DLL name like "gdal.dll" via the
                   # default DLL search path (which may include the CWD).
                   tried = ["pyogrio", "rasterio", "conda", "homebrew"]
               else:
                   tried = ["pyogrio", "rasterio", "conda", "homebrew", "system"]
   ```



##########
python/sedonadb/python/sedonadb/context.py:
##########
@@ -604,3 +604,184 @@ def _configure_proj_prefix(prefix: str):
         database_path=Path(prefix) / "share" / "proj" / "proj.db",
         search_path=Path(prefix) / "share" / "proj",
     )
+
+
+def configure_gdal(
+    preset: Optional[
+        Literal["auto", "pyogrio", "rasterio", "conda", "homebrew", "system"]
+    ] = None,
+    *,
+    shared_library: Optional[Union[str, Path]] = None,
+    verbose: bool = False,
+) -> None:

Review Comment:
   `configure_gdal()` is a new public API and is now invoked during package import (`preset="auto"`). It would be good to add Python tests that validate its behavior without requiring a real GDAL install (e.g., monkeypatch `importlib.import_module`/`ctypes.CDLL` to simulate success/failure and assert it warns rather than raising for the `auto` preset, and that invalid `shared_library` values raise a clear `ValueError`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(python/sedonadb): add Python GDAL configuration API [sedona-db]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on code in PR #689:
URL: https://github.com/apache/sedona-db/pull/689#discussion_r3073561468


##########
python/sedonadb/python/sedonadb/__init__.py:
##########
@@ -15,16 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 from sedonadb import _lib
-from sedonadb.context import connect, configure_proj
+from sedonadb.context import connect, configure_proj, configure_gdal, gdal_version
 
 __version__ = _lib.sedona_python_version()
 
 __features__ = _lib.sedona_python_features()
 
-__all__ = ["connect", "options"]
+__all__ = ["connect", "options", "gdal_version"]

Review Comment:
   The version will pretty much never be accessible from this module (because of the `apache-sedona` wrapper)...probably just as useful to keep it in `context`.



##########
python/sedonadb/python/sedonadb/context.py:
##########
@@ -585,22 +590,234 @@ def _configure_proj_pyproj():
     )
 
 
-def _configure_proj_system():
+def _proj_lib_name() -> str:
     if sys.platform == "win32":
-        configure_proj(shared_library="proj.dll")
+        return "proj.dll"
     elif sys.platform == "darwin":
-        configure_proj(shared_library="libproj.dylib")
+        return "libproj.dylib"
     else:
-        configure_proj(shared_library="libproj.so")
+        return "libproj.so"
+
+
+def _configure_proj_system():
+    configure_proj(shared_library=_proj_lib_name())
 
 
 def _configure_proj_prefix(prefix: str):
     prefix = Path(prefix)
     if not prefix.exists():
         raise ValueError(f"Can't configure PROJ from prefix '{prefix}': does not exist")
 
+    if sys.platform == "win32":
+        shared_library = prefix / "Library" / "bin" / _proj_lib_name()
+    else:
+        shared_library = prefix / "lib" / _proj_lib_name()
+
     configure_proj(
-        shared_library=Path(prefix) / "lib" / "libproj.dylib",
-        database_path=Path(prefix) / "share" / "proj" / "proj.db",
-        search_path=Path(prefix) / "share" / "proj",
+        shared_library=shared_library,
+        database_path=prefix / "share" / "proj" / "proj.db",
+        search_path=prefix / "share" / "proj",
     )
+
+
+def configure_gdal(
+    preset: Optional[
+        Literal["auto", "rasterio", "pyogrio", "conda", "homebrew", "system"]
+    ] = None,
+    *,
+    shared_library: Optional[Union[str, Path]] = None,
+    verbose: bool = False,
+) -> None:
+    """Configure GDAL source
+
+    SedonaDB loads GDAL dynamically at runtime. This is normally configured
+    on package load but may need additional configuration (particularly if the
+    automatic configuration fails).
+
+    This function may be called at any time; however, once a GDAL-backed
+    operation has been performed, subsequent configuration has no effect.
+
+    Args:
+        preset: One of:
+            - None: Use a custom `shared_library` path.
+            - auto: Try all presets in the order pyogrio, rasterio, conda,

Review Comment:
   ```suggestion
               - auto: Try all presets in the order rasterio, pyogrio, conda,
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(python/sedonadb): add Python GDAL configuration API [sedona-db]

Posted by "Kontinuation (via GitHub)" <gi...@apache.org>.
Kontinuation commented on code in PR #689:
URL: https://github.com/apache/sedona-db/pull/689#discussion_r2889025271


##########
python/sedonadb/python/sedonadb/context.py:
##########
@@ -604,3 +604,184 @@ def _configure_proj_prefix(prefix: str):
         database_path=Path(prefix) / "share" / "proj" / "proj.db",
         search_path=Path(prefix) / "share" / "proj",
     )
+
+
+def configure_gdal(
+    preset: Optional[
+        Literal["auto", "pyogrio", "rasterio", "conda", "homebrew", "system"]
+    ] = None,
+    *,
+    shared_library: Optional[Union[str, Path]] = None,
+    verbose: bool = False,
+) -> None:
+    """Configure GDAL source
+
+    SedonaDB loads GDAL dynamically at runtime. This is normally configured
+    on package load but may need additional configuration (particularly if the
+    automatic configuration fails).
+
+    This function may be called at any time; however, once a GDAL-backed
+    operation has been performed, subsequent configuration has no effect.
+
+    Args:
+        preset: One of:
+            - None: Use a custom `shared_library` path.
+            - auto: Try all presets in the order pyogrio, rasterio, conda,
+              homebrew, system and warn if none succeeded.
+            - pyogrio: Attempt to use the GDAL shared library bundled with
+              pyogrio. This aligns the GDAL version with the one used by
+              `read_pyogrio()` / `geopandas.read_file()`.
+            - rasterio: Attempt to use the GDAL shared library bundled with
+              rasterio.
+            - conda: Attempt to load libgdal installed via
+              `conda install libgdal`.
+            - homebrew: Attempt to load libgdal installed via
+              `brew install gdal`.
+            - system: Attempt to load libgdal from a directory already on
+              LD_LIBRARY_PATH (Linux), DYLD_LIBRARY_PATH (macOS), or PATH
+              (Windows).
+
+        shared_library: Path to a GDAL shared library.
+        verbose: If True, print information about the configuration process.
+
+    Examples:
+
+        >>> sedona.db.configure_gdal("auto")
+    """
+    if preset is not None:
+        if preset == "pyogrio":
+            _configure_gdal_pyogrio()
+            return
+        elif preset == "rasterio":
+            _configure_gdal_rasterio()
+            return
+        elif preset == "conda":
+            _configure_gdal_conda()
+            return
+        elif preset == "homebrew":
+            prefix = os.environ.get("HOMEBREW_PREFIX", "/opt/homebrew")
+            shared_library = Path(prefix) / "lib" / _gdal_lib_name()
+        elif preset == "system":
+            shared_library = _gdal_lib_name()
+        elif preset == "auto":
+            tried = ["pyogrio", "rasterio", "conda", "homebrew", "system"]

Review Comment:
   Not a real concern for us: Python 3.8+ changed `ctypes.CDLL` to no longer search CWD by default on Windows, and Python < 3.8 is EOL. More importantly, `configure_proj` uses the exact same pattern (`_configure_proj_system()` passes bare `"proj.dll"` on Windows), and `system` is the last fallback in `auto` — it only runs if pyogrio, rasterio, conda, and homebrew all failed. No change needed; if we ever want to harden this, we should do it for both PROJ and GDAL together.



##########
python/sedonadb/python/sedonadb/__init__.py:
##########
@@ -15,16 +15,17 @@
 # specific language governing permissions and limitations
 # under the License.
 from sedonadb import _lib
-from sedonadb.context import connect, configure_proj
+from sedonadb.context import connect, configure_proj, configure_gdal
 
 __version__ = _lib.sedona_python_version()
 
 __features__ = _lib.sedona_python_features()
 
 __all__ = ["connect", "options"]
 
-# Attempt to configure PROJ on import. This will warn if PROJ
-# can't be configured but should never error. The auto-configured
+# Attempt to configure PROJ and GDAL on import. This will warn if PROJ
+# or GDAL can't be configured but should never error. The auto-configured
 # value can be overridden as long as the call to configure_proj()
-# occurs before actually creating a transform.
+# and configure_gdal() occurs before actually creating a transform.

Review Comment:
   Good catch — fixed in bef2d663. The comment now correctly distinguishes between PROJ transforms and GDAL-backed operations.



##########
python/sedonadb/python/sedonadb/context.py:
##########
@@ -604,3 +604,184 @@ def _configure_proj_prefix(prefix: str):
         database_path=Path(prefix) / "share" / "proj" / "proj.db",
         search_path=Path(prefix) / "share" / "proj",
     )
+
+
+def configure_gdal(
+    preset: Optional[
+        Literal["auto", "pyogrio", "rasterio", "conda", "homebrew", "system"]
+    ] = None,
+    *,
+    shared_library: Optional[Union[str, Path]] = None,
+    verbose: bool = False,
+) -> None:

Review Comment:
   `configure_proj()` has the same structure and also has no dedicated Python-level unit tests — it is tested implicitly through integration tests. Adding monkeypatched tests for GDAL without equivalent tests for PROJ would be inconsistent. This could be a follow-up for both APIs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(python/sedonadb): add Python GDAL configuration API [sedona-db]

Posted by "Kontinuation (via GitHub)" <gi...@apache.org>.
Kontinuation commented on PR #689:
URL: https://github.com/apache/sedona-db/pull/689#issuecomment-4009885662

   I asked a coding agent to work on multi-platform CIs, and it pinpointed the problem loading C++ symbol on Windows, but didn't come up with a correct fix. I have worked on a proper fix manually and now it should be fine.
   
   The mangled name of MEMDataset::Create works for GDAL>=3.5, I have downloaded every pyogrio versions from 0.5.0 to 0.12.1 to verify that. Apparently a better solution is to add MEMCreate to the upstream GDAL C API.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(python/sedonadb): add Python GDAL configuration API [sedona-db]

Posted by "Kontinuation (via GitHub)" <gi...@apache.org>.
Kontinuation merged PR #689:
URL: https://github.com/apache/sedona-db/pull/689


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(python/sedonadb): add Python GDAL configuration API [sedona-db]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on PR #689:
URL: https://github.com/apache/sedona-db/pull/689#issuecomment-4007687998

   Just a note that I have a local windows machine that I found quite helpful when writing the PROJ loader and I'm happy to debug something here if you're running into an issue.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(python/sedonadb): add Python GDAL configuration API [sedona-db]

Posted by "Kontinuation (via GitHub)" <gi...@apache.org>.
Kontinuation commented on code in PR #689:
URL: https://github.com/apache/sedona-db/pull/689#discussion_r3087198239


##########
python/sedonadb/python/sedonadb/__init__.py:
##########
@@ -15,16 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 from sedonadb import _lib
-from sedonadb.context import connect, configure_proj
+from sedonadb.context import connect, configure_proj, configure_gdal, gdal_version
 
 __version__ = _lib.sedona_python_version()
 
 __features__ = _lib.sedona_python_features()
 
-__all__ = ["connect", "options"]
+__all__ = ["connect", "options", "gdal_version"]

Review Comment:
   Removed `gdal_version` in https://github.com/apache/sedona-db/pull/689/changes/73956bde818c4026f2cbcb7865c270204fc2d0e2



##########
python/sedonadb/python/sedonadb/context.py:
##########
@@ -585,22 +590,234 @@ def _configure_proj_pyproj():
     )
 
 
-def _configure_proj_system():
+def _proj_lib_name() -> str:
     if sys.platform == "win32":
-        configure_proj(shared_library="proj.dll")
+        return "proj.dll"
     elif sys.platform == "darwin":
-        configure_proj(shared_library="libproj.dylib")
+        return "libproj.dylib"
     else:
-        configure_proj(shared_library="libproj.so")
+        return "libproj.so"
+
+
+def _configure_proj_system():
+    configure_proj(shared_library=_proj_lib_name())
 
 
 def _configure_proj_prefix(prefix: str):
     prefix = Path(prefix)
     if not prefix.exists():
         raise ValueError(f"Can't configure PROJ from prefix '{prefix}': does not exist")
 
+    if sys.platform == "win32":
+        shared_library = prefix / "Library" / "bin" / _proj_lib_name()
+    else:
+        shared_library = prefix / "lib" / _proj_lib_name()
+
     configure_proj(
-        shared_library=Path(prefix) / "lib" / "libproj.dylib",
-        database_path=Path(prefix) / "share" / "proj" / "proj.db",
-        search_path=Path(prefix) / "share" / "proj",
+        shared_library=shared_library,
+        database_path=prefix / "share" / "proj" / "proj.db",
+        search_path=prefix / "share" / "proj",
     )
+
+
+def configure_gdal(
+    preset: Optional[
+        Literal["auto", "rasterio", "pyogrio", "conda", "homebrew", "system"]
+    ] = None,
+    *,
+    shared_library: Optional[Union[str, Path]] = None,
+    verbose: bool = False,
+) -> None:
+    """Configure GDAL source
+
+    SedonaDB loads GDAL dynamically at runtime. This is normally configured
+    on package load but may need additional configuration (particularly if the
+    automatic configuration fails).
+
+    This function may be called at any time; however, once a GDAL-backed
+    operation has been performed, subsequent configuration has no effect.
+
+    Args:
+        preset: One of:
+            - None: Use a custom `shared_library` path.
+            - auto: Try all presets in the order pyogrio, rasterio, conda,

Review Comment:
   Fixed in https://github.com/apache/sedona-db/pull/689/changes/73956bde818c4026f2cbcb7865c270204fc2d0e2



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org