多边形内的点到多边形边缘的距离 [英] distance from point within a polygon to polygon edge

查看:162
本文介绍了多边形内的点到多边形边缘的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NLCD数据在一个广阔的地区,七个森林州和一个非森林州工作.在某些森林地区内有一个地块(这是我正在研究的硕士论文).我用这个庞大的数据集困扰了我问过的每个人,但是我们确定那里有一个解决方案.森林/非森林区域是一个有符号的离散栅格.通过细分森林区域,我可以使森林区域成为多边形.我无法将非森林区域设置为多边形(太大).所以我试图获取到森林多边形边缘的点距离(该点在多边形内).您对获取点到森林边缘的距离有建议吗?

I am working with a huge area, 7 states of forest and nonforest using the NLCD data. Within some of the forested areas is a plot (this is my master's thesis I am working on). I have stumped everyone I have asked with this large dataset but we are certain there is a resolution out there. The forest/nonforest area is a signed and discrete raster. I was able to make the forested area into polygons by subsetting out the forested area. I am not able to make the nonforest area into polygons (too large). So I was trying to get point distance (the point is within the polygon) to the edge of the forested polygon. Do you have suggestions for getting the distance of a point to the forest edge?

推荐答案

以下是一些输出点到边缘的距离的代码,无论多边形是否凸出,是否CCW.您必须测试所有多边形的边缘.对于大量的边缘,这可能会有点慢.

Here is some code that output the distance from a point to an edge, wether the polygon is convex or not, CCW or not. You'll have to test for all your polygons' edges. It might be a little slow for a large set of edges.

- (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 + (testPoint.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));

}

这篇关于多边形内的点到多边形边缘的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