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
Calculate the internal angles of polygons
2 messages · Juan Pablo Carranza, Michael Sumner
There's code in trip for the angles, but arranging the underlying coords and expressing those in the right form will be the crux. st_coordinates gives what you need, or pure data frame from spbabel::sptable is what I'd start with. I'll take a look when I can. Cheers, Mike On Sat., 1 Jun. 2019, 15:41 Juan Pablo Carranza, <carranzajuanp at gmail.com> wrote:
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]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo