{"metadata":{"kernelspec":{"display_name":"R","language":"R","name":"ir"},"language_info":{"codemirror_mode":"r","file_extension":".r","mimetype":"text/x-r-source","name":"R","pygments_lexer":"r","version":"4.0.3"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Spatial Interpolation - Part 2\n\n
\n\n\n\n
\n\n## Analysis Preparation\n\n### Imports\n\nAll of these libraries should have been previously installed during the environment set-up, if they have not been installed already you can use ```install.packages(c(\"raster\", \"rgdal\", \"ape\", \"scales\", \"deldir\", \"gstat\"))```","metadata":{}},{"cell_type":"code","source":"library(raster) # rasters\nlibrary(rgdal) # spatial data\nlibrary(sf) # for handling spatial features\nlibrary(ape) # clustering (Morans I)\nlibrary(scales) # transparencies\nlibrary(deldir) # triangulation\nlibrary(gstat) # geostatistics\n\nsource('../scripts/helpers.R') # helper script, note that '../' is used to change into the directory above the directory this notebook is in","metadata":{"trusted":true},"execution_count":1,"outputs":[{"name":"stderr","text":"Loading required package: sp\n\nrgdal: version: 1.5-16, (SVN revision 1050)\nGeospatial Data Abstraction Library extensions to R successfully loaded\nLoaded GDAL runtime: GDAL 3.1.4, released 2020/10/20\nPath to GDAL shared files: /srv/conda/envs/notebook/share/gdal\nGDAL binary built with GEOS: TRUE \nLoaded PROJ runtime: Rel. 7.1.1, September 1st, 2020, [PJ_VERSION: 711]\nPath to PROJ shared files: /srv/conda/envs/notebook/share/proj\nPROJ CDN enabled: TRUE\nLinking to sp version:1.4-2\nTo mute warnings of possible GDAL/OSR exportToProj4() degradation,\nuse options(\"rgdal_show_exportToProj4_warnings\"=\"none\") before loading rgdal.\n\nLinking to GEOS 3.8.1, GDAL 3.1.4, PROJ 7.1.1\n\n\nAttaching package: ‘ape’\n\n\nThe following objects are masked from ‘package:raster’:\n\n rotate, zoom\n\n\ndeldir 0.2-3 Nickname: \"Stack Smashing Detected\"\n\n\n Note 1: As of version 0.2-1, error handling in this \n package was amended to conform to the usual R protocol. \n The deldir() function now actually throws an error \n when one occurs, rather than displaying an error number \n and returning a NULL.\n \n Note 2: As of version 0.1-29 the arguments \"col\" \n and \"lty\" of plot.deldir() had their names changed to \n \"cmpnt_col\" and \"cmpnt_lty\" respectively basically \n to allow \"col\" and and \"lty\" to be passed as \"...\" \n arguments.\n \n Note 3: As of version 0.1-29 the \"plotit\" argument \n of deldir() was changed to (simply) \"plot\".\n \n See the help for deldir() and plot.deldir().\n\n\n","output_type":"stream"}]},{"cell_type":"markdown","source":"
\n\n### Loading Data\n\nWe'll start by again checking to see if we need to download any data.","metadata":{}},{"cell_type":"code","source":"download_data()","metadata":{"trusted":true},"execution_count":2,"outputs":[]},{"cell_type":"markdown","source":"
\n\nWe'll then load in the datasets.","metadata":{}},{"cell_type":"code","source":"df_zambia <- read_sf('../data/zambia/zambia.shp')\ndf_africa_cities <- read_sf('../data/africa/cities.shp')\nsolar <- raster('../data/zambia/solar.tif')\naltitude <- raster('../data/zambia/altitude.tif')","metadata":{"trusted":true},"execution_count":3,"outputs":[]},{"cell_type":"markdown","source":"
\n\nDo some pre-processing on the zambian cities dataset (which we'll use as points in our Voronoi diagram later).","metadata":{}},{"cell_type":"code","source":"df_zambian_cities <- df_africa_cities[which(df_africa_cities$COUNTRY=='Zambia'), ]\ndf_zambian_cities_UTM35S <- st_transform(df_zambian_cities, crs=st_crs(20935))\n\nhead(df_zambian_cities_UTM35S, 3)","metadata":{"trusted":true},"execution_count":4,"outputs":[{"output_type":"display_data","data":{"text/html":"
LATLONGID | LATITUDE | LONGITUDE | URBORRUR | YEAR | ES90POP | ES95POP | ES00POP | INSGRUSED | CONTINENT | geometry | ⋯ | SCHADMNM | ADMNM1 | ADMNM2 | TYPE | SRCTYP | COORDSRCE | DATSRC | LOCNDATSRC | NOTES | geometry |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<dbl> | <dbl> | <dbl> | <chr> | <dbl> | <int> | <int> | <int> | <chr> | <chr> | ⋯ | <chr> | <chr> | <chr> | <chr> | <chr> | <chr> | <chr> | <chr> | <chr> | <POINT [m]> | |
4 | -12.65000 | 28.08333 | U | 1990 | 9945 | 10684 | 11218 | N | Africa | POINT (617646.2 8601614) | ⋯ | COPPERBELT | Copperbelt | Kalulushi | UA | Published | NIMA | Census of Population, Housing & Argriculture 1990 Descriptive Tables | UN Statistical Library | NA | POINT (617646.2 8601614) |
7 | -12.36667 | 27.83333 | U | 1990 | 48055 | 51629 | 54206 | N | Africa | POINT (590593.6 8633048) | ⋯ | COPPERBELT | Copperbelt | Chililabombwe | UA | Published | NIMA | Census of Population, Housing & Argriculture 1990 Descriptive Tables | UN Statistical Library | NA | POINT (590593.6 8633048) |
9 | -12.53333 | 27.85000 | U | 1990 | 142383 | 152972 | 160610 | N | Africa | POINT (592346.6 8614610) | ⋯ | COPPERBELT | Copperbelt | Chingola | UA | Published | NIMA | Census of Population, Housing & Argriculture 1990 Descriptive Tables | UN Statistical Library | NA | POINT (592346.6 8614610) |