I recently collected data dat, with gps cordinates. Unit of data collection was ward. On ploting I realised that some points are outside the expected wards. There are a number of wards, kindly assist with an R funtion to clip each point based on the ward shapefile
I tried to compare datasets to obtain the points within. the output came as a geometry and could merge on the original csv to obtain the result
Hi Omena Fulu and welcome to Stack Overflow!! You can accomplish the equivalent of an ArcGIS "clip" using the
st_intersection()function in the "sf" package. I have created a reproducible example for you using example datasets available in the "spData" package (see the end). In your case, you will want to first read in the csv using either theread_csv()function or theread.table()function, and then convert the csv into a simple feature dataframe using thest_as_sf()function in the "sf" package. In my example, the "cycle_hires" dataset is a point dataset that would be analogous to your GPS point dataset in the csv. The "lnd" dataset coincidentally also consists of administrative wards in the London Metropolitan area, and should be almost exactly analogous to what you're after. Below is the example: