QGIS-2.8-PyQGISDeveloperCookbook-en(17)
时间:2025-03-11
时间:2025-03-11
为开发人员准备的文档,涵盖QGIS的多种功能实现和代码。
Toreturnbacktodefaultgraylevels,use:
4.2.2MultiBandRasters
Bydefault,QGISmapsthe rstthreebandstored,greenandbluevaluestocreateacolorimage(thisisthe
MultiBandColordrawingstyle.Insomecasesyoumightwanttooverridethesesetting.Thefollowingcode
interchangesredband(1)andgreenband(2):
4.3RefreshingLayers
Ifyoudochangelayersymbologyandwouldlikeensurethatthechangesareimmediatelyvisibletotheuser,call
these
methods
The rstcallwillensurethatthecachedimageofrenderedlayeriserasedincaserendercachingisturnedon.
ThisfunctionalityisavailablefromQGIS1.4,inpreviousversionsthisfunctiondoesnotexist—tomakesure
thatthecodeworkswithallversionsofQGIS,we rstcheckwhetherthemethodexists.
Thesecondcallemitssignalthatwillforceanymapcanvascontainingthelayertoissuearefresh.
WithWMSrasterlayers,thesecommandsdonotwork.Inthiscase,
youhavetodoitexplicitly
Incaseyouhavechangedlayersymbology(seesectionsaboutrasterandvectorlayersonhowtodothat),you
mightwanttoforceQGIStoupdatethelayersymbologyinthelayerlist(legend)widget.Thiscanbedoneas
follows(ifaceisaninstanceofQgisInterface)
4.4QueryValues
Todoaqueryonvalueofbandsofrasterlayeratsomespeci edpoint
Theresultsmethodinthiscasereturnsa
dictionary,withbandindicesaskeys,andbandvaluesasvalues.