2016-11-25 40 views
-1

我是一個新手python程序員,如果有人能幫助我,我會愛上它。 我正在使用python。我導入了一個.shp文件,其中包含一堆關於建築物的數據。我想提取建築高度最大值的數據'RELHMAX' - 我該怎麼做?從.shp文件中提取特定的數據 - python

這是數據文件。 https://drive.google.com/file/d/0BySL_YFrwgAuTTAzeVlacFdFXzA/view?usp=sharing

到目前爲止,我在想,我應該能夠使用特定的RELHMAX數據集由

buildingHeight = file[RELHMAX] 
print buildingHeight 

非常感謝你提前!

+0

您試過了什麼?我幾乎不會打電話給你目前的嘗試 – smac89

回答

1

考慮到你是編程新手,我建議如下。轉到google.drive.com並將south_camden_topo_v2.xlsx另存爲Google表格。現在,在文件選項卡上,將此文件保存爲csv文件,這是一種Python更容易處理的格式,即原始格式的xlsx格式。

我已經看過文件中的字段名稱。沒有人叫buildingHeight。但是,下面的代碼顯示瞭如何挖掘出可能需要的任何列。請注意,大多數記錄似乎缺乏大多數列的數據。

import csv 

fieldWanted = 'RELH2' 
with open('south_camden_topo_v2.xlsx - south_camden_topo_v2.csv') as csvFile: 
    reader = csv.reader(csvFile) 
    headings = next(reader) 
    fieldIndex = headings.index(fieldWanted) 
    print (headings) 
    count = 0 
    for row in reader: 
     print (row) 
     print (fieldWanted, ':', row[fieldIndex]) 
     count += 1 
     if count > 5 : 
      break 

請注意,該代碼僅輸出前幾條記錄,並從這些記錄中輸出RELH2的值。他們來了。

['FID', 'SCU_ID', 'SCU_CLASSI', 'POLY_SCU', 'THEMES', 'DHM_VOL', 'DHM_MEANH', 'DHM_STDDEV', 'DHM_MINH', 'DHM_MAXH', 'RELH2', 'RELHMAX'] 
['osgb1000005579280', '52101031610006', '1', 'TRUE', 'Buildings', '547.3700000000', '7.1087012987', '1.2253834286', '0.4000000000', '8.2600000000', '8.6000000000', '11.3000000000'] 
RELH2 : 8.6000000000 
['osgb1000001802821881', '52101037490003', '9', '', 'Buildings', '', '', '', '', '', '', ''] 
RELH2 : 
['osgb1000001802821884', '52101037490002', '9', '', 'Buildings', '', '', '', '', '', '', ''] 
RELH2 : 
['osgb1000005575118', '52101032530003', '3', 'TRUE', 'Buildings', '', '', '', '', '', '', ''] 
RELH2 : 
['osgb1000005574922', '52101052910008', '1', '', 'Buildings', '2449.5140000000', '10.7908105727', '3.3956447143', '0.0000000000', '17.5460000000', '11.6000000000', '19.4000000000'] 
RELH2 : 11.6000000000 
['osgb1000005575392', '52101041010004', '1', '', 'Buildings', '', '', '', '', '', '', ''] 
RELH2 : 
+0

非常感謝你的時間和幫助!這非常有幫助! – CvV

+0

非常歡迎!祝你好運。 –

0

我發現,似乎工作的另一種方式,但我覺得這不是最efficent方式

all = fileSource 

b = copy.copy(fileSource) 
b.remove('FID') 
b.remove('SCU_CLASSI') 
b.remove('POLY_SCU') 
b.remove('THEMES') 
b.remove('DHM_VOL') 
b.remove('DHM_MEANH') 
b.remove('DHM_STDDEV') 
b.remove('DHM_MINH') 
b.remove('DHM_MAXH') 
b.remove('RELH2') 
b.remove('SCU_ID') 
RELHMAX = b 

c = copy.copy(fileSource) 
c.remove('FID') 
c.remove('SCU_CLASSI') 
c.remove('POLY_SCU') 
c.remove('THEMES') 
c.remove('DHM_VOL') 
c.remove('DHM_MEANH') 
c.remove('DHM_STDDEV') 
c.remove('DHM_MINH') 
c.remove('DHM_MAXH') 
c.remove('RELH2') 
c.remove('RELHMAX') 
SCU_ID = c 

,但現在我得到一個錯誤說 「運行時錯誤(UnboundNameException ):名稱'複製'未定義「 並且它不再運行...

相關問題