overlap_fraction

overlap_fraction(shp, cellsize = 0.1, range = NULL, outfile = NULL, ...)

Value

  • I : the order of base, [lon, lat], image works directly on it.

  • cell: the order of gdal, [lon, rev(lat)], returned by values(r),

Examples

if (FALSE) { # \dontrun{
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)
} # }

# shp = basin_Baihe
shp = bou1_4p
cellsize <- 0.5
range <- st_range(shp, cellsize)

dat = overlap_fraction(shp, cellsize = cellsize, range, outfile = NULL)
print(dat)
#>          lon   lat     I  cell     fraction     area        area2
#>        <num> <num> <int> <int>        <num>    <num>        <num>
#>    1: 113.25  6.25    81 11956 1.632373e-04 3059.473   0.49941997
#>    2: 113.75  6.75   207 11832 7.004493e-05 3056.512   0.21409320
#>    3: 113.75  7.25   332 11707 4.710106e-05 3053.325   0.14381485
#>    4: 112.75  7.75   455 11580 1.864005e-04 3049.911   0.56850489
#>    5: 113.75  7.75   457 11582 1.657153e-04 3049.911   0.50541709
#>   ---                                                            
#> 4218: 125.25 53.25 11855   230 3.228767e-01 1857.117 599.61984338
#> 4219: 125.75 53.25 11856   231 3.811586e-02 1857.117  70.78561569
#> 4220: 122.25 53.75 11974    99 2.232263e-05 1835.549   0.04097429
#> 4221: 123.25 53.75 11976   101 5.155858e-02 1835.549  94.63832011
#> 4222: 123.75 53.75 11977   102 2.427474e-02 1835.549  44.55748810