找到图层中一个多边形到其他多边形的最小距离?
我试图弄清楚如何找到ArcGIS图层(一个图层由许多多边形组成)中从一个多边形到其他多边形的最小距离。更具体地说,我想知道是否可以用 python 运行一个循环,它会找到每个多边形到其他多边形的最小距离?
谢谢, 拉吉卜
I tried to figure out how to find the min distances from one polygon to other polygons in a layer (a layer consists of many polygons) of ArcGIS. More specific, I was wondering if it is possible to run a loop with python, which will find the min distances from each polygon to others?
Thanks,
Rajib
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您已经获得了多边形的中心坐标,那么您自己就可以轻松完成此操作。首先,您需要一个函数来查找相同维度的两点之间的距离:
然后您可以创建一个函数来查找点向量(列表或其他)中最近的点。我只需将
min()
函数与快速自定义键函数一起应用:如果您有多边形的顶点,则这会更复杂一些,但如果您采取这一步,很容易弄清楚- 一步一步。最外层的循环应该迭代“基本”多边形中的点(您试图找到最小距离的点)。嵌套在其中的循环应该将您带到比较向量中的每个其他多边形。从这里您可以调用 closest_pt() 函数来将您的基点与另一个多边形中的所有点进行比较,找到最接近的点:
它在结构上可能有点多余,但我认为它会起作用它提供了相当透明的逻辑。该函数返回一对
(vertex, close_pt, polys)
,其中:vertex
是基础中最接近另一个多边形的顶点的索引;close_pt
是另一个多边形中被发现包含最近点的点;并且polys
是与vec
中的多边形相对应的布尔值列表,这样每个polys[i] == True
当且仅如果close_pt
是vec[i]
的顶点。希望这有帮助。
If you've got the center coordinates of your polygons, it's illustratably easy to do this on your own. First you need a function to find the distance between two points of the same dimensions:
Then you can make a function to find the closest point among a vector (
list
or whatever) of points. I would simply apply themin()
function with a quick custom key-function:If you have the vertices of the polygon this is a couple steps more complicated, but easy to figure out if you take it step-by-step. Your outer-most loop should iterate through the points in your "base" polygon (the one you are trying to find the minimum distance to). The loop nested within this should take you to each of the other polygons in your comparison vector. From here you can just call the
closest_pt()
function to compare your basis point to all the points in this other polygon, finding the closest one:It may be slightly redundant structurally, but I think it will work and it provides pretty transparent logic. The function returns a pair of
(vertex, close_pt, polys)
, where:vertex
is the index of the vertex in your basis which was found to be closest to another polygon;close_pt
is the point in the other polygon which was found to contain the closest point; andpolys
is a list of Boolean values corresponding with the polygons in yourvec
, such that eachpolys[i] == True
if and only ifclose_pt
is a vertex ofvec[i]
.Hope this is helpful.
arcgis工具箱中有一个工具叫做:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00080000001q000000.htm
There is a tool in arcgis toolbox called:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00080000001q000000.htm