spatial_join: Spatial join a data frame to polygons

Description Usage Arguments Examples

Description

Imports a shp file and a data frame loaded into R, and does a spatial join between the points in the data frame and polygons in the shapefile

Usage

1
2
3
spatial_join(shp, df, proj_crs, lat_var = "lat", lon_var = "lon",
  df_crs = "+proj=longlat +datum=WGS84 +no_defs", binary_var = "inPolygon",
  merge2shp = TRUE, plot_results = TRUE)

Arguments

shp

either a shapefile file location, or a spatial data frame imported using sf::st_read

df

data frame containing latitudes and longtitudes of the points to spatially join to 'shp'. Assumes the data are organized in a data frame containing columns lat_var and lon_var

proj_crs

PROJ4 string specifying the desired projection to use in spatial join. For help choosing projection see http://projectionwizard.org/

lat_var

string specifying column in 'df' that contains the latitude coordinates.

lon_var

string specifying column in 'df' that contains the longitude coordinates.

df_crs

PROJ4 string specifying the coordinate reference system for 'df'. Assumed to be WGS84 if not specified.

binary_var

string specifiying the name of a new binary variable created in the output for whether the point is within any polygon in 'shp' or not

merge2shp

TRUE/FALSE if 'df' should be merged with the contents of 'shp'

plot_results

TRUE/FALSE if a leaflet map of the join should be plotted

Examples

1
2
n = 2000
df = data.frame(lon = sample(round(32.67152*100):round(35.91505*100), n, replace = TRUE)/100, lat = sample(round(-17.12721*100):round(-13.34228*100), n, replace = TRUE)/100)

flaneuse/geocenter documentation built on May 16, 2019, 1:18 p.m.