Create points from a polygon layer
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, force_FC = TRUE, sys = FALSE )
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 |
force_FC |
should the output be forced to be a |
sys |
Should the system mapshaper be used instead of the bundled mapshaper? Gives better performance on large files. Requires the mapshaper node package to be installed and on the PATH. |
points in the same class as the input.
library(geojsonio)
library(sp)
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("json", "geo_json"))
poly <- geojson_sp(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)Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.