Yearly Archives: 2009

A Lab for using the PIHMgis and PIHM model (II)

Zhuotong Nan (南卓铜, [email protected])

DEM processing

In this part, we will show you how to delineate a watershed with inputs of DEM(Digital elevation model) and outlet location. Watershed delineation is necessary for any distributed hydrologic model. Although hydrologic models use different software to implement the delineation, the underlying idea and steps are generally common.

1. Open PIHMgis by double clicking the PIHMgis_v2.0.0 shortcut created in the previous section.

2. Enable PIHMgis.

Open Plugin Manager… in the QGIS Plugins menu, tick the PIHMgis item (Figure 3), and press Ok.

clip_image002

Figure 3 QGIS Plugin Manager

Now the PIHMgis toolbar appears as shown in Figure 4.

clip_image004

Figure 4 the PIHMgis v2.0.0 toolbar

3. Load DEM to PIHMgis for displaying.

Layer > Add a Raster Layer…, select lab3.shale.hillsDEMsh_elev.asc.

This DEM file is in ESRI ASCII grid file format. If you have files in ESRI binary grid format which is a proprietary format, you need to convert them to ASCII format by using some ArcInfo command or by some third party tool, such as gdal_translate available from the GDAL website at http://www.gdal.org/.

The map view of the DEM file looks like as following (Figure 5),

clip_image006

Figure 5 DEM map view in QGIS

4. Save as a QGIS project. File > Save Project As…, in the Save As dialog, navigate to the directory of lab3.shale.hills, type “sh” for the file name, and then click Save.

Note: During following steps, please save the project frequently. If the project is crashed, you can restore to the previous session by open the project you saved.

5. Fill pits.

Question: Why do we need to fill pits for a DEM file prior to further watershed delineation?

Click the small arrow next to the Raster Processing on the PIHMgis toolbar and then select Fill Pits. This will bring up the Fill Pits dialog (Figure 6).

clip_image008

Figure 6 The Fill Pits interface

Select sh_elev.asc as the input DEM grid and name the output pit-filled grid as “pits_filled.asc” under the “raster_processing” directory as shown in Figure 6. Press Run to start the pit filling process. Click “Close” to dismiss the dialog after the process is done. The pit-filled DEM will automatically be loaded into the QGIS data frame.

6. Calculate flow direction and flow accumulation.

Use the command Raster_Processing > Flow Grid to open the Flow Grid window (Figure 7).

Set pits_filled.asc as the input; flow_dir.asc and flow_accu as the output flow direction grid and flow accumulation grid respectively, also under the raster_processing folder.

Click Run to start the processing. After done, click Close.

clip_image010

Figure 7 Flow Grid

Both flow_accu and flow_dir are shown in the QGIS map view (Figure 8).

Note: the direction codes are following: 1 – east, 2 – North east, 3 – North, 4 – North west, 5 -West, 6 – South west, 7 – South, 8 – South east.

clip_image012

Figure 8 Flow direction generated by PIHMgis

Tip: Within the QGIS framework, visibility of a GIS layer can be switched using the table of contents on left.

Tip: The identify tool clip_image013 can be used to identify features by clicking on them in the right map view panel. For example, click on the flow_dir item in the table of contents to make it selected, and then use the identify tool to click over the map view, the Identify Results dialog will pop up and show the value of the clicked feature (Figure 9), here, value of 4 means the point of interest has a flow direction towards north west.

clip_image015

Figure 9 Identify results

7. Generate stream grid

Select Raster Processing > Stream Grid to make the Stream Grid dialog visible, set the flow accumulation grid generated in previous step, i.e., flow_accu.asc, as the input grid, and then set output stream grid to stream_800.asc with a threshold value of 800 (number of grids). Press Run to generate stream grid (Figure 10).

clip_image017

Figure 10 Generate stream grid with a threshold value of 50.

Don’t close the Stream Grid window. Set thresholds to 300 and 800 respectively to compare the resulting stream grids (stream_300 and stream_800 accordingly, Figure 11) and run again.

clip_image019clip_image021clip_image023

Figure 11 The generated stream grids with thresholds set to 50, 300 and 800. (left: 50, middle: 300, right: 800)

Close the Stream Grid dialogue by clicking on the Close button.

Question: How to determine an appropriate threshold for a watershed of interest?

8. Generate the stream order grid (known as Link Grid in PIHMgis)

Select Raster Processing > Link Grid to pop up the configure interface (Figure 12). Select stream_800.asc as the input stream grid and flow_dir.asc as the input flow direction grid, and set the output link grid name to link_800.asc (saving to the same raster_processing folder). Click Run to begin processing. After done, the link grid will be shown on the map view panel if the Load in Data Frame option is checked.

clip_image025

Figure 12 Generate a stream order grid

9. Create a vector file of stream network

