简体   繁体   中英

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

你在寻找凸壳吗?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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