R/spGetStrata.R
spGetStrata.Rd
Wrapper to extract attribute and area from a polygon or raster estimation unit layer and a polygon or raster layer with strata pixel categories.
spGetStrata(
xyplt,
xyplt_dsn = NULL,
unit_layer,
unit_dsn = NULL,
uniqueid = "PLT_CN",
unitvar = NULL,
unitvar2 = NULL,
unit.filter = NULL,
strattype = "RASTER",
strat_layer = NULL,
strat_dsn = NULL,
strvar = NULL,
strat_lut = NULL,
areaunits = "acres",
rast.NODATA = NULL,
keepNA = FALSE,
ncores = 1,
showext = FALSE,
returnxy = FALSE,
savedata = FALSE,
exportsp = FALSE,
exportNA = FALSE,
spMakeSpatial_opts = NULL,
savedata_opts = NULL,
vars2keep = NULL,
gui = FALSE
)
Data frame, sf object, full pathname to *.csv or *shp, or layer name in a geodatabase. Includes XY coordinates and unique identifier. If non-spatial, include options in spMakeSpatial_opts parameter.
String. Name of database where xyplt is. The dsn varies by driver. See gdal OGR vector formats (https://www.gdal.org/ogr_formats.html).
sf R object or String. Name of estimation unit spatial layer. Can be a spatial polygon object, full pathname to a shapefile, name of a polygon layer within a database, or a full pathname to raster file.
String. Data source name (dsn; e.g., sqlite or shapefile pathname) of unit_layer. The dsn varies by driver. See gdal OGR vector formats (https://www.gdal.org/ogr_formats.html). Optional if unit_layer is sf object.
String.* Unique identifier of xyplt records. Note: raster unit layers are converted to polygon.
String. If unittype="POLY", name of attribute in unit_layer defining estimation units. If NULL, the unit_layer represents one estimation unit.
String. If unittype="POLY", name of attribute in unit_layer defining a second, hierarchical larger, estimation unit (e.g., Statecd).
String. Filter to subset unit_layer spatial layer.
String. Spatial layer type of strat_layer ("POLY", "RASTER"). Note: polygon strata layers are converted to raster.
sf R object or full pathname of spatial stratification layer. Can be a spatial polygon object, full pathname to a shapefile, name of a polygon layer within a database, or a full pathname to raster file.
String. Data source name (dsn; e.g., sqlite or shapefile pathname) of strat_layer. The dsn varies by driver. See gdal OGR vector formats (https://www.gdal.org/ogr_formats.html). Optional if unit_layer is sf object.
String. If strattype="POLY", name of strata attribute in strat_layer.
Data frame. A look-up table of codes to aggregate. The format of table includes 2 columns, one column same name as strvar. If strattype="RASTER", strvar="value".
String. Output area units ("acres", "hectares", "sqmeters").
Numeric. NODATA value if stratlayer is raster (See notes). This values will be converted to NA and removed from output. if keepNA=TRUE, NA values will not be in included in stratalut but will remain in pltassgn table.
Logical. If TRUE, returns data frame of NA values.
Integer. Number of cores to use for extracting values.
Logical. If TRUE, layer extents are displayed in plot window.
Logical. If TRUE, returns xy data as sf object (spxyplt).
Logical. If TRUE, the input data with extracted values are saved to outfolder.
Logical. If savedata=TRUE and returnxy=TRUE, If TRUE, the extracted strata point data are exported to outfolder.
Logical. If TRUE and keepNA=TRUE, NA values are exported to outfolder as a point shapefile.
List. See help(spMakeSpatial_options()) for a list of options. Use to convert X/Y values to simple feature (sf) coordinates.
List. See help(savedata_options()) for a list of options. Only used when savedata = TRUE.
String vector. Attributes in SAdoms, other than domvar to include in dunitlut output and extract to pltassgn points.
Logical. If gui, user is prompted for parameters.
Data frame. Input xyplt data with extracted estimation unit and strata values appended.
Data frame. Area by estimation unit.
Data frame. Variable name for estimation unit in unitarea.
Data frame. Variable name for area in unitarea.
Data frame. Strata proportions (weights) by estimation unit and strata.
Data frame. Variable name for strata values in stratalut.
sf List. If keepNA=TRUE, and NA values exist after data extraction, the spatial NA points are returned.
String. Unique identifier of plot.
Simple feature. If returnxy=TRUE, Spatial coordinates.
String. If returnxy=TRUE, unique identifier of spxy.
If savedata=TRUE, pltassgn and unitarea are saved to outfolder.
If
exportsp=TRUE, the spatial sf points object is exported to outfolder.
.
If exportNA=TRUE and NA values exist after data extraction, the spatial NA
points are exported to outfolder.
*If variable = NULL, then it will prompt user for input.
If spatial layers have different projections, the polygon spatial layer is transformed to the projection of raster (See note about on-the-fly projection conversion). If both layers are long/lat coordinate system, they are transformed to default coordinate system (Conus Albers, NAD83).
rast.NODATA
NODATA values are raster pixel values that have no data of
interest, including pixels within the extent of the layer, but outside the
area of interest. Sometimes these pixels have been defined previously. The
defined NODATA pixels are imported to R as NULL values. When not previously
defined, the pixels outside the area of interest will be the minimum or
maximum value depending on the data type (e.g., 16-bit signed: min=-32,768;
max=32,768) or byte size (1 byte: min=0; max=255). These NODATA values will
be added to the zonal statistic calculations if not specified in
rast.NODATA.
If exportsp=TRUE:
If out_fmt="shp", the st_write (sf) function is
called. The ArcGIS driver truncates variable names to 10 characters or less.
Variable names are changed before export using an internal function
(trunc10shp). If Spatial object has more than 1 record, it will be returned
but not exported.
On-the-fly projection conversion
The spTransform (sf) method is used
for on-the-fly map projection conversion and datum transformation using
PROJ.4 arguments. Datum transformation only occurs if the +datum tag is
present in the both the from and to PROJ.4 strings. The +towgs84 tag is used
when no datum transformation is needed. PROJ.4 transformations assume NAD83
and WGS84 are identical unless other transformation parameters are
specified. Be aware, providing inaccurate or incomplete CRS information may
lead to erroneous data shifts when reprojecting. See spTransform help
documentation for more details.
unitarea
Area by estimation unit is calculated and returned as object
named unitarea. Area is based on the projection of unit_layer. If no
unit_layer input, than area is calculated from pixel counts.
polygon to raster
If strattype="POLY", a raster template is created based
on the masked extent of strat_layer, with strat_layer projected coordinate
system and 30 meter pixel size.
# Create a `SpatialPoints` object from `WYplt`
WYspplt <- spMakeSpatialPoints(xyplt = WYplt,
xy.uniqueid = "CN",
xvar = "LON_PUBLIC",
yvar = "LAT_PUBLIC",
xy.crs = 4269)
# Set up stratification from object in `FIESTA`
fornffn <- system.file("extdata",
"sp_data/WYbighorn_forest_nonforest_250m.tif",
package = "FIESTA")
# Set up data from FIESTA
WYbhfn <- system.file("extdata",
"sp_data/WYbighorn_adminbnd.shp",
package = "FIESTA")
# Run `spGetStrata`
spGetStrata(WYspplt,
uniqueid = "CN",
unit_layer = WYbhfn,
strattype = "RASTER",
strat_layer = fornffn)
#> /private/var/folders/kd/4wp69y7d2yd3fxpd1_m64clm0000gn/T/RtmpWUzLtI/temp_libpath10a93f405e55/FIESTA/extdata/sp_data/WYbighorn_forest_nonforest_250m.tif
#> reprojecting layer...
#> from: NAD83
#> to: PROJCS["unnamed",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["latitude_of_center",23],PARAMETER["longitude_of_center",-96],PARAMETER["standard_parallel_1",29.5],PARAMETER["standard_parallel_2",45.5],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]]
#> reprojecting layer...
#> from: EPSG:4269
#> to: PROJCS["unnamed",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["latitude_of_center",23],PARAMETER["longitude_of_center",-96],PARAMETER["standard_parallel_1",29.5],PARAMETER["standard_parallel_2",45.5],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]]
#> Warning: there are 2991 null values for poly1
#> ================================================================================
#> /private/var/folders/kd/4wp69y7d2yd3fxpd1_m64clm0000gn/T/RtmpWUzLtI/temp_libpath10a93f405e55/FIESTA/extdata/sp_data/WYbighorn_forest_nonforest_250m.tif
#> rasterfile
#> <char>
#> 1: /private/var/folders/kd/4wp69y7d2yd3fxpd1_m64clm0000gn/T/RtmpWUzLtI/temp_libpath10a93f405e55/FIESTA/extdata/sp_data/WYbighorn_forest_nonforest_250m.tif
#> band var.name interpolate windowsize statistic rast.NODATA
#> <int> <char> <lgcl> <num> <char> <lgcl>
#> 1: 1 value FALSE 1 none NA
#> extracting point values from WYbighorn_forest_nonforest_250m ...
#> $bnd
#> Simple feature collection with 1 feature and 12 fields
#> Geometry type: POLYGON
#> Dimension: XY
#> Bounding box: xmin: -108.0056 ymin: 44.0199 xmax: -106.8407 ymax: 45.0011
#> Geodetic CRS: NAD83
#> OBJECTID ADMINFORES REV_DATE DATA_SOURC ACCURACY REGION FORESTNUMB
#> 1 6 99020200010343 2012/01/20 09 0 02 02
#> FORESTNAME GIS_ACRES Shape_Leng Shape_Area
#> 1 Bighorn National Forest 1112790 4.942746 0.5097936
#> geometry ONEUNIT
#> 1 POLYGON ((-107.8489 45.0007... 1
#>
#> $pltassgn
#> CN INVYR STATECD CYCLE UNITCD COUNTYCD PLOT MEASYEAR RDDISTCD
#> 1 40404876010690 2012 56 3 2 3 83143 2012 6
#> 2 40404879010690 2011 56 3 2 3 80153 2011 6
#> 3 40404886010690 2012 56 3 2 3 86397 2012 NA
#> 4 40404893010690 2011 56 3 2 3 85901 2011 4
#> 5 40404894010690 2013 56 3 2 3 90221 2013 6
#> 6 40404899010690 2013 56 3 2 3 85144 2013 NA
#> 7 40404903010690 2012 56 3 2 3 80353 2012 NA
#> 8 40404916010690 2011 56 3 2 3 85420 2011 NA
#> 9 40404921010690 2013 56 3 2 3 85403 2013 NA
#> 10 40404925010690 2012 56 3 2 3 87744 2012 3
#> 11 40404930010690 2012 56 3 2 3 89093 2012 8
#> 12 40404939010690 2012 56 3 2 3 86981 2012 6
#> 13 40404940010690 2013 56 3 2 3 85570 2013 8
#> 14 40404944010690 2011 56 3 2 3 83813 2011 7
#> 15 40404948010690 2012 56 3 2 3 81093 2012 NA
#> 16 40404966010690 2013 56 3 2 3 84998 2013 NA
#> 17 40406042010690 2012 56 3 2 19 80535 2012 8
#> 18 40406044010690 2013 56 3 2 19 80030 2013 7
#> 19 40406045010690 2012 56 3 2 19 80759 2012 8
#> 20 40406047010690 2011 56 3 2 19 89515 2011 8
#> 21 40406048010690 2013 56 3 2 19 88335 2013 9
#> 22 40406049010690 2013 56 3 2 19 80173 2013 7
#> 23 40406053010690 2012 56 3 2 19 83314 2012 NA
#> 24 40406059010690 2012 56 3 2 19 81895 2012 7
#> 25 40406064010690 2011 56 3 2 19 81451 2011 7
#> 26 40406065010690 2013 56 3 2 19 81022 2013 NA
#> 27 40406069010690 2013 56 3 2 19 87377 2013 NA
#> 28 40406070010690 2011 56 3 2 19 84586 2011 4
#> 29 40406075010690 2012 56 3 2 19 86816 2012 NA
#> 30 40406081010690 2011 56 3 2 19 85278 2011 NA
#> 31 40406082010690 2012 56 3 2 19 87848 2012 3
#> 32 40406085010690 2011 56 3 2 19 87610 2011 NA
#> 33 40406086010690 2013 56 3 2 19 84201 2013 1
#> 34 40406090010690 2013 56 3 2 19 90267 2013 5
#> 35 40406947010690 2011 56 3 2 33 88166 2011 6
#> 36 40406948010690 2013 56 3 2 33 82099 2013 8
#> 37 40406952010690 2012 56 3 2 33 82446 2012 7
#> 38 40406961010690 2012 56 3 2 33 87062 2012 9
#> 39 40406970010690 2011 56 3 2 33 90061 2011 NA
#> 40 40406976010690 2011 56 3 2 33 88839 2011 5
#> 41 40406977010690 2013 56 3 2 33 89495 2013 NA
#> 42 40406978010690 2011 56 3 2 33 86120 2011 5
#> 43 40406986010690 2013 56 3 2 33 89028 2013 5
#> 44 40406999010690 2011 56 3 2 33 87457 2011 5
#> 45 40407000010690 2012 56 3 2 33 89767 2012 NA
#> 46 40407005010690 2011 56 3 2 33 90348 2011 7
#> 47 40407006010690 2013 56 3 2 33 88657 2013 5
#> 48 40407012010690 2011 56 3 2 33 87586 2011 4
#> 49 40407013010690 2013 56 3 2 33 85208 2013 6
#> 50 40407022010690 2013 56 3 2 33 89414 2013 7
#> 51 40407024010690 2012 56 3 2 33 84145 2012 5
#> 52 40407027010690 2013 56 3 2 33 88483 2013 8
#> 53 40407029010690 2012 56 3 2 33 83085 2012 7
#> 54 40407733010690 2011 56 3 2 43 87298 2011 NA
#> 55 40407737010690 2012 56 3 2 43 85461 2012 7
#> 56 40407743010690 2012 56 3 2 43 89052 2012 NA
#> NF_SAMPLING_STATUS_CD PLOT_STATUS_CD NF_PLOT_STATUS_CD NBRCND NBRCNDSAMP
#> 1 0 1 NA 2 2
#> 2 0 1 NA 1 1
#> 3 0 2 NA 1 1
#> 4 0 1 NA 1 1
#> 5 0 1 NA 1 1
#> 6 0 2 NA 1 1
#> 7 0 2 NA 1 1
#> 8 0 2 NA 1 1
#> 9 0 2 NA 1 1
#> 10 0 1 NA 1 1
#> 11 0 1 NA 1 1
#> 12 0 1 NA 2 2
#> 13 0 1 NA 1 1
#> 14 0 2 NA 2 2
#> 15 0 2 NA 1 1
#> 16 0 2 NA 1 1
#> 17 0 1 NA 1 1
#> 18 0 1 NA 2 2
#> 19 0 1 NA 1 1
#> 20 0 1 NA 2 2
#> 21 0 1 NA 1 1
#> 22 0 1 NA 1 1
#> 23 0 2 NA 1 1
#> 24 0 1 NA 1 1
#> 25 0 1 NA 1 1
#> 26 0 2 NA 1 1
#> 27 0 2 NA 1 1
#> 28 0 1 NA 1 1
#> 29 0 2 NA 1 1
#> 30 0 2 NA 1 1
#> 31 0 1 NA 2 2
#> 32 0 2 NA 1 1
#> 33 0 1 NA 2 2
#> 34 0 1 NA 1 1
#> 35 0 1 NA 3 2
#> 36 0 1 NA 1 1
#> 37 0 1 NA 1 1
#> 38 0 1 NA 1 1
#> 39 0 2 NA 1 1
#> 40 0 1 NA 1 1
#> 41 0 2 NA 1 1
#> 42 0 1 NA 1 1
#> 43 0 1 NA 1 1
#> 44 0 1 NA 1 1
#> 45 0 2 NA 1 1
#> 46 0 1 NA 1 1
#> 47 0 1 NA 1 1
#> 48 0 1 NA 1 1
#> 49 0 1 NA 1 1
#> 50 0 1 NA 1 1
#> 51 0 1 NA 2 2
#> 52 0 1 NA 1 1
#> 53 0 1 NA 2 2
#> 54 0 2 NA 1 1
#> 55 0 1 NA 1 1
#> 56 0 2 NA 1 1
#> NBRCNDFOR CCLIVEPLT FORNONSAMP PLOT_ID ONEUNIT STRATUMCD
#> 1 2 67.50 Sampled-Forest ID560200383143 1 1
#> 2 1 66.00 Sampled-Forest ID560200380153 1 1
#> 3 0 0.00 Sampled-Nonforest ID560200386397 1 2
#> 4 1 48.00 Sampled-Forest ID560200385901 1 2
#> 5 1 2.00 Sampled-Forest ID560200390221 1 2
#> 6 0 8.00 Sampled-Nonforest ID560200385144 1 2
#> 7 0 1.00 Sampled-Nonforest ID560200380353 1 2
#> 8 0 10.00 Sampled-Nonforest ID560200385420 1 2
#> 9 0 0.00 Sampled-Nonforest ID560200385403 1 1
#> 10 1 36.00 Sampled-Forest ID560200387744 1 2
#> 11 1 45.00 Sampled-Forest ID560200389093 1 1
#> 12 1 54.00 Sampled-Forest ID560200386981 1 1
#> 13 1 52.00 Sampled-Forest ID560200385570 1 1
#> 14 0 3.75 Sampled-Nonforest ID560200383813 1 1
#> 15 0 0.00 Sampled-Nonforest ID560200381093 1 1
#> 16 0 0.00 Sampled-Nonforest ID560200384998 1 2
#> 17 1 56.00 Sampled-Forest ID560201980535 1 1
#> 18 2 54.50 Sampled-Forest ID560201980030 1 1
#> 19 1 54.00 Sampled-Forest ID560201980759 1 1
#> 20 1 12.50 Sampled-Forest ID560201989515 1 1
#> 21 1 65.00 Sampled-Forest ID560201988335 1 1
#> 22 1 57.00 Sampled-Forest ID560201980173 1 1
#> 23 0 0.00 Sampled-Nonforest ID560201983314 1 2
#> 24 1 37.00 Sampled-Forest ID560201981895 1 1
#> 25 1 38.00 Sampled-Forest ID560201981451 1 1
#> 26 0 0.00 Sampled-Nonforest ID560201981022 1 2
#> 27 0 0.00 Sampled-Nonforest ID560201987377 1 2
#> 28 1 67.00 Sampled-Forest ID560201984586 1 1
#> 29 0 0.00 Sampled-Nonforest ID560201986816 1 2
#> 30 0 0.00 Sampled-Nonforest ID560201985278 1 2
#> 31 1 20.50 Sampled-Forest ID560201987848 1 1
#> 32 0 1.00 Sampled-Nonforest ID560201987610 1 1
#> 33 1 18.50 Sampled-Forest ID560201984201 1 1
#> 34 1 54.00 Sampled-Forest ID560201990267 1 1
#> 35 1 14.00 Sampled-Forest ID560203388166 1 1
#> 36 1 51.00 Sampled-Forest ID560203382099 1 1
#> 37 1 32.00 Sampled-Forest ID560203382446 1 1
#> 38 1 28.00 Sampled-Forest ID560203387062 1 1
#> 39 0 3.00 Sampled-Nonforest ID560203390061 1 1
#> 40 1 28.00 Sampled-Forest ID560203388839 1 1
#> 41 0 0.00 Sampled-Nonforest ID560203389495 1 1
#> 42 1 53.00 Sampled-Forest ID560203386120 1 1
#> 43 1 49.00 Sampled-Forest ID560203389028 1 1
#> 44 1 67.00 Sampled-Forest ID560203387457 1 1
#> 45 0 2.00 Sampled-Nonforest ID560203389767 1 1
#> 46 1 59.00 Sampled-Forest ID560203390348 1 1
#> 47 1 31.00 Sampled-Forest ID560203388657 1 2
#> 48 1 50.00 Sampled-Forest ID560203387586 1 1
#> 49 1 2.00 Sampled-Forest ID560203385208 1 1
#> 50 1 55.00 Sampled-Forest ID560203389414 1 1
#> 51 2 59.75 Sampled-Forest ID560203384145 1 1
#> 52 1 53.00 Sampled-Forest ID560203388483 1 1
#> 53 1 12.50 Sampled-Forest ID560203383085 1 1
#> 54 0 0.00 Sampled-Nonforest ID560204387298 1 1
#> 55 1 73.00 Sampled-Forest ID560204385461 1 1
#> 56 0 0.00 Sampled-Nonforest ID560204389052 1 2
#>
#> $pltassgnid
#> [1] "CN"
#>
#> $unitarea
#> ONEUNIT ACRES_GIS
#> 1 1 1112401
#>
#> $unitvar
#> [1] "ONEUNIT"
#>
#> $unitvar2
#> NULL
#>
#> $areavar
#> [1] "ACRES_GIS"
#>
#> $areaunits
#> [1] "ACRES"
#>
#> $stratalut
#> ONEUNIT STRATUMCD P2POINTCNT strwt
#> 1 1 1 52289 0.7260344
#> 2 1 2 19731 0.2739656
#>
#> $strvar
#> [1] "STRATUMCD"
#>
#> $getwt
#> [1] FALSE
#>
#> $strwtvar
#> [1] "strwt"
#>