I'm trying to get the union of around 4,000 polygons using Shapely's cascaded_union function. The output of this function is a multipolygon in my case, which is normal since many input polygons do not overlap.

Yet, when I draw the output, I can clearly see that some small polygons are included whereas these polygons belong to a larger polygon. To my mind, these small polygons should be excluded from the union.

Here is a sample screenshot with 3 polygons of the union returned by shapely. The blue one is the bigger one with 43 185 exterior points and the green and orange ones are the smaller ones.

union of polygons

I also uploaded a text file containing the coordinates of the 3 Polygons using the built-in function mapping() from the shapely.geometry module.

It can be accessed there.

The file contains a dictionary {index:{...}} with 3 indexes, each of them containing a dictionnary representing a Polygon. If you need to get back the coordinates from the file, you can use the following Python code:

with open("file_polygon.txt","r") as f:
    testl = f.readlines()
teststr = "".join(testl)
testd = json.loads(teststr)
for index in testd:
    # List of exterior points of the polygon of index "index"
    ps = testd[index]["coordinates"][0]

If you have any clue of why these polygons are returned by the cascaded_union function, I would be happy to get them :).

  • Your link leads to nothing – gene Feb 7 '19 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.