Skip to content

Instantly share code, notes, and snippets.

@cybernar
cybernar / lire_projets.R
Last active March 14, 2023 16:13
Projets UMR 2023
#library(openxlsx)
library(tidyverse)
library(readxl)
library(nominatimlite)
library(sf)
library(htmltools)
# lire fichier excel
f_xlsx <- "data/00_Ressources_propres_UMR_2021_2023_corrige.xlsx"
@cybernar
cybernar / effemeshsize_cbc.R
Last active June 13, 2022 10:04
Grass module for Effective Mesh Size, CBC
# Effective Mesh Size (CBC)
library(vroom)
library(dplyr)
# pour surface en ha
divisurf <- 10000
nom_colonnes <- c("id", "id_patch", "surf_m2", "nb_pixels")
tbl_stats_grass <- vroom("FR/stats_completes.txt", delim = "\t", col_names= nom_colonnes, col_types = "iidi")

Configuration de snappy sur Windows 10

Création d'un environnement virtuel avec conda

snappy requiert la version 3.6 de Python (or la dernière version de Python est plutôt 3.10). L'utilisation de conda, qui permet d'utiliser plusieurs versions de python sur un même poste, prend tout son sens.

Pour créer et activer un environnement virtuel :

conda create -n snap_env -c conda-forge python=3.6 mamba

conda activate snap_env

@cybernar
cybernar / projets_2022.geojson
Last active March 14, 2023 12:41
Projets 2022
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cybernar
cybernar / app.R
Last active June 23, 2020 14:20
Shiny RStudio : Select polygon feature on a Leaflet map
# select polygon feature example
# with leaflet & shiny
library(shiny)
library(leaflet)
data(gadmCHE)
ui <- bootstrapPage(
tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
@cybernar
cybernar / safran2raster.R
Created May 3, 2019 13:28
Create raster from SAFRAN csv file
# safran 2 raster
library(data.table)
library(raster)
library(sf)
# ##### FONCTIONS #####
# genere 1 raster à partir de DT(data.table) pour la variable et la date spécifiées
@cybernar
cybernar / sf_snippets.R
Last active April 10, 2020 17:01
sf snippets
# genere sf à partir de data.frame
df2sf <- function(df, x_col, y_col, epsg) {
geomdef <- paste0("POINT(", df[[x_col]], " ", df[[y_col]],")")
sfc <- st_as_sfc(geomdef, epsg)
st_geometry(df) <- sfc
df
}
# autre solution
sf_points <- st_as_sf(df, crs=4326, coords=c("longitude", "latitude"), remove=FALSE)
@cybernar
cybernar / display_ff_bookmarks.html
Last active February 8, 2019 18:09
Display Firefox bookmarks (after exporting them to json)
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<!--
<link rel="stylesheet" href="design.css" />
<script src="script.js"></script>
-->
<script src="bookmarks-2019-02-08.js"></script>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto">

GIS DATA AND RESOURCES

CEFE-CNRS, sept 2019

The aim of this document is to list free spatial data and resources on the web for ecology and geography.

The data are identified by title, URL and keywords.

Summary

# random walk
f_point_in_circle <- function(x_from, y_from, step_dist=10, step_number=100) {
angle <- runif(step_number, 0, 360)
x_diff <- step_dist * cos(angle)
y_diff <- step_dist * sin(angle)
x_pos <- x_from + cumsum(x_diff)
y_pos <- y_from + cumsum(y_diff)
cbind(x=x_pos, y=y_pos)
}