Exporting lconnect outputs as shapefiles

Recently I was approached by someone using our lconnect R package for teaching, which is great! Just a quick reminder: this is a very simple R package I created with Bruno Silva, that computes patch connectivity metrics and assesses habitat patch importance in a given landscape.

This lconnect user requested something that was a really good idea, and I can’t believe we haven’t thought about it: Exporting the connect outputs as shapefiles. I devised a simple workaround (maybe in a later version we will create a function for this…).

So… let’s start! We can use the sample code and data:

library(lconnect)
library(sf)

#Load data
vec_path <- system.file("extdata/vec_projected.shp", package = "lconnect")
landscape <- upload_land(vec_path, bound_path = NULL, habitat = 1, max_dist = 500)

Having the data on the landscape, we can derive the patch importance:

#Deriving patch importance
importance <- patch_imp(landscape, metric = "IIC")

We can plot both, the landscape and the importance:

plot(landscape)
plot(importance)

The landscape created above is of class “connect”. We can check this by doing:

class(landscape)

But this object is based upon the “sf” class, of the package sf. We can check this by doing:

class(landscape$landscape)

The patch importance output is of class “pimp”, but also based upon the “sf” class:

class(importance)
class(importance$landscape)

So, to save these outputs as shapefiles we can use the functions of the sf package:

st_write(landscape$landscape, “landscape.shp”)
st_write(importance$landscape, “importance.shp”)

I hope this has been useful!

One thought on “Exporting lconnect outputs as shapefiles

  1. Pingback: Just out! Paper describing the lconnect R package – Geekcologist

Leave a comment