Select Raster Processing > Stream PolyLine to make the interface appear (Figure 13). Set inputs with stream_800.asc and flow_dir.asc generated by previous steps and set the name of the output stream polyline file to str800.shp. Click Run to process it after parameters are specified.

clip_image027

Figure 13 Create a vectorized stream network

10. Generate catchment grid and its corresponding vector file

Select Raster Processing > Catchment Grid to bring up the catchment grid generation interface (Figure 14). Set Stream Link Grid to link_800.asc, Flow Dir. Grid to flow_dir.asc, and output Catchment Grid to “cat_800.asc”. Both input and output files are located in the raster_processing directory.

Click Run to start calculating the catchment grid. Click Close to dismiss the dialog.

Select Raster Processing > Catchment Polygon to display the interface for converting grid catchment file to vector (Figure 15). Set input to cat_800.asc and output to cat800v.shp. Run to start the processing and Close to dismiss the window. The resulting catchment polygons are shown on Figure 16. Note: the color to render the polygons might not be same as that on the Figure 16, as it is determined by QGIS automatically.

clip_image029

Figure 14 Catchment grid generation interface

clip_image031

Figure 15 Convert catchment grid to vector

clip_image033

Figure 16 Resulting catchment polygons

11. Extract the watershed boundary of interest

The current PIHMgis version 2.0 does not provide such a function to clip the watershed boundary under study and stream network within it. We need to do this by help of other GIS software such as ESRI ArcInfo, or by using QGIS editing capability demonstrated below. In the future version of PIHMgis, this functionality will be implemented. To determine the boundary of a watershed, the outlet location should also be specified.

Open QGIS 1.0, load cat800v.shp and str800.shp generated in previous steps to the data frame using Layer > Add Vector Layer…, and then load outlet.shp, which contains outlet location. The view now looks like Figure 17.

clip_image035

Figure 17 QGIS 1.0 with stream network, catchment polygons and outlet layers loaded

Click on cat800v within the table of contents to make it the current layer. Use “Select Features” tool (Figure 18) to select the watershed polygon of interest (Figure 19). The selected polygon is now in yellow. If the tool is invisible, just drag the toolbar to a new place to make fully appeared.

Students are advised to have a look at all built-in toolbars, making them familiar with all those often-use tools.

clip_image037

Figure 18 The Attributes toolbar

clip_image038

Figure 19 Select the watershed of interest

Right click the cat800v item and select “Save selection as shapefile…” to save the selected polygon (Figure 20) to a new shapefile, here, “cat800v_sel.shp”, under the “raster_processing” folder. If you are required to select a project, click OK to use the default one.

Note: The default project probably is not correct, but does not matter with following operations. You can change the project in a layer’s property window later.

clip_image040

Figure 20 Save selection as a new shapefile

Similarly, select the corresponding stream from str800 and save as a new shapefile “str800_sel.shp” (Figure 21), also into the “raster_processing” folder. If you are required to select a project, click OK to use the default one.

clip_image042

Figure 21 Select the corresponding stream, shown in yellow.

Load str800_sel and cat800v_sel into the QGIS map view. Drag layers up or down to rearrange layers’ visibility. Uncheck str800 and cat800v to hide them. Now the map view looks like Figure 22.

clip_image044

Figure 22 Load str800_sel and cat800v_sel and hide str800 and cat800v

Make str800_sel disappear. Select “cat800v_sel” layer, and use “zoom in” tool (the one w/ magnifier icon and a plus symbol shown in Figure 23) to enlarge the area near the outlet. Click “Toggle editing” tool (the one w/ pen icon shown in Figure 23) to make the current layer editable (Figure 23). Now the other tools on the Digitizing toolbar are also available when the layer enters into edit mode. The tools may be hidden, in this case drag toolbars to a blank place to make all tools shown.

clip_image046

Figure 23 cat800v_sel in edit mode

Click the Split Features tool. Draw a curve to cross the outlet so as to split the whole polygon. Right click to finalize the curve; the Split Features will then split the polygon. Click the “Toggle editing” again to make the layer back in the normal view mode. Make sure saving it if you are asked to save the features.

Use “Select Features” tool to select the large polygon right to the outlet. If the previous operation has been done successfully, only the large part will be selected and the upper left part remains unselected. Save the selected polygon to a new shapefile named “cat800v_clip.shp”. Load cat800v_clip to the map view. It now looks like as shown on Figure 24.

clip_image048

Figure 24 Clipped watershed boundary

Similarly, we also split the str800_sel.shp. Make it visible and editable, draw a curve to split it across the outlet, save the operation, and then export the desirable line (on the right) to a new shapefile, “str800_clip.shp”. (Figure 25)

clip_image050

Figure 25 Clipped stream network

Zoom in the outlet area, and carefully edit the stream polyline making its end node locate on the watershed edge. However no necessary exact alignment is needed. Tools for vertex editing are shown in Figure 26. The final stream line looks like as in the Figure 27. Save the stream file after done.

