更新
今天发现之前的代码运行会报错,发现shapefile接口有更新,最近比较忙,没有去确认是否是因为python版本不同的问题。之前的代码是基于python2.7的,下面这部分更新后的代码是基于python3的。
#-*-coding:utf-8-*-
import shapefile as shp
import csv
import codecs
import os
def trans_point(folder, fn, delimiter=','):
'''transfer a csv file to shapefile'''
# create a point shapefile
output_shp = shp.Writer(folder + "%s.shp"%fn.split('.')[0], shp.POINT)
# for every record there must be a corresponding geometry.
output_shp.autoBalance = 1
# create the field names and data type for each.you can omit fields here
# 顺序一定要与下面的保持一致
output_shp.field('photo_url', 'C', 50) # string, max-length
output_shp.field('longitude', 'F', 10, 8) # float
output_shp.field('latitude', 'F', 10, 8