I have 2 shapefiles, one of them has the coordinates of administrative units as a multipolygon, and the other has the coordinates of various sections of a border wall as a multilinestring. I am trying to match the sections of the border wall to their respective administrative units in R.
I started by importing the shapefiles:
rm(list = ls())
# Load necessary packages
install.packages("sf")
install.packages("dplyr")
library(sf)
library(dplyr)
install.packages("readstata13")
library(readstata13)
library(haven)
library(foreign)
setwd("C:/Desktop/Wall")
latlong_data14 <- st_read("Barrier_Sept_2014.shp")
setwd("C:/Desktop/Admin")
admin <- st_read("geo1_ps1997_2017.shp")
latlong_data14 looks something like this:
Shape_Leng | geometry |
---|---|
1900.11 | MULTILINESTRING(74850…) |
2109.13 | MULTILINESTRING(69375…) |
and admin looks like:
ADMIN_NAME | geometry |
---|---|
Unit A | MULTIPOLYGON(36.587…) |
Unit B | MULTIPOLYGON(37.095…) |
I would like to append a column to latlong_data14 with the administrative unit name, but I’m not sure how to do this. Note: it’s possible that some observations span multiple administrative units, but I’m not sure. In that case, is it possible for each observation to break down how much of the shape length belongs to each administrative unit?
user24939654 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.