GeoDaCenter / rgeoda

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

sf_to_geoda removes all columns from sf object #1

Closed angela-li closed 3 years ago

angela-li commented 4 years ago

When you try to convert an sf object to a geoda object, it removes all the columns of the sf object.

I'm using the guerry sf object from the teaching geodaData package here.

library(geodaData)
library(rgeoda)
guerry_sf <- geodaData::guerry
guerry_geoda <- rgeoda::sf_to_geoda(guerry_sf)
#> Loading required package: sf
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
#> Loading required package: wkb
guerry_geoda
#> Reference class object of class "geoda"
#> Field "gda":
#> An object of class "_p_GeoDa"
#> Slot "ref":
#> <pointer: 0x7fcbfbf7c810>
#> 
#> Field "map_type":
#> [1] "polygon_type"
#> Field "n_cols":
#> [1] 0
#> Field "n_obs":
#> [1] 85
#> Field "field_names":
#> character(0)
#> Field "field_types":
#> character(0)
#> Field "table":
#> data frame with 0 columns and 85 rows
angela-li commented 4 years ago

Hm, I realize that the default is with_table = FALSE, which is why this is happening. I'm wondering if it would make more sense to set it to TRUE, so people don't think it's an error when they read in their data...

lixun910 commented 4 years ago

Sounds good. I didn’t think about it from a user perspective. Will change it to True by default.

FYI I did it on purpose: 1. when you have an sf object with table data, rgeoda can be created with only geometries for weights creation, and one can always pass the table data (tuple or vector) directly from sf to rgeoda function (see the example of rgeoda+sf). 2. copy the existing table from sf to rgeoda will take some time especially when you have a big table. 3. When you use rgeoda to load data (eg assume no sf) it will create a table by default.

Thanks!

On Tue, Nov 19, 2019 at 8:55 AM Angela Li notifications@github.com wrote:

Hm, I realize that the default is with_table = FALSE, which is why this is happening. I'm wondering if it would make more sense to set it to TRUE, so people don't think it's an error when they read in their data...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lixun910/rgeoda/issues/1?email_source=notifications&email_token=AASPYTZ3QY3NNE2UFP6MMC3QUQD7VA5CNFSM4JPFJ7EKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEOVXTI#issuecomment-555572173, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASPYT45LJCINDNHJVDGLK3QUQD7VANCNFSM4JPFJ7EA .