0

I converted my input file with geometry Polygon 25D to an output file with geometry Polygon using the below code. As you can see the below image. Problem is that the holes in the polygon is vanished after applying this code. I would like to keep the holes in the polygon. To achieve that how can I edit or modify the below code? Or is there a better way to do it ?? I am open for anything answer related to python.

def convert_3D_2D(geometry):
    import geopandas as gp
    new_geo = []
    for p in geometry:
        if p.has_z:
            if p.geom_type == 'Polygon':
                lines = [xy[:2] for xy in list(p.exterior.coords)]
                new_p = Polygon(lines)
                new_geo.append(new_p)
            elif p.geom_type == 'MultiPolygon':
                new_multi_p = []
                for ap in p:
                    lines = [xy[:2] for xy in list(ap.exterior.coords)]
                    new_p = Polygon(lines)
                    new_p
                    new_multi_p.append(new_p)
                    new_multi_p
                new_geo.append(MultiPolygon(new_multi_p))
                new_geo
    return new_geo


df = gpd.GeoDataFrame.from_file('input_file_25D.shp')
df.geometry = convert_3D_2D(df.geometry)
df.to_file('output_file_2D.shp')

figure

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.