GeoDaCenter / rgeoda

R library for spatial data analysis based on libgeoda and GeoDa
70 stars 13 forks source link

make sf_to_geoda and sp_to_geoda R friendly #10

Closed lanselin closed 3 years ago

lanselin commented 3 years ago

The functions sf_to_geoda and sp_to_geoda should become generic as.geoda( ) functions to which either an sf or an sp objects can be passed. So, the type of object passed needs to be detected by the function and then it works seamlessly to create a geoda object. For example, see as.ppp in spatstat.

Ideally, there should also be a geoda method added to as.sf and as.sp.

lixun910 commented 3 years ago

Added as.geoda() function in rgeoda. Users can pass either an 'sf' object or 'sp' object. For example:

library(sf)
library(rgeoda)

# load file using sf
guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda")
guerry_sf <- st_read(guerry_path)

# using sf object (geometries) to create a geoda object
guerry_gda <- as.geoda(guerry_sf)

or

library(rgdal)
library(rgeoda)

# load file using sp
guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda")
guerry_sp <- readOGR(guerry_path)

# using sp object (geometries) to create a geoda object
guerry_gda <- as.geoda(guerry_sp)