1

I am trying to merge a bunch of either polygons or multipolygons by the merge_multi_polygons function in shapely, I am using my below code inside Spark

        elems=row['_c0']
        area_multipolygons=[]
        for y in elems:
            json_polygon=[]
            searchObj = re.finditer( r'[(]{1}([^()]*)[)]{1}', y)
            for i in searchObj:
                if i:
                    st_polygon= i.group(1)
                    list_polygon=[float(i) for i in st_polygon.split()]
                    json_loop=list(zip(list_polygon[::2], list_polygon[1::2]))
                    json_polygon.append(json_loop)

            forest_area_multipolygon=[json_polygon] 
            area_multipolygons.append(forest_area_multipolygon)

        merged_parttion_polygon=merge_multi_polygons(*area_multipolygons)

I get below error on some of my data

 File "C:\Users\Mahdi\AppData\Local\Programs\Python\Python37\lib\site-packages\pyspark\util.py", line 55, in wrapper
    return f(*args, **kwargs)
  File "main.py", line 147, in <lambda>
    udf_calculate_intersection=udf(lambda x: calculate_intersection(x), FloatType())
  File "main.py", line 138, in calculate_intersection
    merged_parttion_polygon=merge_multi_polygons(*area_multipolygons)
  File "C:\Users\Mahdi\eclipse-workspace\EliizaTest\mahdi\polygon_utils.py", line 75, in merge_multi_polygons
    res = [to_polygon(union)]
  File "C:\Users\Mahdi\eclipse-workspace\EliizaTest\mahdi\polygon_utils.py", line 47, in to_polygon
    e = coords(polygon_shape.exterior)
AttributeError: 'GeometryCollection' object has no attribute 'exterior'
0

merge multi polygons is not a shapely function to my knowledge. Try cascaded union https://shapely.readthedocs.io/en/latest/manual.html#shapely.ops.cascaded_union .

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.