rpic_geojson() read into an sf data frame (EPSG:4326), one row per
feature, ready for ggplot2::geom_sf(), mapgl or any other sf
consumer.
Arguments
- src
pic source code: a
pic()object or a single string.- ...
arguments passed to
rpic_geojson()(frame,anchor,scale,bearing,features,flatten,view_scale,circuits,texlabels,name_col).
Details
Columns are the feature properties, in snake_case: every : and - of
a GeoJSON property name becomes _ (rpic_sf_names()) — stroke,
stroke_width, fill, stroke_opacity, fill_opacity, title, and
geopic_id, geopic_kind, geopic_text, geopic_placement,
geopic_font_size, ... for the geopic: namespace — so every column is a
syntactic name (x$geopic_kind, aes(fill = fill), dplyr::filter()).
A property no feature carries is absent; one only some features carry is
NA elsewhere. The geometry column is geometry, of mixed type
(polygons for boxes and circles, line strings for lines and arrows,
points for dots and text).
A shape with text (box "Marco Zero") is followed by a title row: a
point at the centre of its text, geopic_kind == "title", geopic_id
"<id>:title" and geopic_for naming the shape's geopic_id, carrying
the text in title and geopic_text (engine 0.15.1; MapLibre's
pic-title layer draws these). Filter them out
(x[x$geopic_kind != "title", ]) to keep one row per shape.
The "warnings" and "registration" attributes of rpic_geojson() are
carried over (as attributes of the data frame; sf operations may drop
them), and warnings are raised the same way. The "geojson" attribute
keeps the engine's own GeoJSON text (the rpic_geojson() result the data
frame was read from), which rpic_maplibre_layers() and add_rpic()
use instead of re-serialising the data frame.
See also
rpic_sf_names() for the column names; autoplot.rpic_source()
for a quick ggplot2 map; vignette("maps").
Examples
if (requireNamespace("sf", quietly = TRUE)) {
x <- pic('geo_lon = -34.8711; geo_lat = -8.0631; geo_scale = 400
B: box "Marco Zero" at (1, 1) fill 0.95
arrow from B.sw to (0, 0)') |>
rpic_sf()
x[, c("geopic_kind", "fill", "stroke_width")]
}
#> Simple feature collection with 4 features and 3 fields
#> Geometry type: GEOMETRY
#> Dimension: XY
#> Bounding box: xmin: -34.8711 ymin: -8.0631 xmax: -34.86611 ymax: -8.058579
#> Geodetic CRS: WGS 84
#> geopic_kind fill stroke_width geometry
#> 1 box #f2f2f2 0.8 POLYGON ((-34.86883 -8.0603...
#> 2 title <NA> NA POINT (-34.86747 -8.059483)
#> 3 arrow <NA> 0.8 LINESTRING (-34.86883 -8.06...
#> 4 arrowhead #000000 0.8 POLYGON ((-34.87094 -8.0627...