Skip to content

Instantly share code, notes, and snippets.

# snippets R raster
library(raster)
# creer raster vide type entier 60 x 80 km, res 500 m
rvide.crs <- CRS("+init=EPSG:2154")
rvide.ext <- extent(c(688500,748500,6292500,6372500))
rvide.val <- rep(0, 120*160)
rvide <- raster(crs=rvide.crs, ext=rvide.ext, resolution=500, vals=rvide.val)
writeRaster(rvide, filename="D:/GIS_DATA/HomeRange/RSpatial/reference_grid2.asc", format="ascii", datatype='INT2S', NAflag=-9999)
CREATE TABLE carto.parcelles
(
num_fiche serial NOT NULL,
date_debut date,
date_fin date,
surface numeric(10, 2),
personnes text,
code_dept character(10),
laboratoire text,
@cybernar
cybernar / ncdf_extract_values.R
Last active November 23, 2016 12:10
Extract values at XY position from NetCDF file
library(raster)
library(ncdf4)
library(maptools)
# netcdf file from ftp://aspen.atmos.albany.edu/pdsi/cmip5/scPDSIpm/pdsisc.monthly.maps.1900-2099.r2.5x2.5.EnsAvg14Models.TP2.ipe=2.nc
# shp file from http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_airports.zip
# load netcdf file as a raster brick
f <- "D:/bacasable/pdsisc.monthly.maps.1900-2099.r2.5x2.5.EnsAvg14Models.TP2.ipe=2.nc"
rbr <- brick(f, varname="pdsisc")
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cybernar
cybernar / S2_reflectance.R
Created January 21, 2019 18:29
Process Sentinel2 reflectance data from Theia
## CALCUL NDVI avec masque nuages
## Image couleur naturel Sentinel2
library(raster)
library(rgdal)
library(stringr)
# 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)
}

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

@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">
@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)