[R-sig-Geo] add a field to sf object and point shape in kml

Barry Rowlingson b@row||ng@on @end|ng |rom gm@||@com
Tue May 7 21:23:05 CEST 2019


On Tue, May 7, 2019 at 6:11 PM Vijay Lulla <vijaylulla using gmail.com> wrote:

> Good one Barry!  As far as I'm aware sf uses rgdal to write various file
> formats and writeOGR has options called dataset_options and layer_options
> which are considered experimental.
>

Not quite - `sf` uses the underlying C/C++ GDAL/OGR library directly. The
`rgdal` package does the same. One doesn't use the other.

To write KML the GDAL/OGR library uses either its "kml" or its "libkml"
driver which is documented here:

https://www.gdal.org/drv_libkml.html

dataset_options and layer_options tend to be single value options per
dataset and per layer - to set something per *feature* is going to need a
lot more information, and having an extra attribute in the feature table
(spatial data frame) seems reasonable.

I've not quite understood all the libkml creation options relating to
styles so there may be an easy way to do it but I don't think the overhead
of an extra column is too much trouble.

Barry



> Do you know if either of these options can be used instead of creating a
> new field/attribute for the sf dataframe?  More importantly, I would like
> to know your opinion of using these options vs creating an attribute.
> Thanks in advance,
> Vijay.
>
> On Tue, May 7, 2019 at 11:07 AM Barry Rowlingson <b.rowlingson using gmail.com>
> wrote:
>
>> On Tue, May 7, 2019 at 12:54 PM Marta Rufino <marta.m.rufino using gmail.com>
>> wrote:
>>
>> > Hi,
>> >
>> > Two very simple question:
>> >
>> > 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')
>> >
>> >
>> Setting styles for writing KML using GDAL/OGR is described here:
>>
>>
>> https://gis.stackexchange.com/questions/297494/how-to-style-kml-through-libkml-layer-creation-options
>>
>> For example I have an sf data frame of Osprey tracking data (as points),
>> and if I create a new field:
>>
>>
>> osp$OGR_STYLE="PEN(c:#128020,w:5px)"
>>
>> and then:
>>
>> st_write(osp, "/tmp/osp.kml",driver="libkml")
>>
>> then the features in the KML get written with:
>>
>>          <LineStyle>
>>             <color>ff208012</color>
>>             <width>5</width>
>>           </LineStyle>
>>
>> I realise now that "PEN" is probably wrong for point features, but it
>> should all be explained in the google OGR style docs:
>>
>> https://www.gdal.org/ogr_feature_style.html
>>
>> and in the links in that GIS stack exchange question...
>>
>> Barry
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo using r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list