Python将Excel生成SHP
2016-08-20 10:19
561 查看
#!/usr/bin/env python # -*- coding: utf-8 -*- import gdal import xlrd import shapefile # open the excel file excel_file = xlrd.open_workbook("../geodata/highest-mountains-europe.xlsx") # get the first sheet sh = excel_file.sheet_by_index(0) w = shapefile.Writer(shapefile.POINT) # fields available GeoNameId Name Country Latitude Longitude Altitude (m) w.field('GeoNameId','F') w.field('Name', 'C') w.field('Country', 'C') w.field('Latitude', 'F') w.field('Longitude', 'F') w.field('Altitude', 'F') # loop over each row in the excel sheet for rownum in range(sh.nrows): # skips over the first row since it is the header row if rownum == 0: continue else: x_coord = sh.cell_value(rowx=rownum, colx=4) y_coord = sh.cell_value(rowx=rownum, colx=3) w.point(x_coord, y_coord) w.record(GeoNameId=sh.cell_value(rowx=rownum, colx=0), Name=sh.cell_value(rowx=rownum, colx=1), Country=sh.cell_value(rowx=rownum, colx=2), Latitude=sh.cell_value(rowx=rownum, colx=3), Longitude=sh.cell_value(rowx=rownum, colx=4),Altitude=sh.cell_value(rowx=rownum, colx=5)) print( "Adding row: " + str(rownum) + " creating mount: " + sh.cell_value(rowx=rownum, colx=1) ) w.save('../geodata/highest-mountains')
相关文章推荐
- python 生成excel
- 使用python生成excel格式的图片
- Python读excel生成数据存入txt文件
- python 读取excel文件生成sql文件实例详解
- python读取和生成excel文件
- Python生成九九乘法表到Excel
- python生成每日报表数据(Excel)并邮件发送
- python脚本――生成EXCEL,连接数据库,并将指定数据写入EXCEL
- 服务器巡检shell脚本,python生成excel文档并邮件发出
- python操作excel--生成图表
- python前端生成excel
- python结合Arcpy处理EXCEL数据生成多边形
- python 读取excel 生成json 读取json
- python 按固定格式数据生成excel报表源代码
- 利用python语言实现shp文件生成geojson文件
- 使用Python生成Excel格式的图片
- python3生成Excel报告
- Python中生成(写入数据到)Excel文件
- php中使用python生成excel报表
- Python实现导出数据生成excel报表的方法示例