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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]