I’ve written quite a nice little desktop app to process digital elevation models using Shell commands to GDAL (Geospatial Data Abstraction Libraries). It is essentially a GUI for a subset of GDAL functionality works very well. This is my first experience with shell commands. My questions have as much to do with GDAL as with Xojo:
The first time I access GDAL (on a Mac), it is very slow, sometimes taking 10 seconds or more. Subsequent runs of the same command are much faster. While this is not a dealbreaker, is there anyway to speed things up?
GDAL seems notoriously fiddly about installations with lots of external dependencies that seem to break easily. Setting the path and environment variables is essential but can be imposing to users who have had little or no experience with ther Terminal, Powershell or whatever. On the Mac, I use “which gdalinfo --version” to get the path but I was wondering whether there was any way for my app to set the path and environment variables automatically for the user?
Is there any way to simply bundle all of GDAL with my Xojo app so the user never has to set foot in the terminal to install it? I know that there are several open source (e.g., QGIS) and commercial apps that bundle all or parts of GDAL but I have no idea how one might do this in Xojo.
Nope, never heard of Docker. I just read some of the intro docs. It seems like that might work though I have a long way to get up to speed to do something with Docker. I’ll have to do some more exploring.
Pull the Image once
Execute this in Terminal: docker pull ghcr.io/osgeo/gdal:alpine-small-latest
Now you can run GDAL like this in Terminal: docker run --rm -v /local/path/to/a/folder:/home ghcr.io/osgeo/gdal:alpine-small-latest gdalinfo $PWD/my.tif
The interesting part in their example is: -v /local/path/to/a/folder:/home - to get your data into the docker container.
The above command will:
docker run: use Docker to run (the previously downloaded image) in a (new) container
--rm: once the command has finished, the container is removed again
-v /local/folder:/home mount a local folder into the container, so data on your machine can be accessed from within the container
ghcr.io/osgeo/gdal:alpine-small-latest the docker image to be used
gdalinfo $PWD/my.tif the command to be executed (within the docker container) $PWD will likely be /home, so that you can run commands and use the files in the mounted folder. Their examples assumes you have a file my.tif in /local/path/to/a/folder on your machine
Thanks, Jürg, for the additional info about Docker. It seems like a very powerful way to deliver functionality in a self contained package.
I guess my question is how would one wrap a GDAL Docker container inside a Xojo app and then access it using Shell commands on a user’s computer that had neither Docker nor GDAL explicitly installed, just the Xojo app? Or isn’t this possible?
It is. I only wanted to elaborate how “shell command to access GDAL” would look like (with the Docker approach, since that idea has come up).
Well, you most certainly won’t bundle Docker with your app. But it could check if Docker is installed, and inform that it’s a requirement to use the app. Then the app could just use the above Shell commands.
But I guess it’s not a good way for an end user app… since GDAL source is available, one could build the libraries and bundle/link it with an own app. But then I don’t think Xojo is the best tool. First you’d need to build the .dylib (macOS), .dll (Windows), .so (Linux) yourself. Then it likely would require lots of Declares. Or you’d write an own Plugin as a Xojo-Wrapper for/with the GDAL Libraries - which probably is an awful lot of work.