Dear Marta,

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"))], attr(a, "sf_column"))]
a <- st_sf(cbind(st_set_geometry(a, NULL), st_geometry(a)))

HTH,
Ákos Bede-Fazekas
Hungarian Academy of Sciences


2019.05.07. 13:54 keltezéssel, Marta Rufino írta:
Hi,

Two very simple question:

1)
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
a
# you can see that the second field is after the geometry, which shows it
is nested.

2)
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,
M.

------
My first steps in sf: https://rpubs.com/MRufino/488297

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to