程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python implements the conversion of csv files (point tables and line tables) to shapefile files

編輯:Python

Python converts csv files (point and line tables) into shapefiles

Description

  1. The geometry coordinates used by the point table are wkbPoint(geometry point coordinates)
  2. The geometry coordinates used by the line table are wkbLineString (multi-point coordinates)
    The difference is detailed in the screenshot

Annotated with reference to the method written by others, the conversion of points and edges is written as a function, and the shp file is read after each successful conversion to test whether the conversion is successful.

Notes

1. Solve the Chinese encoding of the shp dbf file
#gdal.SetConfigOption(“SHAPE_ENCODING”, “”)
#gdal.SetConfigOption(“SHAPE_ENCODING”, “gb2312”)
gdal.SetConfigOption(“SHAPE_ENCODING", "gbk")
2.layer.CreateField(ogr.FieldDefn('local_id', ogr.OFTString))
The name of the created field is preferably in English, and cannot exceed the cross character, a Chinese characteraccounts for more characters.

Code
(The order of the import of geopandas gdal should be considered, otherwise an error will be reported)

import

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved