zoukankan      html  css  js  c++  java
  • Python将Excel生成SHP

    #!/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')
  • 相关阅读:
    【 socke】C# socket端口复用-多主机头绑定
    【网络】 NAT
    【socket】高级用法-ReceiveMessageFrom
    【socket】高级用法-异步
    C# GET 和 SET作用
    多态是什么意思?
    LINQ(LINQ to Entities)
    LINQ(隐式表达式、lambda 表达式)
    LINQ(LINQ to DataSet)
    C# 中的委托和事件
  • 原文地址:https://www.cnblogs.com/gispathfinder/p/5789767.html
Copyright © 2011-2022 走看看