clip_image052

Figure 26 vertex editing tools. Left: move vertex; middle: add vertex; right: remove vertex

clip_image054 clip_image056

Figure 27 Align the end node of stream line to the boundary. Left: original; right: edited

Close QGIS 1.0.

小熊挣了好多钱

这两天给家里的电话总是不通,先是朵朵妈妈手机被偷,再是欠费停机。今天再试了一下,却意外惊喜的发现通了。她们正坐在机场到兰州的出租车上。没跟小赵说两句,朵朵就说她要发言。接过后,她说,爸爸,小熊挣了好多钱,回来小熊将钱给你呀。她的最喜欢的玩具小熊吗?不是很明白她的意思。当我问的时候,朵朵抗议说信号不好,不跟我讲了。她妈接上后,说朵朵说要改名了,不叫朵朵叫小熊了,原因是她感觉小熊好可爱。这趟回老家的时候,可能大人给了她不少压岁钱,说要给爸爸。原因是爸爸没钱,妈妈有很多钱,最重要的是,爸爸会用钱给朵朵买糖吃,总归还是为好她自己着想呢。

Talking about 也说内存

Syeerzy在blog里有讲他关于程序内存使用的看法,认为为了追求速度的提高,有必要“充分利用内存”。

这是似是而非而且荒谬的结论,而且同样极端了。

不管内存有多少G了,相比硬盘比还是很小。所以在完成任务目的,保证用户可接受的速度下,优化内存当然是性能的一个重要指标了。写程序的时候永远无法知道运行这个程序时的计算机情况,当然能节省则要节省了,一般程序很少去智能调整自己内存占有,优化程序的内存使用是现代操作系统的重要任务。节省越多的内存,意味着可以同时并存更多的程序,这是为用户负责的一种表现。

举个极端的例子,程序A完成既定任务用1M内存在多数配置机器上可以比较流畅的运行了,这时目标机器上还有2G的内存可用,OK,照“充分利用内存”的说法,意思就是最好将2G都“充分”用起来,OK,程序A充分用了1G的内存(嗯,程序A load了除了必要的执行代码和必要的数据,将潜在操作有可能用到的文件也顺便load进来了,这样对1%的用户来讲可能提升了 0.0001%的速度,这符合“充分使用内存”吧),目标机器上还有1G剩余的(幸好不是只剩1K内存了)。问题是,1M内存使用的时候速度已经不错了,用1G内存提升的速度并不明显。但为了这一点速度上的优化被你“充分”占了1G的内存。目标机器接下去还要再运行一个专业软件,而这个软件需要load一个1G的数据进内存,my god,stupid的操作系统接下去做的事情就能让你发疯。就是因为程序A根本无法预料到用户机器的情况,从而根本无法做到“充分”利用。你能做的就是,保证性能的前提下,尽量优化内存使用,尤其对于大型程序来讲。

让程序去根据内存可获取情况自动调整自己的内存占有情况? 当然可以,但有这时间,不如去开发更多的大家需要的功能。而且操作系统已经具备多数情况下行之有效的算法去优化这些程序的内存使用,尽管有时候很stupid。

“所以,最终结论是”,即使“在内存使用不超出最大物理内存的情况下,比如在大内存的PC机上(大内存指内存接近或超过4G—4G是32位地址的范围,比如2G或3G或8G)”,也不能为了一点点的速度提升去“充分”利用内存。“内存多使用并不是什么错,不要再把内存使用多少作为性能标准了”,这是对的,但“我们追求的性能”不仅仅是“速度”,还有对用户负责的一种态度。——除非,增加内存使用可以明显提高各方面的性能,那又是另一个story了。

Documentary film on the global warming issue presented by former US vice president Gore

A friend recommended a *documentary* movie presented by the former US vice president Gore on the topic of global warming. It takes totally approx. 1hr30 min in length. I would like to share it with all of you. Very good movie worthy all of you have a look at it.

BTW, the movie is presented in English, but also with a good Chinese translation on the screen.

Following please find the links,

Part 1.  http://www.tudou.com/programs/view/HoJM-FFBL5g/

Part 2. http://www.tudou.com/programs/view/9Fxft4eiyN8/

Part 3. http://www.tudou.com/programs/view/lZEjFpbrf3Y/

Part 4 : http://www.tudou.com/programs/view/LdBZIFXborQ/

In the Part 3, we also can see Prof Yao Tangong who introduced the facing challenges to Gore.

Latest Flash player should be installed in order to see the movie online.

如何在vista里显示图片缩略图

南卓铜 ([email protected])

Vista的资源管理器里浏览图片时默认仅显示图标。如图1所示,

image
图1 以图标形式出现的缩略图,这是Vista显示图片的默认方式

