boundaries icon indicating copy to clipboard operation
boundaries copied to clipboard

Question on code

Open standarddev opened this issue 5 years ago • 5 comments

Hi! I'm in the process of learning python and using your code to do so!

I was able to run your code on the files that you provided. I decided to create my own file in qgis and try it on that but I'm running into an error with the concave_hull, edge_points = alpha_shape(points, alpha=1.87) line.

Traceback (most recent call last):

File "", line 63, in concave_hull, edge_points = alpha_shape(points, alpha=1.87)

File "", line 35, in alpha_shape for ia, ib, ic in tri.vertices:

ValueError: too many values to unpack (expected 3)

I'm not sure how to fix it. Any advice? I've attached the point file I'm trying to do it on. Test.zip

standarddev avatar May 12 '20 21:05 standarddev

There's nothing obviously wrong with your shapefile. I ran the Delaunay triangulation on it using qgis and there were no errors, so I think it's good input.

It's possible that it's tripping up the scipy Delaunay implementation. I would recommend that you run the code in a debugger (PyCharm, etc) and set a breakpoint at line 35 and inspect the value of tri.vertices.

dwyerk avatar May 18 '20 13:05 dwyerk

Thanks!

I got that working. Only part now I can’t figure out is when I run

Triangles = list(polygonize(m)), I get tuple object is not callable.

I did just polygonize(m) and that works fine. Just can’t get the list to work around it.

Any ideas?

standarddev avatar May 18 '20 17:05 standarddev

I'd make the same recommendation for setting a breakpoint at that point in the code and inspecting the values of each variable. list() should work just fine with whatever is returned from polygonize, so it's likely that something else has changed here.

dwyerk avatar May 18 '20 18:05 dwyerk

Thanks! It looks like the polygonize(m) function is working fine. It results in a generator which I expected. What is the point of the list() around that? What is it trying to accomplish?

Without it, the cascaded union doesn’t work but I’m not sure why.

Thanks!

standarddev avatar May 19 '20 13:05 standarddev

cascaded_union expects a list as input, not a generator, so list() unrolls the generator and returns a list. Consider this generator:

def gen():
    for i in range(10):
        yield i

g = gen()
lst = list(gen())

print(lst[0]) # <-- prints 0
print(g[0])   # <-- raises TypeError

dwyerk avatar May 19 '20 13:05 dwyerk