聽同學報告
2.本週作業
上週作業
使用 函數編輯器 寫一個getZone的函數
語法跟Python一樣
#-*- coding: utf-8 -*- from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def getZone(value, feature, parent): Zone ={ u'可耕地':[11,12,13], u'靜止水體':[30,2031,2032,2033,9010], u'林業':[20], u'河道':[2011], u'草地':[42,3111,5011,5012,5013,5014,9020,9040], u'裸露地':[2040,7011,7021,9030,9050,9060,9071], u'不透水層':[41,50,1010,1021,1022,1023,1024,1025,1031,1032,1033,1034,1035,1036,1037,1038,1039,1041,1042,1043,2012,2013,2014,2020,3011,3012,3021,3022,3023,3024,3030,3031,3032,3041,3042,3043,3044,3045,3050,3060,3070,3081,3082,3083,3084,3091,3092,3093,3094,3095,3096,3097,3098,3099,3100,3112,3120,3030,3140,4010,4020,4030,5020,5030,6010,6020,7022,8000,9072,9073] } for key in Zone: if value in Zone[key]: return key
Python語法:
串列(list)
宣告
type = [11, 12 ,13]
取值
type[0] => 11
type[1] => 12
判斷式
11 in type => true
633 in type => false
字典(dict)
由key:value配對的資料型態
key值必須為唯一 value則沒有限制
宣告
d = { 1:"a" , 2:"b" , 'pass':"You can't pass!"}
取值
d[1] => a
d[2] => b
範例
假設 value = 11
for key in Zone: # key = u'可耕地' if value in Zone[key]: # Zone[u'可耕地']的value是[11,12,13]
# value in Zone[key] 等於 11 in [11,12,13] =>true return key # true : 回傳key值 u'可耕地'
3.國外網站
Getting Started With Python Programming
http://www.qgistutorials.com/en/docs/getting_started_with_pyqgis.html
沒有留言:
張貼留言