This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sp) | |
library(sf) | |
library(tidyverse) | |
library(rosm) | |
library(ggspatial) | |
nc <- st_read(system.file("shape/nc.shp", package="sf")) | |
ncsp <- as(nc, 'Spatial') | |
# only for sf < 0.5 I think...? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
library(tidyverse) | |
setwd('C:/data/prepair_test') | |
# a file with known problems, also at https://github.com/obrl-soil/bits-n-pieces/tree/master/r2p | |
tester <- read_sf('C:/data/r2p/cat_v_pretty.gpkg') | |
# I used the QGIS topology checker tool to find invalid geometries. Row 130 is no good: | |
plot(st_geometry(tester[130, ])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inset method based on https://gis.stackexchange.com/questions/222799/create-an-inset-map-in-r/222877#222877 | |
# libraries | |
library(sf) | |
library(raster) | |
library(tidyverse) | |
library(rosm) | |
library(ggspatial) | |
library(ggsn) | |
library(rmapshaper) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# method: raster stack to uniquely attributed polygons | |
# using GRASS 7.4 to avoid rasterToPolygons | |
library(sp) | |
library(sf) | |
library(raster) | |
library(rgrass7) | |
library(dsmartr) # just for the demo dataset | |
# https://github.com/obrl-soil/dsmartr/blob/master/data/heronvale_covariates.rda | |
data("heronvale_covariates") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 2018-07-03 | |
# An example of doing some slightly fancy stuff with GDAL on the command line | |
# from R using OSGeo4W GDAL, which is on system PATH already | |
# Task: rescale all input covariate rasters to the last BM run to [0, 1], see | |
# if it makes any difference to model outputs (spoiler: no) | |
library(raster) | |
library(tidyverse) | |
options(stringsAsFactors = FALSE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
options(stringsAsFactors = FALSE) | |
# 94720 points - | |
# src: http://qldspatial.information.qld.gov.au/catalogue/custom/search.page?q=SALI_SITE | |
many_points <- st_read('D:/Spatial_data/soils/soil_survey_sites.shp') %>% | |
st_transform(., crs = 3577) # always dist planar, kids | |
# divide in 2 | |
many_points$nrow <- as.numeric(1:nrow(many_points)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from https://twitter.com/RallidaeRule/status/1083102769169514497 | |
library(sf) | |
options(stringsAsFactors = FALSE) | |
nc <- st_read(system.file("shape/nc.shp", package="sf")) | |
pts <- st_centroid(nc[1:3, ]) | |
pts <- pts[ , c('NAME')] | |
pts <- st_transform(pts, 32617) | |
buff <- st_buffer(pts, 10000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find the nearest vertex on a polygon to a point | |
# re: https://twitter.com/EmmaVitz/status/1095574327855001600 | |
library(sf) | |
nc <- st_read(system.file("shape/nc.shp", package="sf")) | |
# pick a random state: | |
nc1 <- nc[sample(seq(nrow(nc)), 1), ] | |
# always project to a plane before using geos funs! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# faffing about with methods to approximate a "lag vertex polygon" (Poore, 1986) | |
# or "best-fit regular geometric feature" (Stoddard, 1965) for polygon shape | |
# metric | |
# References: | |
# Poore 1986 - MSc Thesis on soil map quantification at | |
# https://ir.library.oregonstate.edu/downloads/zk51vk04q | |
# Stoddart, D. (1965). The shape of atolls. Marine Geology, 3(5), 369–383. | |
# doi:10.1016/0025-3227(65)90025-3 (its on scihub) | |
# also apparently Fridland 1972 "The pattern of the soil cover" but that's |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# datapasta'd http://worldpopulationreview.com/us-counties/nc/ | |
#library(datapasta) | |
#df_paste() | |
nc_pop <- data.frame(stringsAsFactors=FALSE, | |
V1 = c("Mecklenburg County", "Wake County", "Guilford County", | |
"Forsyth County", "Cumberland County", "Durham County", | |
"Buncombe County", "Union County", "New Hanover County", | |
"Gaston County", "Cabarrus County", "Johnston County", "Onslow County", | |
"Pitt County", "Iredell County", "Davidson County", | |
"Alamance County", "Catawba County", "Orange County", "Randolph County", |