Python 在Geopandas中将linestring转换为geojson文件的多边形

Python 在Geopandas中将linestring转换为geojson文件的多边形,python,geojson,geopandas,cad,dxf,Python,Geojson,Geopandas,Cad,Dxf,我有以下dxf格式的CAD文件,显示在autocad中,如下所示: 我使用GDAL org2org将其转换为名为test.geojson的格式文件geojson,但所有文件都在type:LineString { "type": "FeatureCollection", "name": "entities", "features": [ { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "Line

我有以下
dxf
格式的CAD文件,显示在
autocad
中,如下所示:

我使用GDAL org2org将其转换为名为
test.geojson
的格式文件
geojson
,但所有文件都在
type:LineString

{
"type": "FeatureCollection",
"name": "entities",
"features": [
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 30.0, 0.0 ], [ 30.0, 9.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 16.0, 47.0 ], [ 16.0, 34.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 16.0, 13.0 ], [ 16.0, 0.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 0.0, 31.0 ], [ 9.0, 31.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 30.0, 31.0 ], [ 39.0, 31.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 0.0, 23.0 ], [ 9.0, 23.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 30.0, 23.0 ], [ 39.0, 23.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 0.0, 16.0 ], [ 9.0, 16.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 30.0, 16.0 ], [ 39.0, 16.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 0.0, 0.0 ], [ 39.0, 0.0 ], [ 39.0, 47.0 ], [ 0.0, 47.0 ], [ 0.0, 0.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 9.0, 38.0 ], [ 11.0, 38.0 ], [ 11.0, 34.0 ], [ 28.0, 34.0 ], [ 28.0, 38.0 ], [ 30.0, 38.0 ], [ 30.0, 9.0 ], [ 28.0, 9.0 ], [ 28.0, 13.0 ], [ 11.0, 13.0 ], [ 11.0, 9.0 ], [ 9.0, 9.0 ], [ 9.0, 38.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 11.0, 32.0 ], [ 17.0, 32.0 ], [ 17.0, 15.0 ], [ 11.0, 15.0 ], [ 11.0, 32.0 ] ] } },
{ "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 20.0, 32.0 ], [ 28.0, 32.0 ], [ 28.0, 15.0 ], [ 20.0, 15.0 ], [ 20.0, 32.0 ] ] } }
]
}
我想将其转换为
类型:polygon
,显示如下图所示:

我如何在Geopandas中做到这一点?谢谢

顺便说一句,我读了
test.geojson
文件,它看起来像:

import geopandas as gpd
df = gpd.read_file("test.geojson")
df.head(5)
输出:

  Layer               SubClasses EntityHandle                                           geometry
0     0  AcDbEntity:AcDbPolyline          106  LINESTRING (30.35270412013777 0.79246615687498...
1     0  AcDbEntity:AcDbPolyline          107  LINESTRING (16.16520412013776 47.1049661568749...
2     0  AcDbEntity:AcDbPolyline          108  LINESTRING (16.16520412013776 13.4799661568749...
3     0  AcDbEntity:AcDbPolyline          109  LINESTRING (0.665204120137787 31.2924661568749...
4     0  AcDbEntity:AcDbPolyline          10A  LINESTRING (30.35270412013777 31.2924661568749...

有9条两点线和5条多边形线。您要求我们从它们创建12个多边形。是吗?是的,我想问题可能来自这样一个事实:第一张图片中的每个多边形看起来都像多边形,但实际上并不是闭合的。因此,在将其从
dxf
转换为
geojson
后,它是
LineString
而不是
Polygon
。我想得到每个多边形的
边点
角点
,以便在JavaScript中显示它们,但我不知道如何正确地对它们进行分组。您有9条两点线,和5条多边形线条。您要求我们从它们创建12个多边形。是吗?是的,我想问题可能来自这样一个事实:第一张图片中的每个多边形看起来都像多边形,但实际上并不是闭合的。因此,在将其从
dxf
转换为
geojson
后,它是
LineString
而不是
Polygon
。我想得到每个多边形的
边点
角点
,以便在JavaScript中显示它们,但我不知道如何正确地将它们分组。