Skip to content

Instantly share code, notes, and snippets.

View agila5's full-sized avatar

Andrea Gilardi agila5

View GitHub Profile
# get data
library(osmextract)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright.
#> Check the package website, https://docs.ropensci.org/osmextract/, for more details.
munich_multilines <- oe_get(
  place = "Muenches", 
  layer = "multilinestrings", 
  provider = "bbbike", 
 extra_tags = "route"
# Sia X1, ..., Xn un campione casuale estratto da X ~ N(0, 1). Dalla teoria
# dell'inferenza statistica, sappiamo che lo stimatore
#
# (n - 1) S^2 / sigma ^ 2= 1 / sigma ^ 2 * sommatoria di (x_i - x_medio) ^ 2
#
# ha distribuzione Chi-quadrato con n - 1 gradi di liberta. Proviamo a
# verificare empiricamente questa affermazione.
m <- 1e4 # numero di simulazioni usate per approssimare la distribuzione
n <- 100 # numero di elementi nel campione
suppressPackageStartupMessages({library(spatstat)}) 

vertices <- ppp(
  c(0, 1, 2,  1, 1), 
  c(0, 1, 0, -1, 0),
  window = owin(c(-1, 3), c(-2, 2))
) 

#matrice di adiacenza 
library(stars)
#> Loading required package: abind
#> Loading required package: sf
#> Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE

# Download global NDVI data which average the values from 2024-05-01 to 2024-05-10
options(timeout = 1200)
tmp_nc <- tempfile(fileext = ".nc")
download.file(
@agila5
agila5 / st_covers.md
Last active April 7, 2025 08:26
Covers vs intersects
# Packages
library(sf)
#> Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE

# Let's work on the unit square
unit_square <- st_as_sfc(st_bbox(c(xmin = 0, xmax = 1, ymin = 0, ymax = 1)))

# Let's divide the unit square into 1600 (regular) cells
cells <- st_as_sf(st_make_grid(unit_square, cellsize = c(0.025, 0.025)))