[R-sig-Geo] add a field to sf object and point shape in kml
b|@|ev||@t @end|ng |rom gm@||@com
Tue May 7 14:16:00 CEST 2019
I have answer only to your first question.
The way you created the new column (a$b = 2) is correct.
The order of the columns and the place of the geometry column are
usually not so important, but if you want to rearrange the columns, just
use one of the following lines:
a <- a[, c(colnames(a)[!(colnames(a) %in% attr(a, "sf_column"))],
a <- st_sf(cbind(st_set_geometry(a, NULL), st_geometry(a)))
Hungarian Academy of Sciences
2019.05.07. 13:54 keltezéssel, Marta Rufino írta:
> Two very simple question:
> What is the best way to add a variable (field) to an sf object?
> # For example, if I do:
> (a = st_sf(a=1, geom = st_sfc(st_point(0:1))))
> # I would expect this would work, and it does, but then it makes some kind
> of a nested structure which I cannot work with properly.
> # Is this the proper way to add fields or there s another one?
> a$b = 2
> # you can see that the second field is after the geometry, which shows it
> is nested.
> Can we change the polygon col/fill and point shape/col when exporting sf
> obejcts to kml, using the function:
> st_write(sf.object, " sf.object .kml", driver='kml')
> Thank you very much in advance,
> Best wishes,
> My first steps in sf: https://rpubs.com/MRufino/488297
> [[alternative HTML version deleted]]
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
More information about the R-sig-Geo