nightlight_apply: Apply a function to each geometric object

Description Usage Arguments Examples

Description

nightlight_apply applies a function over each geometric object in geom for each year of nightlight data in nightlight_data

Usage

1
nightlight_apply(nightlight_data, geom, func, ...)

Arguments

nightlight_data

source path where nightlight data was downloaded

geom

geometric object

func

function to apply

...

arguments passed to func

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
library(nightlight)

set the root folder for where you want to download the dataset
NOAA_DATASET_ROOT <- "~/datasets/noaa"

nightlight_download(NOAA_DATASET_ROOT)

nightlight_data <- nightlight_load(NOAA_DATASET_ROOT)

create a polygon for testing
coordinates <- matrix(
  c(
    113.4789, 22.19556,
    113.4811, 22.21748,
    113.4941, 22.24155,
    113.5271, 22.24595,
    113.5481, 22.22261,
    113.5455, 22.22148,
    113.4988, 22.20166,
    113.4842, 22.19775,
    113.4789, 22.19556
  ),
  ncol = 2,
  byrow = TRUE
)
polygon <- Polygon(coordinates)

spatial_polygons <- SpatialPolygons(list(Polygons(list(polygon),1)))

results <- nightlight_apply(nightlight_data, c(spatial_polygons), mean, na.rm = TRUE)

print(results)

altaf-ali/nightlight documentation built on May 11, 2019, 11:29 p.m.