I have a series of polygons and points with each polygon containing a point. I want to determine the maximum distance of each point to the edge of the polygon containing it is contained within in R.
I looked at using the rgeos gDistance function but this returns 0 for points within polygons.
Using an example polygon and a point that falls within the polygon this is what i've coded so far but i'm getting a distance of 0 rather than the distance from a point to polygon edges.
pt1 = readWKT("POINT(0.5 0.25)")
p1 = readWKT("POLYGON((0 0,1 0,1 1,0 1,0 0))")
gDistance(pt1, p1)
# 0
Does a function exist in R or an R package that can determine distances for points within polygons to the polygon edge?
Much appreciated within advance.
r
specific, but in general, why not loop through each point defining the polygon, and measure the euclidean distance to the point inside the polygon? And just keep track of the max distance you encounter – jean