You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When passing an sf data.frame to r_to_py(), it is implicitly converted to a non-spatial pandas.DataFrame, and the geometry field is converted to a normal list. This transformation results in the loss of the coordinate reference system (CRS) information, which is crucial for spatial data analysis.
Are there any opportunities to convert sf objects to a geopandas.GeoDataFrame when using r_to_py()?
library(sf)
library(reticulate)
nc<-sf::st_read(system.file("shape/nc.shp", package="sf"))
class(nc)
# [1] "sf" "data.frame"
all(sf::st_is_valid(nc$geometry))
# [1] TRUEnc_py<-reticulate::r_to_py(nc)
class(nc_py)
# [1] "pandas.core.frame.DataFrame" "pandas.core.generic.NDFrame" # [3] "pandas.core.base.PandasObject" "pandas.core.accessor.DirNamesMixin"# [5] "pandas.core.indexing.IndexingMixin" "pandas.core.arraylike.OpsMixin" # [7] "python.builtin.object"
all(sf::st_is_valid(nc_py$geometry))
# Error in UseMethod("st_is_valid") : # no applicable method for 'st_is_valid' applied to an object of class "c('pandas.core.series.Series', 'pandas.core.base.IndexOpsMixin', 'pandas.core.arraylike.OpsMixin', 'pandas.core.generic.NDFrame', 'pandas.core.base.PandasObject', 'pandas.core.accessor.DirNamesMixin', 'pandas.core.indexing.IndexingMixin', 'python.builtin.object')"
Hi, that seems reasonable to me, though I'm not sure if taking a "Suggests" dependency to {sf} in reticulate is prudent. @kevinushey Do you have thoughts?
@philiporlando Would you like to submit a PR adding r_to_py() and py_to_r() methods?
@t-kalinowski, if adding {sf} to "Suggests" isn't an issue, then I can start working on a PR but I may need some additional support throughout the process.
When passing an
sf
data.frame tor_to_py()
, it is implicitly converted to a non-spatialpandas.DataFrame
, and thegeometry
field is converted to a normallist
. This transformation results in the loss of the coordinate reference system (CRS) information, which is crucial for spatial data analysis.Are there any opportunities to convert
sf
objects to ageopandas.GeoDataFrame
when usingr_to_py()
?Here are my session details:
The text was updated successfully, but these errors were encountered: