Low level GDAL bindings for Rust. The build script will try to auto-detect the installed GDAL version.
Contains:
- mapping of data types
- raster (GDAL) and vector (OGR) operations
- error handling
- spatial reference operations
The build script should work an Linux and Windows systems. It can be configured with a couple of environment variables:
- if
GDAL_INCLUDE_DIR
orGDAL_LIB_DIR
are defined, they will be used. You should also setGDAL_VERSION
toX.Y.Z
- otherwise, if
GDAL_HOME
is defined, the build script looks forGDAL_HOME/include
,GDAL_HOME/lib
andGDAL_HOME/bin
- finally,
pkg-config
is queried to determine theGDAL
location - you can define
GDAL_STATIC
to linkGDAL
statically
The include directories are only used if you choose to generate the bindings at build time.
On Linux, building should work out-of-the-box.
On Windows, the easiest solution is to point the GDAL_HOME
environment variable to the GDAL
folder.
windows-msvc
requiresgdal_i.lib
to be found in%GDAL_HOME%\lib
.windows-gnu
requires eithergdal_i.lib
in%GDAL_HOME%\lib
ORgdal{version}.dll
in%GDAL_HOME%\bin
.
By default, gdal-sys will detect the version of libgdal you have installed and
attempt to use prebuilt bindings corresponding to that version. Alternatively,
you can generate your own bindings from your libgdal installation by specifying
the bindgen
feature.
If a new version of GDAL is released, you (as a gdal
contributor) can
generate new bindings for inclusion in the gdal-sys
source distribution by
building with the bindgen
feature, and then copying the generated file. For
example (the hash will differ in your build):
$ cargo build --features bindgen
$ cp target/debug/build/gdal-sys-db833e3088b78e57/out/bindings.rs gdal-sys/prebuilt-bindings/gdal_3_6.rs
If your're not on a rolling distro, the following command might help:
$ podman run --rm -it -v $PWD:$PWD:z -w $PWD ghcr.io/osgeo/gdal:ubuntu-full-3.9.3 bash -c "curl --proto =https --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable; . ~/.cargo/env && apt update && apt install -y pkg-config gcc libclang-dev && cargo clean && cargo test --features bindgen && shopt -s globstar && mv target/**/bindings.rs gdal-sys/prebuilt-bindings/gdal_3_9.rs"