Skip to content

Visualization functions to accept a path to a .shp file in the 'shapefile' parameter

Hi @abatalla,

As we discussed in the SUNSET dev meeting, currently esviz functions that accept a shapefile parameter (e.g. VizEquiMap) expect the following formats:

A character string of the path to a .rds file or a list object containinig shape file data. 
If it is a .rds file, it should contain a list. 
The list should contains 'x' and 'y' at least, which indicate the location of the shape. 
The default value is NULL.

It would be good if we could expand this to allow the functions to read .shp files directly without the user having to do it beforehand. The functions could check if the parameter shapefile has a .shp extension and use the following piece of code adapted from what we currently have in the SUNSET visualization functions:

shapefile <- sf::read_sf(shapefile)
shapefile <- sp::spTransform(as(shapefile, "Spatial"),
                             CRSobj = CRS("+proj=longlat"))
shapefile <- maps::SpatialPolygons2map(shapefile)

sf and maps are already esviz dependencies, sp would be a new one.

Can you look into this?

Thanks a lot,

Victòria

FYI @nperez