The distance from a point within the polygon to the edge of the polygon

I work with a huge area, 7 forest states and nonforest using NLCD data. In some forest areas there is a plot (this is my main thesis I'm working on). I ran into everyone I asked with this large dataset, but we are sure that there is permission. Forest / non-forest zone is a signed and discrete raster. I was able to make the wooded area polygons, multiplying the forest area. I cannot make an unnecessary area with polygons (too large). So I tried to get the point distance (point in the polygon) to the edge of the wooded polygon. Do you have any suggestions for getting the distance from the point to the edge of the forest?

+3
source share
3 answers

Well, it really depends on a few things; in particular, which edge do you want? Do you want to find the nearest edge or do you have other criteria that you want to select for the edge (for example, the cardinal direction)?

If you want to find the nearest edge, you basically want to iterate over all line segments defined by the polygon, calculating the distance between lines and points; it will find your distance. There is a good implementation of the algorithm in Python on this question, and there is a good description of the algorithms there.

+2
source

, , , CCW . . .

- (double) distanceFromPoint:(yourPoint)testPoint
{

double pointX = edgePointB.x - edgePointA.x;
double pointY = edgePointB.y - edgePointA.y;

double k = pointX * pointX + pointY * pointY;
double u = ((testPoint.x - edgePointA.x) * pointX + (edgePointA.y - edgePointA.y) * pointY) / k;

if (u > 1)
    u = 1;
else if (u < 0)
    u = 0;

double x = edgePointA.x + (u * pointX);
double y = edgePointA.y + (u * pointY);

double dx = x - testPoint.x;
double dy = y - testPoint.y;

return sqrt((dx * dx) + (dy * dy));

}
+2
+1

All Articles