ms_points | R Documentation |
Can be generated from the polygons by specifying location
to be
"centroid"
or "inner"
, OR by specifying fields in the
attributes of the layer containing x
and y
coordinates.
ms_points(input, location = NULL, x = NULL, y = NULL, ...)
input |
input polygons object to convert to points. One of:
|
location |
either |
x |
name of field containing x coordinate values. Must be |
y |
name of field containing y coordinate values. Must be |
... |
Arguments passed on to
|
points in the same class as the input.
library(geojsonsf)
library(sf)
poly <- structure("{\"type\":\"FeatureCollection\",
\"features\":[{\"type\":\"Feature\",\"properties\":
{\"x_pos\": 1, \"y_pos\": 2},
\"geometry\":{\"type\":\"Polygon\",
\"coordinates\":[[[102,2],[102,4],[104,4],[104,2],[102,2]]]}},
{\"type\":\"Feature\",\"properties\":{\"x_pos\": 3, \"y_pos\": 4},
\"geometry\":{\"type\":\"Polygon\",
\"coordinates\":[[[100,2],[98,4],[101.5,4],[100,2]]]}},
{\"type\":\"Feature\",\"properties\":{\"x_pos\": 5, \"y_pos\": 6},
\"geometry\":{\"type\":\"Polygon\",
\"coordinates\":[[[100,0],[100,1],[101,1],[101,0],[100,0]]]}}]}",
class = c("geojson", "json"))
poly <- geojson_sf(poly)
summary(poly)
plot(poly)
# Convert to points using centroids
out <- ms_points(poly, location = "centroid")
summary(out)
plot(out)
# Can also specify locations using attributes in the data
out <- ms_points(poly, x = "x_pos", y = "y_pos")
summary(out)
plot(out)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.