CF_bbox_grid: NetCDF-CF Grid Bounding Box Intersection

Description Usage Arguments Details Value Author(s) Examples

View source: R/CF_bbox_grid.R

Description

This function takes a bounding box in WGS84 lat/lon and the spatial coordinate variable values for a NetCDF-CF grid. It will return a list containing the index positions in the grid that fully contain the requested bounding box and information needed to construct a SpatialPixelsDataFrame to be written to a spatial data format like GeoTiff.

Usage

1
2
CF_bbox_grid(x_vals, y_vals, bbox_in, grid_mapping_name = NULL,
  grid_mapping_atts = NULL)

Arguments

x_vals

A 1d array of the x (or longitude) values of the grid.

y_vals

A 1d array of the y (or latitude) values of the grid.

bbox_in

A four-values vector in the format min lat/lon max lat/lon

grid_mapping_name

The NetCDF-CF Grid Mapping Name if there is one, WGS84 Lat/Lon is assumes given no Grid Mapping.

grid_mapping_atts

A list of attributes of the grid mapping variable as returned by ncdf or ncdf4's get attributes functions.

Details

This function has been tested to work with lat/lon and Lambert Conformal Conic grid mappings. Other grid mappings have not been implemented.

Value

A named list containing the following variables

  1. 'x1'Index position on the x (or longitude) axis for the minimum longitude.

  2. 'y1'Index position on the y (or latitude) axis for the minimum latitude.

  3. 'x2'Index position on the x (or longitude) axis for the maximum latitude.

  4. 'y2'Index position on the y (or latitude) axis for the maximum longitude.

  5. 'coords_master'The coordinates of the subset grid prepared for creation of an sp SpatialPoints object.

  6. 'prj'A proj4 string for the x/y coordinates for use in creating a SpatialPixelsDataFrame.

Author(s)

David Blodgett dblodgett@usgs.gov

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
Using ncdf4 and remote data:

library("ncdf4")
bbox_in <- c(-87,41,-89,43)
OPeNDAP_URI<-"http://cida.usgs.gov/thredds/dodsC/prism"
ncdf4_handle <- nc_open(OPeNDAP_URI)
x_vals<-ncdf4_handle$dim$lon$vals
y_vals<-ncdf4_handle$dim$lat$vals
CF_bbox_grid(x_vals,y_vals,bbox_in)

Using sample data that is projected:

data(CF_bbox_grid_example, package='climates')
bbox_indices<-CF_bbox_grid(x_vals,y_vals,bbox_in,grid_mapping_name,grid_mapping_atts)

## End(Not run)

jjvanderwal/climates documentation built on May 19, 2019, 11:41 a.m.