Description Usage Arguments Details Value Author(s) Examples
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.
1 2 | CF_bbox_grid(x_vals, y_vals, bbox_in, grid_mapping_name = NULL,
grid_mapping_atts = NULL)
|
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. |
This function has been tested to work with lat/lon and Lambert Conformal Conic grid mappings. Other grid mappings have not been implemented.
A named list containing the following variables
'x1'Index position on the x (or longitude) axis for the minimum longitude.
'y1'Index position on the y (or latitude) axis for the minimum latitude.
'x2'Index position on the x (or longitude) axis for the maximum latitude.
'y2'Index position on the y (or latitude) axis for the maximum longitude.
'coords_master'The coordinates of the subset grid prepared for creation of an sp SpatialPoints object.
'prj'A proj4 string for the x/y coordinates for use in creating a SpatialPixelsDataFrame.
David Blodgett dblodgett@usgs.gov
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.