Closed Robinlovelace closed 2 years ago
Another observation, I would expect this to work if the input had been created by sfheaders
:
world_sfh = sfheaders::sf_multipolygon(world_df_sfh)
Reasonable?
Came here for the same reason as @Robinlovelace, and seconding that I'd expect
library(spData)
world_df_sfh = sfheaders::sf_to_df(world)
sfheaders::sfc_multipolygon(world_df_sfh)
to work the same as:
library(spData)
world_df_sfh = sfheaders::sf_to_df(world)
sfheaders::sf_multipolygon(
world_df_sfh,
x = "x",
y = "y",
multipolygon_id = "multipolygon_id",
polygon_id = "polygon_id",
linestring_id = "linestring_id",
)
I'm guessing it is do with arguments being fed as a character? I'd be happy to do a draft PR, but with the r-cmd-check failing it's challenging to do testing (and my Rcpp knowledge is fairly limited).
Also additional workflow documentation and examples for sf -> df -> sfh I think would be useful, similar to sf_to_df()
.
If the workflow was clear, a new feature of sf_to_sfh()
(or another name to reflect going from "regular" sf to "sfheader" sf) might be useful, to skip this step of manually converting from sf to df and back. As far as I can tell, the output of sf_to_df()
is always the same, so can be used "under-the-hood" to take an sf and convert it to sfh straight away.
That would also remove any user errors that could be introduced in the manual process (for example, forgetting one of multipolygon_id
, linestring_id
etc. produces some funny results), and a direct function could also incorporate checks that length(sf) == length(sfh)
which would help with the above.
Again happy to attempt a draft PR, but not sure where to start.
There are helper functions
sf_pt()
sf_mpt()
sf_line()
sf_mline()
sf_poly()
sf_mpoly()
Which are designed to work on the output of sf_to_df()
directly, e.g
library(spData)
world_df_sfh = sfheaders::sf_to_df(world)
sfheaders::sf_mpoly(world_df_sfh)
But it's by design that the more general functions (sf_point()
, sf_linestring()
, etc...) require the user to specify the columns.
@thomaszwagerman
or another name to reflect going from "regular" sf to "sfheader" sf
I'm not entirely sure I follow the logic here. There's not really a sfh
object, so the concept of going to "sfheader" sf doesn't make much sense.
This maybe a non-issue. Opening it here in case of use/interest from a developer perspective.
Note:
sfheaders
does substantially better thansf
when it comes to round trip but seems there are some differences, as shown in the output of the reprex below.