开发者

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.

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.

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


Are you looking for a convex hull?


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. 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. (Keeping in mind that ordering 60k points in some significant way just for this may not pay for itself.)


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/.

Many thanks for all participants!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