[R-sig-Geo] Calculate the internal angles of polygons
Juan Pablo Carranza
c@rr@nz@ju@np @end|ng |rom gm@||@com
Sat Jun 1 07:40:53 CEST 2019
Dear members,
I'm having trouble in calculating the internal angles of a set of polygons.
I have a sf "MULTIPOLYGON" object of 5000 land parcels that has been tagged
according to their shape. The objective is to train an algorithm to predict
a large dataset (over 2 million polygons) according to these
classification. But that is a problem that comes forward.
First I need to calculate the internal angles of each one of the polygons
in the sample, in order to eliminate unnecesary nodes (yes, I tryed
st_simplify and also ms_simplify, but I need to control the process by the
angle values).
Here is as far as I get, a few lines of code (with an example polygon). The
next steps will be dealing with a way to generate a dataframe in wich each
row is a line of each polygon (decomposing the geometry but preserving the
polygon entityid in order to go back... easy to do with spdplyr?), and find
a way to calculate the angle between adjscent lines. Need a hand, please!
x =
c(4293215,4293205,4293205,4293194,4293174,4293176,4293190,4293201,4293204,4293218,4293215)
y =
c(6463731,6463733,6463734,6463736,6463740,6463750,6463747,6463744,6463744,6463741,6463731)
cords = cbind(x, y)
library(sp)
p = Polygon(cords)
ps = Polygons(list(p),1)
poly = SpatialPolygons(list(ps))
plot(poly)
library(sf)
poly = st_as_sf(poly)
lines = st_cast(poly$geometry, "LINESTRING")
plot(lines)
# not run: this turns the object too simple, I need to work on very complex
shapes.
# lines = st_simplify(lines, preserveTopology = FALSE, dTolerance = 1)
Really sorry for the lousy english... Best regards.
*MSc. Juan Pablo Carranza*
Economist
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list