Git Product home page Git Product logo

geo-docker-mamba's Introduction

Geocomputation with R in Docker

This repo documents Docker images for geographic research and reproducing code in the book Geocomputation with R. The Dockerfiles build on work done for the Rocker Project. As documented on the Rocker Project website, Docker can save time and increase reproducibility by providing an environment with up-to-date and stable software.

To get started, after you install Docker, try running one of the following commands:

# The latest version of rocker/geospatial + geocompr dependencies
docker run -e PASSWORD=pw --rm -p 8786:8787 geocompr/geocompr
# With up-to-date OSGeo packages and qgisprocess:
docker run -e PASSWORD=pw --rm -p 8786:8787 geocompr/geocompr:dev-osgeo

If you are asked for a username and password, then you should use rstudio as your username and the password you set with the above code (e.g., pw).

Then open a browser at http://localhost:8786/, and you should see something like this:

If so congratulations 🎉 you can proceed to open the geocompr.Rproj project or other files in the geocompr folder, which contains a complete copy of the source code and example data needed to build the html version of the book.

To run a container without RStudio, try the following.

docker run -e PASSWORD=pw --rm -ti geocompr/geocompr /bin/bash

Use this resource to play with the examples, develop new answers to the questions at the end of each page, or even to generate reproducible examples to illustrate issues with the books contents.

If not, see documentation on using Docker at websites such as docker.com and https://www.rocker-project.org/.

Sharing folders with Docker

To use these Docker images for your own work you will need to share files with Docker. That means sharing ‘volumes’. You can do this using the -v argument as shown below, which shares your current working directory with the Docker container. If you run these commands in a terminal that has access to Docker, like bash or Windows PowerShell you should get a local copy of Geocomputation with R on your computer that you can use for testing and development purposes, e.g. to test changes before submitting a Pull Request to improve the book:

# download repo with Windows Powershell or a Unix terminal
git clone https://github.com/Robinlovelace/geocompr.git 
# or download manually from https://github.com/Robinlovelace/geocompr/archive/main.zip
cd geocompr # navigate into the repo
# on linux and mac with password:
docker run -d -p 8786:8787 -v $(pwd):/home/rstudio/data -e USERID=$UID -e PASSWORD=pw geocompr/geocompr:minimal
# on linux and mac without password:
docker run -d -p 8786:8787 -e DISABLE_AUTH=TRUE -v $(pwd):/home/rstudio/geocompr  geocompr/geocompr:minimal
# on windows without a password:
docker run -d -p 8786:8787 -v ${pwd}:/home/rstudio/data -e DISABLE_AUTH=TRUE robinlovelace/geocompr:minimal

If you see something like this after following the steps above, congratulations: it worked! See github.com/rocker-org for more info.

You can also pull and run the same images from ghcr.io, e.g. as follow:

docker run -d -p 8786:8787 -v $(pwd):/home/rstudio/data -e PASSWORD=pw ghcr.io/geocompr/geocompr:minimal

From this point to build the book you can open projects in the geocompr directory from the project box in the top-right hand corner, and knit index.Rmd with the little knit button above the the RStudio script panel (Ctl+Shift+B should do the same job).

There are various versions of the geocompr Docker image available. The default is the latest tag, representing the Dockerfile in the root of this repo, but you can get other images, as outlined below.

Versions

Building on the rocker-org project, we provide various versions for testing and development, including builds that use more up-to-date versions of OSGeo packages such as GDAL provided by the UbuntuGIS software repository, as shown below:

image description size
geocompr:latest geocompr/geocompr:minimal image + book files
geocompr:minimal rocker/geospatial plus core packages from geocompkg (Imports)
geocompr:suggests rocker/geospatial plus all packages from geocompkgs (Suggests)
geocompr:osgeo geocompr/geocompr:minimal running on rocker/geospatial:dev-osgeo
geocompr:unzipped rocker/geospatial:latest with book contents
geocompr:buildbook rocker/geospatial:suggests that runs the book code
geocompr:qgis geocompr/geocompr with QGIS
geocompr:qgis-dev geocompr/geocompr with dev version of QGIS
geocompr:qgis-min geocompr/geocompr with just QGIS + qgisprocess
geocompr:python geocompr/geocompr:osgeo with Python
geocompr:geocompy rocker/geospatial:dev-osgeo with Python packages
geocompr:geocompy rocker/geospatial:conda with Python packages installed with Miniconda
geocompr:geocompy rocker/geospatial:mamba with Python packages installed with MicroMamba

