This manual is tended both for R users wishing to set up spatial data peocessing and for users wishing to use R to carry out the tasks that they usually carry out with GIS. The main steps in the processing of geographic information are covered. Emphasis is placed on the processing of vector data but a part is still dedicated to raster data.
**How to use the manual**\
The RStudio project containing all the data used in the manual is available [here](https://github.com/rCarto/geodata/archive/refs/heads/main.zip). Once the file is unzipped it is possible to test all the manipulations proposed in the RStudion project.
**Context**\
This manual has been designed from the courses "[Géomatique avec R](https://rcarto.github.io/geomatique_avec_r/)" and "[Cartographie avec R](https://rcarto.github.io/cartographie_avec_r/)" by Timothée Giraud and Hugues Pecout. It has been translated and its examples have been adapted to the geographical distribution of the audience.
The online version of this document licensed under the [Creative Commons Attribution-NonCommercial-ShareAlike 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/).
<p><imgsrc="img/geohealth_banner.jpeg"title="Mapping and spatial analyses in R for One Health studies"class="quarto-cover-image img-fluid"></p><h1class="unnumbered">Preface</h1>
<p>This manual is tended both for R users wishing to set up spatial data peocessing and for users wishing to use R to carry out the tasks that they usually carry out with GIS. The main steps in the processing of geographic information are covered. Emphasis is placed on the processing of vector data but a part is still dedicated to raster data.</p>
<p><strong>How to use the manual</strong><br>
The RStudio project containing all the data used in the manual is available <ahref="https://github.com/rCarto/geodata/archive/refs/heads/main.zip">here</a>. Once the file is unzipped it is possible to test all the manipulations proposed in the RStudion project.</p>
<p><strong>Context</strong><br>
This manual has been designed from the courses “<ahref="https://rcarto.github.io/geomatique_avec_r/">Géomatique avec R</a>” and “<ahref="https://rcarto.github.io/cartographie_avec_r/">Cartographie avec R</a>” by Timothée Giraud and Hugues Pecout. It has been translated and its examples have been adapted to the geographical distribution of the audience.</p>
<p>The online version of this document licensed under the <ahref="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0</a>.</p>
"text":"4.6 Transformation and conversion\n\n4.6.1 Rasterization\nConvert polygons to raster format.\n\nchamkarmon = subset(district, district$ADM2_PCODE ==\"KH1201\") \nraster_district <- rasterize(x = chamkarmon, y = elevation_clip_utm)\n\n\nplot(raster_district)\n\n\n\n\n\n\n\n\nConvert points to raster format\n\n#rasterization of the centroids of the municipalities\nraster_dist_centroid <- rasterize(x = centroids(district), \n y = elevation_clip_utm, fun=sum)\nplot(raster_dist_centroid, col = \"red\")\nplot(district, add =TRUE)\n\n\n\n\nConvert lines in raster format\n\n#rasterization of municipal boundaries\nraster_dist_line <- rasterize(x = as.lines(district), y = elevation_clip_utm, fun=sum)\n\n\nplot(raster_dist_line)\n\n\n\n\n\n\n4.6.2 Vectorisation\nTransform a raster to vector polygons.\n\npolygon_elevation <- as.polygons(elevation_clip_utm)\n\n\nplot(polygon_elevation, y = 1, border=\"white\")\n\n\n\n\nTransform a raster to vector points.\n\npoints_elevation <- as.points(elevation_clip_utm)\n\n\nplot(points_elevation, y = 1, cex = 0.3)\n\n\n\n\nTransform a raster into vector lines.\n\nlines_elevation <- as.lines(elevation_clip_utm)\n\n\nplot(lines_elevation)\n\n\n\n\n\n\n4.6.3 terra, raster, sf, stars…\nReference packages for manipulating spatial data all rely o their own object class. It is sometimes necessary to convert these objects from one class to another class to take advance of all the features offered by these different packages.\nConversion functions for raster data:\n\n\n\nFROM/TO\nraster\nterra\nstars\n\n\n\n\nraster\n\nrast()\nst_as_stars()\n\n\nterra\nraster()\n\nst_as_stars()\n\n\nstars\nraster()\nas(x, ‘Raster’) + rast()\n\n\n\n\nConversion functions for vector data:\n\n\n\nFROM/TO\nsf\nsp\nterra\n\n\n\n\nsf\n\nas(x, ‘Spatial’)\nvect()\n\n\nsp\nst_as_sf()\n\nvect()\n\n\nterra\nst_as_sf()\nas(x, ‘Spatial’)\n\n\n\n\n\n\n\n\nHijmans, Robert J. 2022. “Terra: Spatial Data Analysis.” https://CRAN.R-project.org/package=terra.\n\n\nLi, Xingong. 2009. “Map Algebra and Beyond : 1. Map Algebra for Scalar Fields.” https://slideplayer.com/slide/5822638/.\n\n\nMadelin, Malika. 2021. “Analyse d’images Raster (Et Télédétection).” https://mmadelin.github.io/sigr2021/SIGR2021_raster_MM.html.\n\n\nMennis, Jeremy. 2015. “Fundamentals of GIS : Raster Operations.” https://cupdf.com/document/gus-0262-fundamentals-of-gis-lecture-presentation-7-raster-operations-jeremy.html.\n\n\nNowosad, Jakub. 2021. “Image Processing and All Things Raster.” https://nowosad.github.io/SIGR2021/workshop2/workshop2.html.\n\n\nRacine, Etienne B. 2016. “The Visual Raster Cheat Sheet.” https://rpubs.com/etiennebr/visualraster."
},
{
"objectID":"index.html",
"href":"index.html",
"title":"Mapping and spatial analyses in R for One Health studies",
"section":"",
"text":"This manual is tended both for R users wishing to set up spatial data peocessing and for users wishing to use R to carry out the tasks that they usually carry out with GIS. The main steps in the processing of geographic information are covered. Emphasis is placed on the processing of vector data but a part is still dedicated to raster data.\nHow to use the manual\nThe RStudio project containing all the data used in the manual is available here. Once the file is unzipped it is possible to test all the manipulations proposed in the RStudion project.\nContext\nThis manual has been designed from the courses “Géomatique avec R” and “Cartographie avec R” by Timothée Giraud and Hugues Pecout. It has been translated and its examples have been adapted to the geographical distribution of the audience.\n\n\n\n\nCreative Commons License\n\n\nThe online version of this document licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0."