-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clean_names.sf()
does not recognize SHAPE
column as a sfc
column when it contains multiple Geometry Types
#578
Comments
I think that is readily possible. Can you please provide a small file as a reproducible example? |
I was apparently not entirely correct. The problem (to my understanding so far) is not about the name of the sfc_GEOMETRY column ( But from what I just found out, it might have been because the This is the code: library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(readr)
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
library(janitor)
#>
#> Attaching package: 'janitor'
#> The following objects are masked from 'package:stats':
#>
#> chisq.test, fisher.test
projects <- readr::read_rds("D:/Projects.rds")
st_geometry_type(projects)
#> [1] MULTILINESTRING MULTILINESTRING MULTIPOINT MULTIPOINT
#> [5] MULTILINESTRING MULTILINESTRING MULTIPOINT MULTIPOINT
#> [9] MULTILINESTRING MULTILINESTRING
#> 18 Levels: GEOMETRY POINT LINESTRING POLYGON MULTIPOINT ... TRIANGLE
projects_shape <- projects %>%
janitor::clean_names()
View(projects_shape) # Does not work
project_shape_transformed <- projects_shape %>%
sf::st_transform("EPSG:3857") # Does not work
#> Error in st_geometry.sf(x): attr(obj, "sf_column") does not point to a geometry column.
#> Did you rename it, without setting st_geometry(obj) <- "newname"?
projects_geometry <- projects %>%
dplyr::rename(`geometry` = `SHAPE`) %>%
janitor::clean_names()
View(projects_geometry) # works
project_geometry_transformed <- projects_geometry %>%
sf::st_transform("EPSG:3857") # Works Created on 2024-09-07 with reprex v2.1.1 Since, the problem doesn't seem to be originating from the GIS file format, rather than from having multiple geometry types, I am attaching the |
clean_names.sf()
does not recognize SHAPE
or shape
as a geometry field.clean_names.sf()
does not recognize SHAPE
column as a sfc
column when it contains multiple Geometry Types
The underlying issue was that we renamed the |
@billdenney That seems to have solved the issue. Thank you so much. |
Feature Requests/Bug Report
While
geometry
is a commonly used name of thesfc_GEOMETRY
column within asf
class object, thesf
data loaded from ESRI GeoDatabase has thesfc_GEOMETRY
in a column calledSHAPE
(or sometimesshape
). Whenclean_names()
is used in thissf
object, the function renames theSHAPE
toshape
which essentially breaks thesf
object and throws the following error when I try toview()
the SF object after cleaning the names. I am assuming that since thesfc
column is renamed, R essentially does not recognize thesf
object anymore.One workaround I have been using is to rename the
sfc
column togeometry
fromSHAPE
before usingclean_names()
.Would it be possible to internally identify
SHAPE
as asfc_GEOMETRY
column ifgeometry
doesn't exist in thesf
class object such thatclean_names()
doesn't try to rename it and break the object?The text was updated successfully, but these errors were encountered: