简体   繁体   English

从随机坐标列表中查找外边框

[英]Finding the outer borders from the list of random coordinates

I've a huge list (60 000+) of coordinates and I haven't found a way for recognizing the outer borders. 我有一个巨大的坐标列表(60 000+),我还没有找到识别外边界的方法。

The list of coordinates are quite random, but they're defining some really specific area. 坐标列表非常随机,但它们定义了一些非常特定的区域。

I should be able to draw an area by using that list by using OpenLayers, so they also should in order. 我应该能够通过使用OpenLayers使用该列表绘制区域,因此它们也应该按顺序。

This seemed to be relatively easy nut to break but has proven to be quite challenging. 这似乎相对容易破解,但已被证明是非常具有挑战性的。

What might be the best approach for this problem? 什么可能是解决这个问题的最佳方法?

  • Heikki 科瓦莱宁

你在寻找凸壳吗?

If you just want the bounding box, it's easy enough: 如果你只想要边界框,那很容易:

min_x = MAX_INT;
min_y = MAX_INT;
max_x = MIN_INT;
max_y = MIN_INT;

for p in points:
  if p.x < min_x then min_x = p.x;
  if p.y < min_y then min_y = p.y;
  if p.x > max_x then max_x = p.x;
  if p.y > max_y then max_y = p.x;

If there's no easy equivalent of MAX_INT and MIN_INT on your platform, just pick the first one in the list. 如果您的平台上没有简单的等效MAX_INT和MIN_INT,只需选择列表中的第一个。 It's possibly less 'pretty' code, but it is also possibly faster by a meaningless amount. 它可能不那么“漂亮”的代码,但它也可能更快,无意义的数量。

Of course, if your data were ordered in some significant way, you might be able to do something more clever than iterating over 60k items and performing 240k comparisons. 当然,如果您的数据以某种显着的方式排序,您可能能够做一些比迭代超过60k项目和执行240k比较更聪明的事情。 (Keeping in mind that ordering 60k points in some significant way just for this may not pay for itself.) (请记住,为此目的以某种重要方式订购60k点可能不会为此付出代价。)

Convex hull is the subject what I've been looking for. 凸壳是我一直在寻找的主题。 I found a really nice script from http://code.activestate.com/recipes/66527-finding-the-convex-hull-of-a-set-of-2d-points/ . 我从http://code.activestate.com/recipes/66527-finding-the-convex-hull-of-a-set-of-2d-points/找到了一个非常好的脚本。

Many thanks for all participants! 非常感谢所有参与者!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM