From c422a7a8bb3558b6a9a2041153ab152141251fde Mon Sep 17 00:00:00 2001 From: chenzenghui Date: Fri, 12 Jan 2024 16:54:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- csv2shape.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 csv2shape.py diff --git a/csv2shape.py b/csv2shape.py new file mode 100644 index 0000000..a0a0303 --- /dev/null +++ b/csv2shape.py @@ -0,0 +1,24 @@ +import shapefile +from shapely.geometry import Polygon +import csv +from shapely import wkt + +# 从CSV文件读取数据 +csv_file_path = r'D:\德清研究院加密\项目\项目文档归档\空基算法\算法验证文档\样本\test_landConver.csv' + +with open(csv_file_path, 'r') as csv_file: + csv_reader = csv.DictReader(csv_file) + data = list(csv_reader) + +# 创建Shapefile文件 +with shapefile.Writer('output_shapefile.shp') as shpfile: + shpfile.field('parent_id', 'N', '10') + shpfile.field('id', 'N', '10') + shpfile.field('covernm', 'C', '50') + + for item in data: + wkt_polygon = item['WKT'] + polygon = wkt.loads(wkt_polygon) + #polygon = Polygon(eval(wkt_polygon)) + shpfile.poly([list(polygon.exterior.coords)]) + shpfile.record(parent_id=int(item['parent_id']), id=int(item['id']), covernm=item['covernm'])