Generates an S4 SpatialPoints object with defined projection from a data table or matrix including X and Y coordinates, with option to export as an ArcGIS shapefile (*.shp).

spMakeSpatialPoints(
  xyplt,
  xyplt_dsn = NULL,
  xy.uniqueid = NULL,
  xvar = NULL,
  yvar = NULL,
  xy.crs = 4269,
  addxy = FALSE,
  exportsp = FALSE,
  savedata_opts = NULL
)

Arguments

xyplt

Data frame object or String. Name of layer with xy coordinates and unique identifier. Can be layer with xy_dsn, full pathname, including extension, or file name (with extension) in xy_dsn folder.

xyplt_dsn

String. Name of database or folder were xyplt is. The dsn varies by driver. See gdal OGR vector formats (https://www.gdal.org/ogr_formats.html).

xy.uniqueid

String. Unique identifier of xyplt rows.

xvar

String. Name of variable in xyplt defining x coordinate.

yvar

String. Name of variable in xyplt defining y coordinate.

xy.crs

PROJ.4 String or CRS object or Integer EPSG code defining Coordinate Reference System. (e.g., EPSG:4269-Geodetic coordinate system for North America, NAD83).

addxy

Logical. If TRUE, adds x and y variables to spatial sf object.

exportsp

Logical. If TRUE, exports spatial object.

savedata_opts

List. See help(savedata_options()) for a list of options. Only used when exportsp = TRUE.

Value

spplt

sf obect with spatial points and defined CRS.

If exportsp = TRUE, the sf object is written to specified output.

Note

If exportsp=TRUE and a shp output format is specified:
The ESRI shapefile driver truncates variable names to 10 characters or less. Variable names are changed before export using an internal function (trunc10shp). Name changes are output to the outfolder, 'outshpnm'_newnames.csv. The returned Spatial object will have original names, before truncating.

If Spatial object has more than 1 record, it cannot be exported.

Author

Tracey S. Frescino

Examples

# Generate an `sf` points object with `spMakeSpatialPoints` for Wyoming plot
# data, stored in `FIESTA`
spMakeSpatialPoints(xyplt = WYplt, 
                    xy.uniqueid = "CN", 
                    xvar = "LON_PUBLIC", 
                    yvar = "LAT_PUBLIC", 
                    xy.crs = 4269)
#> Simple feature collection with 3047 features and 18 fields
#> Attribute-geometry relationships: identity (18)
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -111.044 ymin: 41.00308 xmax: -104.058 ymax: 44.99897
#> Geodetic CRS:  NAD83
#> First 10 features:
#>                CN INVYR STATECD CYCLE UNITCD COUNTYCD  PLOT MEASYEAR RDDISTCD
#> 1  40404728010690  2013      56     3      2        1 86688     2013       NA
#> 2  40404729010690  2011      56     3      2        1 84596     2011        1
#> 3  40404730010690  2013      56     3      2        1 88993     2013        6
#> 4  40404731010690  2012      56     3      2        1 82340     2012       NA
#> 5  40404733010690  2012      56     3      2        1 82869     2012       NA
#> 6  40404734010690  2013      56     3      2        1 83304     2013       NA
#> 7  40404735010690  2011      56     3      2        1 86847     2011       NA
#> 8  40404736010690  2013      56     3      2        1 88035     2013       NA
#> 9  40404737010690  2011      56     3      2        1 81546     2011        3
#> 10 40404738010690  2013      56     3      2        1 90467     2013        6
#>    NF_SAMPLING_STATUS_CD PLOT_STATUS_CD NF_PLOT_STATUS_CD NBRCND NBRCNDSAMP
#> 1                      0              2                NA      1          1
#> 2                      0              1                NA      1          1
#> 3                      0              1                NA      1          1
#> 4                      0              2                NA      1          1
#> 5                      0              2                NA      1          1
#> 6                      0              2                NA      1          1
#> 7                      0              2                NA      1          1
#> 8                      0              2                NA      1          1
#> 9                      0              1                NA      2          2
#> 10                     0              1                NA      1          1
#>    NBRCNDFOR CCLIVEPLT        FORNONSAMP        PLOT_ID
#> 1          0         0 Sampled-Nonforest ID560200186688
#> 2          1        17    Sampled-Forest ID560200184596
#> 3          1        41    Sampled-Forest ID560200188993
#> 4          0         0 Sampled-Nonforest ID560200182340
#> 5          0         0 Sampled-Nonforest ID560200182869
#> 6          0         0 Sampled-Nonforest ID560200183304
#> 7          0         0 Sampled-Nonforest ID560200186847
#> 8          0         6 Sampled-Nonforest ID560200188035
#> 9          1         7    Sampled-Forest ID560200181546
#> 10         1        17    Sampled-Forest ID560200190467
#>                      geometry
#> 1  POINT (-105.9625 42.41013)
#> 2  POINT (-105.7277 42.40928)
#> 3  POINT (-105.6679 42.40953)
#> 4  POINT (-106.0313 42.35599)
#> 5  POINT (-105.8509 42.31655)
#> 6  POINT (-106.0363 42.26546)
#> 7  POINT (-105.9092 42.26803)
#> 8  POINT (-105.8607 42.27953)
#> 9  POINT (-105.6062 42.27355)
#> 10 POINT (-105.5466 42.27137)