# Figuring out coordinates of a line in a shapefile

I am working with a shapefile in R that is made up of 48 polygons. It is a map of Sweden with a line plotted to denote a biological boundary between north and south. I want to figure out the latitude of the line (see plot) but I cannot figure out how to extract that information from the shapefile.

I am wondering how to go about this. Can I plot each polygon separately to see if one/multiple polygons make up this line?

## 1 Answer

With the `sf` package you can very easily iterate over the geometries:

``````gadm <- raster::getData("GADM", country="SWE", level=1)

library("sf")
sf_geom <- st_geometry(st_as_sf(gadm))
# use st_read instead of st_as_sf to read the shapefile

for(i in seq_along(sf_geom)) {
plot(sf_geom[i], main=i, axes=TRUE)
Sys.sleep(1)
}
``````
• OK thanks. I have managed to parse out each polygon's geometry using the st_geometry function. Now, I am interested in seeing whether a set of coordinates lies in one particular polygon. I was using the over() function before to check if SpatialPoints lie within a SpatialPolygon but that does not work anymore since st_geometry is now a geometry set. See code: LC2 <- SpatialPoints(LC[,1:2]) proj4string(LC2) <- proj4string(map_wgs84) map2 <- as(map_wgs84, "SpatialPolygons") inside <- !is.na(over(LC2, map2)) Feb 24, 2017 at 15:52
• Nevermind! solved. Thanks for your help. LC2 <- SpatialPoints(LC[,1:2]) proj4string(LC2) <- proj4string(map_wgs84) map2 <- as(map_wgs84, "SpatialPolygons") inside <- !is.na(over(LC2, map2[46])) Feb 24, 2017 at 16:15