将线串转换为Geopandas中的geojson文件的多边形

时间:2019-03-14 04:03:43

标签: python geojson geopandas cad dxf

我有以下dxf格式的CAD文件,以autocad显示,如下所示: enter image description here

我使用GDAL org2org将其转换为名为geojson的{​​{1}}格式的文件,但所有文件都位于test.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 ] ] } } ] } 并显示如下图所示: enter image description here

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

顺便说一句,我读了type: polygon文件,它看起来像:

test.geojson

输出:

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

0 个答案:

没有答案