{"id":14067424,"url":"https://github.com/statnmap/cartomisc","last_synced_at":"2025-10-05T10:33:39.394Z","repository":{"id":43085109,"uuid":"183621067","full_name":"statnmap/cartomisc","owner":"statnmap","description":"Miscellaneous tools for spatial data manipulation and analysis","archived":false,"fork":false,"pushed_at":"2022-03-19T15:51:53.000Z","size":636,"stargazers_count":10,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T10:43:27.413Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://statnmap.github.io/cartomisc/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/statnmap.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-26T12:01:44.000Z","updated_at":"2023-06-29T10:49:05.000Z","dependencies_parsed_at":"2022-09-06T03:21:03.747Z","dependency_job_id":null,"html_url":"https://github.com/statnmap/cartomisc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fcartomisc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fcartomisc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fcartomisc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statnmap%2Fcartomisc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statnmap","download_url":"https://codeload.github.com/statnmap/cartomisc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249746041,"owners_count":21319581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-13T07:05:35.220Z","updated_at":"2025-10-05T10:33:34.371Z","avatar_url":"https://github.com/statnmap.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n# cartomisc\n\n\u003c!-- badges: start --\u003e\n[![R build status](https://github.com/statnmap/cartomisc/workflows/R-CMD-check/badge.svg)](https://github.com/statnmap/cartomisc/actions)\n\u003c!-- badges: end --\u003e\n\nThe goal of {cartomisc} is to store a few useful functions for spatial data manipulation and analysis. \n\n## Installation\n\nYou can install the dev version on Github\n\n```{r, eval=FALSE}\n# install.packages(\"remotes\")\nremotes::install_github(\"statnmap/cartomisc\")\n```\n\n# Usage\n\n```{r, message=FALSE}\nlibrary(dplyr)\nlibrary(raster)\nlibrary(cartomisc)\nlibrary(ggplot2)\nlibrary(sf)\n```\n\n## Extract part of the data with `gplot_data`\n\nTo draw multiple raster on the same ggplot2, or to draw raster after other objects (points, polygons, lines)\n\n- data are extracted as a tibble\n- data can then be added to a ggplot2 with `geom_tile`\n\n```{r}\n# Read some data\nslogo \u003c- stack(system.file(\"external/rlogo.grd\", package = \"raster\")) \nslogo\n\n# Get partial raster data to plot in ggplot\nr.gg \u003c- gplot_data(slogo)\n\n# Remove NA to reduce size of table\nr.gg.nona \u003c- r.gg %\u003e% \n  filter(!is.na(value))\n\nr.gg.nona\n```\n\n### Plot with ggplot2\n\n```{r, fig.width=12, fig.height=4}\n# Plot\nggplot(r.gg.nona) +\n  geom_tile(aes(x = x, y = y, fill = value)) +\n  scale_fill_gradient(\"Probability\", low = 'yellow', high = 'blue') +\n  facet_wrap(vars(variable)) +\n  coord_equal()\n```\n\n## Sun position\n\nCalculate sun position for hillShade\n\n```{r}\nsun_position \u003c- sun_position(2019, 04, 26,\n  hour = 12, min = 0, sec = 0,\n  lat = 46.5, long = 6.5\n)\nsun_position\n```\n\nUse with hillShade\n\n```{r}\nr \u003c- raster(system.file(\"external/rlogo.grd\", package = \"raster\"))\n# slope and aspect\nr_slope \u003c- terrain(r, opt = \"slope\")\nr_aspect \u003c- terrain(r, opt = \"aspect\")\n# hillshade\nr_hillshade \u003c- hillShade(r_slope, r_aspect, angle = sun_position$elevation, direction = sun_position$azimuth)\n# plot\nimage(r)\nimage(r_hillshade, col = grey(seq(0, 1, 0.1), alpha = 0.5), add = TRUE)\n```\n\n## Create buffer areas with attribute of the closest region\n\n- Download some data\n```{r}\n# Define where to save the dataset\nextraWD \u003c- tempdir()\n# Get some data available to anyone\nif (!file.exists(file.path(extraWD, \"departement.zip\"))) {\n  githubURL \u003c- \"https://github.com/statnmap/blog_tips/raw/master/2018-07-14-introduction-to-mapping-with-sf-and-co/data/departement.zip\"\n  download.file(githubURL, file.path(extraWD, \"departement.zip\"))\n  unzip(file.path(extraWD, \"departement.zip\"), exdir = extraWD)\n}\n```\n\n- Reduce the dataset to a small region\n```{r}\ndepartements_l93 \u003c- read_sf(dsn = extraWD, layer = \"DEPARTEMENT\")\n\n# Reduce dataset\nbretagne_l93 \u003c- departements_l93 %\u003e%\n  filter(NOM_REG == \"BRETAGNE\")\n```\n\n- Calculate the regional buffer area using `regional_seas()`\n```{r}\nbretagne_regional_2km_l93 \u003c- regional_seas(\n  x = bretagne_l93,\n  group = \"NOM_DEPT\",\n  dist = units::set_units(30, km), # buffer distance\n  density = units::set_units(0.5, 1/km) # density of points (the higher, the more precise the region attribution)\n)\n```\n\n- Plot the data\n```{r}\nggplot() + \n  geom_sf(data = bretagne_regional_2km_l93,\n          aes(colour = NOM_DEPT, fill = NOM_DEPT),\n          alpha = 0.25) +\n  geom_sf(data = bretagne_l93,\n          aes(fill = NOM_DEPT),\n          colour = \"grey20\",\n          alpha = 0.5) +\n  scale_fill_viridis_d() +\n  scale_color_viridis_d() +\n  theme_bw()\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatnmap%2Fcartomisc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatnmap%2Fcartomisc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatnmap%2Fcartomisc/lists"}