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
The geometry coordinates used by the point table are wkbPoint(geometry point coordinates)
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)