The base image is rocker/geospatial from github.com/rocker-org/rocker-versioned2.

Add :tagname to geocompr/geocompr to get the image you want.

docker run -e PASSWORD=pw --rm -p 8786:8787 geocompr/geocompr:buildbook

Examples

osgeo

To test your code or package against recent versions of OSGeo libraries (GDAL, GEOS, PROJ), you can run the following command from inside root directory of the folder containing the code:

# on linux and mac with password:
docker run -d -p 8786:8787 -v $(pwd):/home/rstudio/data \
  -e USERID=$UID -e PASSWORD=pw geocompr/geocompr:osgeo

Python

The Python tag contains Python geospatial packages:

docker run -e PASSWORD=pw --rm -ti geocompr/geocompr:python /bin/bash

python3
import pandas as pd
import geopandas as gpd
import movingpandas as mpd

You can run an interactive session via Reticulate in RStudio as follows:

docker run -e PASSWORD=pw --rm -p 8786:8787 geocompr/geocompr:python

And then in the resulting RStudio session you can enter something along the lines of:

library(sf)
f = file.path(system.file("shape/nc.shp", package="sf"))
nc_sf = read_sf(f)
library(reticulate)
system("pip3 install descartes")
gp = import("geopandas")
nc_gp = gp$read_file(f)
class(nc_gp)
plot(nc_gp$AREA, nc_gp$PERIMETER)
gp = import("geopandas", convert = FALSE)
nc_gp = gp$read_file(f)
nc_gp
plt = import("matplotlib.pyplot", convert = FALSE)
nc_gp$plot()
plt$savefig("test.png")

To plot from Python packages (work in progress).

QGIS

To run QGIS from the command line, you can run:

docker pull geocompr/geocompr:qgis
docker run --rm -ti geocompr/geocompr:qgis /bin/bash
qgis --version
# QGIS 3.20.3-Odense 'Odense' (495fbaecaf)

You can also run QGIS algorithms via the qgisprocess package as follows:

docker run -d -p 8786:8787 -v $(pwd):/home/rstudio/data -e PASSWORD=pw geocompr/geocompr:qgis

Then open a browser and the local url such as http://192.168.0.99:8786/ or http://localhost:8786, enter RStudio server, and you should be able to access QGIS as follows in the R console:

system("qgis --version")
## QGIS 3.16.1-Hannover 'Hannover' (b381a90dca)
remotes::install_github("paleolimbot/qgisprocess") # install the latest version of the package
qgis_algs = qgisprocess::qgis_algorithms()
nrow(qgis_algs)
## [1] 303
table(qgis_algs$provider)
##    3d   gdal native   qgis 
##     1     55    196     51 

QGIS extensions

You can access algorithms from other GIS programs through QGIS but they need to be installed. These can be accessed from the geocompr/geocompr:qgis image as follows:

docker run -d -p 8786:8787 -v $(pwd):/home/rstudio/data -e PASSWORD=pw geocompr/geocompr:qgis

Again, open the browser, e.g. at http://localhost:8786, and find the new algorithms as follows:

system("qgis --version")
## QGIS 3.16.1-Hannover 'Hannover' (b381a90dca)
remotes::install_github("paleolimbot/qgisprocess") # install the latest version of the package
## Skipping install of 'qgisprocess' from a github remote, the SHA1 (6e378511) has not changed since last install.
qgis_algs = qgisprocess::qgis_algorithms()
nrow(qgis_algs)
## [1] 970
table(qgis_algs$provider)

##    3d   gdal grass7 native   qgis   saga 
##     1     55    301    196     51    366 

Congratulations, you now have nearly 1000 QGIS algorithms at your disposal from the R command line 🎉

Building the images locally

You can build the images locally, e.g. as follows:

docker build qgis -t test
docker run -p 8888:8888 test
docker build conda -t geocompy
docker run -it geocompy /bin/bash
docker build mamba -t geocompy

geo-docker-mamba's People

Contributors

jannes-m avatar nowosad avatar robinlovelace avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.