Is there an efficient algorithm to generate a 2D c

2019-01-04 07:34发布

Having a set of (2D) points from a GIS file (a city map), I need to generate the polygon that defines the 'contour' for that map (its boundary). Its input parameters would be the points set and a 'maximum edge length'. It would then output the corresponding (probably non-convex) polygon.

The best solution I found so far was to generate the Delaunay triangles and then remove the external edges that are longer than the maximum edge length. After all the external edges are shorter than that, I simply remove the internal edges and get the polygon I want. The problem is, this is very time-consuming and I'm wondering if there's a better way.

10条回答
贼婆χ
2楼-- · 2019-01-04 07:46

You can do it in QGIS with this plug in; https://github.com/detlevn/QGIS-ConcaveHull-Plugin

Depending on how you need it to interact with your data, probably worth checking out how it was done here.

查看更多
贪生不怕死
3楼-- · 2019-01-04 07:47

The answer may still be interesting for somebody else: One may apply a variation of the marching square algorithm, applied (1) within the concave hull, and (2) then on (e.g. 3) different scales that my depend on the average density of points. The scales need to be int multiples of each other, such you build a grid you can use for efficient sampling. This allows to quickly find empty samples=squares, samples that are completely within a "cluster/cloud" of points, and those, which are in between. The latter category then can be used to determine easily the poly-line that represents a part of the concave hull.

Everything is linear in this approach, no triangulation is needed, it does not use alpha shapes and it is different from the commercial/patented offering as described here ( http://www.concavehull.com/ )

查看更多
做个烂人
4楼-- · 2019-01-04 07:51

The Bing Maps V8 interactive SDK has a concave hull option within the advanced shape operations.

https://www.bing.com/mapspreview/sdkrelease/mapcontrol/isdk/advancedshapeoperations?toWww=1&redig=D53FACBB1A00423195C53D841EA0D14E#JS

Within ArcGIS 10.5.1, the 3D Analyst extension has a Minimum Bounding Volume tool with the geometry types of concave hull, sphere, envelope, or convex hull. It can be used at any license level.

There is a concave hull algorithm here: https://github.com/mapbox/concaveman

查看更多
唯我独甜
5楼-- · 2019-01-04 07:52

A simple solution is to walk around the edge of the polygon. Given a current edge om the boundary connecting points P0 and P1, the next point on the boundary P2 will be the point with the smallest possible A, where

H01 = bearing from P0 to P1
H12 = bearing from P1 to P2
A = fmod( H12-H01+360, 360 )
|P2-P1| <= MaxEdgeLength

Then you set

P0 <- P1
P1 <- P2

and repeat until you get back where you started.

This is still O(N^2) so you'll want to sort your pointlist a little. You can limit the set of points you need to consider at each iteration if you sort points on, say, their bearing from the city's centroid.

查看更多
狗以群分
6楼-- · 2019-01-04 07:53

Good question! I haven't tried this out at all, but my first shot would be this iterative method:

  1. Create a set N ("not contained"), and add all points in your set to N.
  2. Pick 3 points from N at random to form an initial polygon P. Remove them from N.
  3. Use some point-in-polygon algorithm and look at points in N. For each point in N, if it is now contained by P, remove it from N. As soon as you find a point in N that is still not contained in P, continue to step 4. If N becomes empty, you're done.
  4. Call the point you found A. Find the line in P closest to A, and add A in the middle of it.
  5. Go back to step 3

I think it would work as long as it performs well enough — a good heuristic for your initial 3 points might help.

Good luck!

查看更多
forever°为你锁心
7楼-- · 2019-01-04 08:01

A quick approximate solution (also useful for convex hulls) is to find the north and south bounds for each small element east-west.

Based on how much detail you want, create a fixed sized array of upper/lower bounds. For each point calculate which E-W column it is in and then update the upper/lower bounds for that column. After you processed all the points you can interpolate the upper/lower points for those columns that missed.

It's also worth doing a quick check beforehand for very long thin shapes and deciding wether to bin NS or Ew.

查看更多
登录 后发表回答