0

I have a dataframe that shows bus stop locations in Glasgow and another dataframe that shows Datazone polygons for Glasgow. I am using the sf package and have made both dataframes spatial. I want to do a spatial join to create a new dataframe (joined_ds) to match each bus stop location to a Datazone polygon and its associated characteristics (deprivation score). I'm using st_intersection which gives me a new dataframe with all the correct columns but 0 observations.

joined_ds <- st_intersection(st_buffer(bus_stop_data,0), st_buffer(datazones,0))

Both datasets are using the appropriate CRS (EPSG: 27700 for the British National Grid) and I know that the points and polygons overlap because I have successfully plotted them on a map using ggplot, so no idea why my dataframe is showing 0 obs. I've also tried loading in the datasets from scratch and no luck.

Any suggestions welcome, thanks!

KS100
  • 3
  • 3

1 Answers1

0

Look at the differences between st_intersection and st_intersectshere:

Why use st_intersection rather than st_intersects?

Since you are only interested if a point intersects with a polygon, you need st_intersects. If I understand you correctly you don't need to use st_buffer but simply use st_join in combination with st_intersects. Something like:

st_join(bus_stop_data, datazones, join = st_intersects)

Keep in mind issues that might arise when using spatial joins, for example when a point intersects with two polygons.

maarvd
  • 1,254
  • 1
  • 4
  • 14