python - 在 Geopandas 中将线串转换为 geojson 文件的多边形
问题描述
我有以下dxf
格式的 CAD 文件,其显示autocad
如下:
我将其转换为以 GDAL org2orggeojson
命名的格式文件,但全部在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 ] ] } }
]
}
我怎样才能在 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...
解决方案
推荐阅读
- reactjs - 反应中循环中的元素的useRef
- scrapy - scrapy-splash 如何过滤重复项?
- ios - 如何在 Flutter 中为 IOS 14 上显示的 Admob 原生广告请求 App Tracking Transparency 授权?
- ios - 将 Picker 的值设置为对象的索引
- angular - 使用 Angular 11 中的 Hammer.JS,应用程序无法识别手势,例如平移
- javascript - 创建多个 DIV 并分配唯一 ID
- tensorflow.js - 有没有办法创建 TensorFlow.js 的本地调试版本?还是公开可用的非缩小版呢?
- r - 我如何将不同的参数归因于函数 strsplit(split = " ")?
- javascript - “无法解码图像:'primary.png'”安装 chrome 扩展程序时
- python - 我的 Python 代码运行但不会从 Gmail 收件箱中删除选定的电子邮件