Convert geometric entities loaded vom DXF files using ezdxf to shapely geometry objects.
First use ezdxf to load the DXF entities from file and filter them using query or similar.
import ezdxf
dxf_doc = ezdxf.readfile("your_file.dxf")
entities = dxf_doc.modelspace().query("*[layer==0]")Then use ezdxf-shapely to convert the entities and refine the results.
import ezdxf_shapely
geoms = ezdxf_shapely.convert_all(entities)
polygons = ezdxf_shapely.polygonize(geoms) # optionally merge lines to polygonsLicensed under the terms of the MIT License