尽管双击图标,转到照片库,可以浏览图片内容的缩略图。我个人更偏向于如以前XP下直接在资源管理器里显示照片内容的缩略图。这其实是可以通过改变选项做到的。Vista默认禁止显示图片内容缩略图,估计是出于性能上的考虑。

单击“组织”菜单,在下拉菜单里选择“文件夹和搜索选项”(图2),确认“以缩略图形式显示文件图标”打上勾,并且去掉“始终显示图标,从不显示缩略图”前的勾。确定后,图片以内容缩略图的形式出现(图3)。

image
图2 文件夹选项

image
图3 Vista以图片内容缩略图显示

A Lab for using the PIHMgis and PIHM model (I)

Zhuotong Nan (南卓铜, [email protected])

Set up work place

1. Download PIHMgis version 2.0 from the URL:

http://www.pihm.psu.edu/PIHMgis_v2.0.0/PIHMgis_v2.0.0.zip

Download Shale Hills PIHMgis data files from the URL:

http://cid-0ea641a5a7f665a1.skydrive.live.com/self.aspx/Public/shale.hills.pihmgis.data.zip

Download qgis.1.0 from the URL:

http://cid-0ea641a5a7f665a1.skydrive.live.com/self.aspx/Public/qgis.1.0.zip

Note: The current PIHMgis v2.0 is built with QGIS 0.8 preview version and cannot run with QGIS 1.0 because APIs of those two version are inconsistent. The stable QGIS 1.0 version provides us a much better user interface and richer functionality than version 0.8. We will use QGIS 1.0 editing functions to manipulate vector data. The development team of PIHMgis is working on the migration to QGIS 1.0, which might be available in near future.

2. Make a directory “PIHM-lab”, and then extract “PIHMgis_v2.0.0.zip” to this directory. Go to this PIHMgis_v2.0.0 folder, locate “PIHMgis_v2.0.0.exe”, make a shortcut and rename the shortcut to “PIHMgis_v2.0.0”, and then copy this shortcut file to the directory “PIHM-lab” (our lab root directory).

Clicking the shortcut will bring up the Quantum GIS (QGIS) window, as shown Figure 1. Click “X” to close QGIS.

clip_image002

Figure 1 the QGIS 0.8 preview version interface coming with the PIHMgis. Note, the interface might be shown in different language if your computer locale is not set to English.

3. Create a directory “lab3.shale.hills” under “PIHM-lab”. Extract “shale.hills.pihmgis.data.zip” to the “lab3.shale.hills” directory.

4. Extract qgis.1.0.zip to the directory “PIHM-lab”, go to “qgis.1.0bin”, make a shortcut “qgis” for qgis.exe under this folder, and then copy this shortcut to the directory “PIHM-lab”. Click the qgis shortcut to open it, making sure it can work. It looks like Figure 2.

clip_image004

Figure 2 the QGIS 1.0 interface

回复

见友有评论几条谜语,给予很高评价。诚然,有几条无论从立意和技巧上讲都很见水平,评述也见一定功底。但对某条,我不大为然,与友有不同意见,回复其评论如下:

1-5很精彩
6貌似从技术上讲 或许很精巧 如你所评
但谜底很为勉强。中国13亿人,估计没几个人知道有个俄罗斯的地名叫古巴哈吧
如果这样为了制谜而去刻意找谜底,恭喜,全世界无数个地名,而且翻译没有标准,
随便组合到一起就可以作地名
如果是耳熟能详的地名,自当别论
犹如音乐,技巧再好,如果音乐缺少了感情和投入,那都不叫好音乐
类似,这也不算好谜

原文见:http://user.qzone.qq.com/502934697/blog/1214660957

(6)啥别解,离合吧(俄罗斯地名)古巴哈
       狼作谜                       南周须评析
       读本谜时让我想起好多事,记得刚学谜时,在中华灯谜网,受到众
多谜师友的指点,使我受益非浅。“啥别解,离合吧”一位导师的话语,在
我耳旁回荡。是呀,不要在会意方面去想,直接从离合这边去考虑,谜底“古
巴哈”不就出来了吧。“啥”字离别,分解后成“哈,十”,再把“吧”字用
离合的手法和“哈,十”相扣合,就成为谜底。面句引用灯谜术语名词二,
嵌入“啥,吧”两字,使得整条谜,更加让人回味。其手法干净利索,不留
刀斧之痕,可见谜作者的功底是何等的利害。

朵朵的bf

朵朵问她姑姑,姑姑你什么时候找男朋友呀,我都为你着急了。她姑逗她说,姑姑找不到呀。朵朵敲着她姑姑的脑袋说,你笨死了。姑姑说,那朵朵有吗,送一个给姑姑。朵朵同志说,五一、龙龙,还有在老家认识的小男孩,一口气数了四五个。最后说,不送给姑姑,她舍不得。