| Title: | Spatial Analysis tools |
|---|---|
| Description: | sf2 extends the function of sf package. |
| Authors: | Dongdong Kong [aut, cre] |
| Maintainer: | Dongdong Kong <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.6 |
| Built: | 2026-05-05 07:40:47 UTC |
| Source: | https://github.com/rpkgs/sf2 |
get_RegionalMean
get_RegionalMean(f, shp = sf2::bou1_4p) get_RegionalMeans(fs, shp = sf2::bou1_4p)get_RegionalMean(f, shp = sf2::bou1_4p) get_RegionalMeans(fs, shp = sf2::bou1_4p)
guess_network
guess_network(info)guess_network(info)
info: |
the first two columns should be |
https://stackoverflow.com/questions/25130462/get-disjoint-sets-from-a-list-in-r
## Not run: info = shp_contains(shp) l_net = guess_networ(info) ## End(Not run)## Not run: info = shp_contains(shp) l_net = guess_networ(info) ## End(Not run)
load_data
load_china_river() load_china() load_continent()load_china_river() load_china() load_continent()
river$i$: river polylines
river_p$i$: river polygons
construct SpatialGridDataFrame
make_grid( range = c(-180, 180, -90, 90), cellsize = 1, midgrid = c(TRUE, TRUE), prj = NULL, type = "base", fix_lon360 = FALSE ) get_grid.lonlat(lon, lat, fix_lon360 = FALSE) fix_lon(x)make_grid( range = c(-180, 180, -90, 90), cellsize = 1, midgrid = c(TRUE, TRUE), prj = NULL, type = "base", fix_lon360 = FALSE ) get_grid.lonlat(lon, lat, fix_lon360 = FALSE) fix_lon(x)
range |
A numeric vector, |
cellsize |
Numeric vector, grid cell size |
midgrid |
A vector, |
prj |
|
type |
Character, one of
|
fix_lon360 |
boolean |
The input matrix suits for image, can be directly input to make_grid.
range <- c(73, 105, 25, 40) # Tibetan Plateau grid <- make_grid(range, cellsize = 1 / 2, midgrid = TRUE)range <- c(73, 105, 25, 40) # Tibetan Plateau grid <- make_grid(range, cellsize = 1 / 2, midgrid = TRUE)
make_rast
make_rast( range = c(-180, 180, -90, 90), cellsize = 1, nlyrs = 1, vals = NULL, ... )make_rast( range = c(-180, 180, -90, 90), cellsize = 1, nlyrs = 1, vals = NULL, ... )
range |
A numeric vector, |
cellsize |
Numeric vector, grid cell size |
nlyrs |
positive integer. Number of layers |
... |
other parameters to |
overlap_fraction
overlap_fraction(shp, cellsize = 0.1, range = NULL, outfile = NULL, ...)overlap_fraction(shp, cellsize = 0.1, range = NULL, outfile = NULL, ...)
I : the order of base, [lon, lat], image works directly on it.
cell: the order of gdal, [lon, rev(lat)], returned by values(r),
## Not run: library(nctools) f = "//kong-nas/CMIP6/DATA/China/CN0.5.1_ChinaDaily_025x025/yearly/CN05.1_Tmax_1961_2021_yearly_025x025.nc" data = ncread(f, "tmax") image(data[, , 1]) # should works r = rast(f) range = as.vector(ext(r)) cellsize = res(r) ## End(Not run) # shp = basin_Baihe load_china() shp = bou1_4p cellsize <- 0.5 range <- st_range(shp, cellsize) dat = overlap_fraction(shp, cellsize = cellsize, range, outfile = NULL) print(dat)## Not run: library(nctools) f = "//kong-nas/CMIP6/DATA/China/CN0.5.1_ChinaDaily_025x025/yearly/CN05.1_Tmax_1961_2021_yearly_025x025.nc" data = ncread(f, "tmax") image(data[, , 1]) # should works r = rast(f) range = as.vector(ext(r)) cellsize = res(r) ## End(Not run) # shp = basin_Baihe load_china() shp = bou1_4p cellsize <- 0.5 range <- st_range(shp, cellsize) dat = overlap_fraction(shp, cellsize = cellsize, range, outfile = NULL) print(dat)
rast_coord
rast_df(r, .area = TRUE, na.rm = FALSE)rast_df(r, .area = TRUE, na.rm = FALSE)
I : the order of base, [lon, lat], image works directly on it.
cell: the order of gdal, [lon, rev(lat)], returned by values(r),
rdist.earth
rdist.earth(x1, x2 = NULL)rdist.earth(x1, x2 = NULL)
x1 |
A position matrix |
x2 |
same as x1 |
This function allows you to select specific layers from a SpatRaster object using tidyverse-style syntax similar to dplyr's select. Supports selection by name, position, and tidyselect helpers.
## S3 method for class 'SpatRaster' select(.data, ...)## S3 method for class 'SpatRaster' select(.data, ...)
.data |
A SpatRaster object containing multiple layers |
... |
Expressions for selecting layers. You can use:
|
A SpatRaster object containing only the selected layers
## Not run: library(terra) r <- rast(c("elevation.tif", "slope.tif", "aspect.tif")) # Select by name r_elev <- select(r, elevation) # Select multiple layers r_sub <- select(r, elevation, slope) # Exclude layers with negative selection r_no_aspect <- select(r, -aspect) # Use tidyselect helpers r_s <- select(r, starts_with("s")) ## End(Not run)## Not run: library(terra) r <- rast(c("elevation.tif", "slope.tif", "aspect.tif")) # Select by name r_elev <- select(r, elevation) # Select multiple layers r_sub <- select(r, elevation, slope) # Exclude layers with negative selection r_no_aspect <- select(r, -aspect) # Use tidyselect helpers r_s <- select(r, starts_with("s")) ## End(Not run)
st_dissolve
st_dissolve(x, by = NULL, ...) ## S3 method for class 'sf' st_dissolve(x, by = NULL, ...) ## S3 method for class 'character' st_dissolve(x, by = NULL, ...)st_dissolve(x, by = NULL, ...) ## S3 method for class 'sf' st_dissolve(x, by = NULL, ...) ## S3 method for class 'character' st_dissolve(x, by = NULL, ...)
st_extractId
st_extractId(x, y, plot = TRUE, ...)st_extractId(x, y, plot = TRUE, ...)
x |
A sf point, or file path |
y |
A sf polygon, or file path |
plot |
Boolean. Whether to visualize extracted points? |
... |
others passed to |
sf objectget range of sf object
st_range(x, cellsize = 0.1)st_range(x, cellsize = 0.1)
x |
|
cellsize |
double |
st_rect
st_rect(range, crs = st_crs(4326))st_rect(range, crs = st_crs(4326))
range |
|
## Not run: xlim <- c(112, 115) ylim <- c(21, 23) range <- c(xlim, ylim) poly <- st_rect(range) write_sf(poly, "poly.shp") ## End(Not run)## Not run: xlim <- c(112, 115) ylim <- c(21, 23) range <- c(xlim, ylim) poly <- st_rect(range) write_sf(poly, "poly.shp") ## End(Not run)
write and read ESRI Shapefile
write_shp(x, file, ...)write_shp(x, file, ...)
x |
Spatial* Object from sp package |
file |
The path of ESRI shapefile |
... |
other parameters to |