| sp_left_join | R Documentation | 
sp_left_join tests if a point is within a polygon and joins data from
a spatial object (the data slot of the spatial-polygon data frame) if the 
match is TRUE. This process is analogous to a SQL left join but with
spatial objects. If variable names collide, they will be suffixed with 
"_polygons".
sp_left_join(sp_points, sp_polygons)
sp_points | 
 Spatial points object. Spatial points will usually have a 
data slot but   | 
sp_polygons | 
 Spatial polygons object.   | 
over is used for the point-in-polygon test and the projection systems
must be identical for the two geometries.
A tibble, not a spatial object.
Stuart K. Grange
sp_transform, over, merge,
sp_from_data_frame
## Not run: 
# I am in London, I know my latitude and longitude. Which borough am I in? 
# Load geojson containing the London boroughs
sp_london <- sp_read(
  "http://skgrange.github.io/www/data/london_sport.json",
  verbose = FALSE
) %>% 
  sp_transform()
# Make latitude and longitude a data frame, observation is optional
data_points <- data.frame(
  observation = "current_location",
  latitude = 51.523595, 
  longitude = -0.027114
)
# Promote to spatial points, this will use wgs84 when not stated
sp_points <- sp_from_data_frame(data_points, type = "points")
# Test point with 33 polygons (boroughs) in the shape file
data_point_test <- sp_left_join(sp_points, sp_london)
# Print
data_point_test$name
"Tower Hamlets"
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.