knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width=6, fig.height=4 ) options(scipen = 9999)
This example shows how to
Below the example, all the geometry types that ncdfgeom
handles are shown in detail.
Tables of point, line, or polygon features with associated timeseries are the target for this functionality. Here, we use some sample data from the ncdfgeom
package.
example_file <- tempfile() file.copy(from = system.file('extdata/example_huc_eta.nc', package = 'ncdfgeom'), to = example_file, overwrite = TRUE) -> quiet polygons <- sf::read_sf(system.file('extdata/example_huc_eta.json', package = 'ncdfgeom')) polygons <- dplyr::select(polygons, LOADDATE, AREASQKM, HUC12, NAME) plot(sf::st_geometry(polygons))
Now we have the polygons as shown above and a NetCDF file with a header that looks like:
try({ncdump <- system(paste("ncdump -h", example_file), intern = TRUE) cat(ncdump ,sep = "\n")}, silent = TRUE)
Now we can use the write_geometry
function to add the polygon data to the NetCDF file.
(vars <- ncmeta::nc_vars(example_file)) ncdfgeom::write_geometry(nc_file=example_file, geom_data = polygons, instance_dim_name = "station", variables = vars$name) -> example_file
Now the NetCDF file looks like:
try({ncdump <- system(paste("ncdump -h", example_file), intern = TRUE) cat(ncdump ,sep = "\n")}, silent = TRUE)
Read the polygon data from the file and write it out to a geopackage.
polygons_sf <- ncdfgeom::read_geometry(example_file) plot(sf::st_geometry(polygons_sf)) sf::write_sf(polygons_sf, "polygons.gpkg")
temp <- file.remove(example_file, "polygons.gpkg")
```r
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.