| Zhuotong's profile苦楝树BlogListsNetwork | Help |
|
|
2/10/2009 A Lab for using the PIHMgis and PIHM model (II)Zhuotong Nan (南卓铜, zhn1@pitt.edu) DEM processingIn 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. Figure 3 QGIS Plugin Manager Now the PIHMgis toolbar appears as shown in Figure 4. Figure 4 the PIHMgis v2.0.0 toolbar 3. Load DEM to PIHMgis for displaying. Layer > Add a Raster Layer…, select lab3.shale.hills\DEM\sh_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), 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). 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. 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. 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 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). 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. 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. 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. 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. Figure 14 Catchment grid generation interface Figure 15 Convert catchment grid to vector 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. 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. Figure 18 The Attributes toolbar 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. 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. 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. 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. 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. 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) 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. Figure 26 vertex editing tools. Left: move vertex; middle: add vertex; right: remove vertex Figure 27 Align the end node of stream line to the boundary. Left: original; right: edited Close QGIS 1.0. 2/3/2009 A Lab for using the PIHMgis and PIHM model (I)Zhuotong Nan (南卓铜, zhn1@pitt.edu) Set up work place1. 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. 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.0\bin”, 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. Figure 2 the QGIS 1.0 interface 7/23/2008 Land cover数据Goode格式在ArcGIS中的访问南卓铜 (zhn1@pitt.edu) 一些有名的Land cover数据集并没有使用通用的GIS格式,比如在以下链接, http://www.geog.umd.edu/landcover/tree-cover-poster/download.html 下载broadleaf Layer,gzip解压缩后为 694,417,920 bytes,扩展名为.img,但不同于Erdas Imagine .img格式。 据介绍Goode binary file是plain binary,即相当于BSQ (Band sequential),其metadata有以下信息: 40031 pixels by 17347 lines,且是8bit unsigned integer,应当总大小为 694,417,757bytes,而解压缩后的大小大了163bytes,目前我还不知道原因。 根据metadata信息,可以添加头文件,broadleaf.hdr,内容如下, nrows 17347 将broadleaf.img改名为 broadleaf.bsq,在ArcGIS中才可以正常访问,也可以导出为其它格式,比如Grid。不过注意其空间参考系仍为unknown。在ArcCatalog中打开其属性页,在spatial reference中选projected coordinates/World/Goode Homolosine (Land).prj。可以将bsq设置为 Goode投影。 如果希望转换成其它常用格式, 上图将bsq转成ESRI binary grid格式。图形化结果如下图。 在Workstation下好像没有找到Goode投影,但在Desktop下可以找到.prj。因为如果bsq是unknown时,导成esri grid,在ArcCatalog里对grid进行定义投影(属性->define spatial reference),没法子定义到Goode投影,很奇怪。所以这里,我是先对bsq定义投影,再转成grid。此外,通过ArcToolbox的Data Management下的projection define来做,也是可以。 6/10/2008 ArcGIS Identity command "Number of shapes does not match the number of table records" errorWhen I run Identity_analysis in ArcGIS command windows against geodatabase, a message of something like "Number of shapes does not match the number of table records" popups. The error continues even if you reinstall the ArcGIS whenever using the Identify command. Solution: go to c:\documents and settings\yourname\local settings\temp and delete all the files (some files might be denied to access, just skip them). 5/27/2008 ArcGIS栅格向Surfer Grid的格式转化 (Convert ArcGIS raster to Surfer GIS)Zhuotong Nan (zhn1@pitt.edu) 以下简单的代码实现了ArcGIS支持的栅格向Golden software的Surfer ASCII grid的格式转化。需要注意的是,ArcGIS的栅格左上为坐标原点,向下向右为正。而Surfer grid是左下是坐标原点,向上向右为正。 Here I will show a class that implements the major functionality to convert any Raster file supported by ArcGIS to Surfer ASCII grid format. The resulting Surfer grid can be read by Surfer with version 6 or higher. One point we need to keep in mind, ArcGIS raster stores data in row-major order, right and downwards being positive, while Surfer grid takes lower left corner as the original, right and upwards being positive. using System; namespace RasterToSurferGrid public SurferGrid(string rasterPath) IWorkspaceFactory wf = new RasterWorkspaceFactoryClass(); IRasterProps props = (IRasterProps)raster; //populate data for (int y = ny - 1; y >= 0; y--) //get the max, and min zlo = min; public void WriteToFile(string outPath) } } } 附件是源代码。工具的运行需要dotnet framework 2.0和ArcView以上的License运行。编译后在命令行敲入RasterToSurferGrid有使用提示。 The attached please find necessary source codes which can be compiled on your own platform. Dotnet framework 2.0 and a valid ArcView license or higher are both required to run this tool. Besides, ArcGIS assemblies for dotnet framework are required. After successful compilation, typing RasterToSurferGrid following the command prompt shows you its usage information. 4/1/2008 MODIS过境时间及相关Zhuotong Nan(南卓铜, zhn1@pitt.edu) 教科书上都有MODIS有固定的过境时间,比如Terra说是10am过境(指从北向南经过赤道,中文资料上有意无意忽略这些定语,时间是UTC),Aqua是13:30过境(从南到北经过赤道。国家MODIS网站上将13:30写成14:30,是错误的。)。其实对于某一区域,过境时间不一样了。比如下面两张NASA Orbit Archive的Terra轨道图。 对于美国Oklahoma区域(MODIS tile: h09v05)左边在下午5点,右边在下午7点。 而针对16天合成的NDVI和EVI,它是选择其后16天内的观测良好(如无云)的若干观测通过一定算法合成的,每个网格上的数据都有可能来自此16天内的不同时间。幸好NDVI/EVI作为反应植被的一种指标,对半月期变化是可以接受的,用来反应整个植被变化的趋势是足够了。但如果要跟土壤水分等时间性十分强(如一场大降水)的数据耦合到一起应用,则需要慎重的考虑。 (最近看的资料有这些想法,了解不多,如有谬误,请指正) 3/27/2008 Kappa toolZhuotong Nan (南卓铜,zhn1@pitt.edu) 网上可以找到的计算Kappa系数的工具都是基于ArcView 3.x,如KappaStat。大多是做Land cover classification的人开发的。计算对象是采样的点文件和分类的polygon或者grid文件。但如果我们将Kappa应用于两个图像比较它们的相似性时,这类软件不能直接用。一个可行的方法是,将其中一个图像转换成point文件,比如应用arcgis的RasterToPoint命令。但对于很多图像对要比较,则没有好用的法子。KappaStat的图形界面和本身是一个ArcView 3.x的扩展模块,决定了即使写Avenue脚本也不是件容易实现的事。 所以我们写了一个小工具Kappa.exe。它用来计算两个栅格文件之间的Kappa系数,只要两个栅格文件有同样的width和height(即两图像是同样的mxn阵列)。Kappa工具不考虑栅格文件所在的空间参考系,只是简单的逐网格进行运算。用户需要自己确认两幅图像有合适的空间参考系。 Kappa工具与KappaStat进行了结果验证,证明计算是可靠,输出结果包括误差矩阵(Error Matrix),Kappa系数,还包括Variance和P统计值。 Kappa工具对栅格图像的支持调用了ArcGIS ArcObjects栅格API,支持很多种栅格格式,包括ESRI grid, ASCII grid, TIFF/GeoTIFF, JPEG等。 Kappa工具运行在命令行。这意味着通过简单的批处理脚本,可以实现批处理功能。比如,以下Windows batch代码实现了两个目录下相同文件名的栅格文件的Kappa计算。计算结果保存在kappa.txt文件里。 @echo off 命令行格式,Kappa.exe [参考或实测图像] [待比较图像] {-l:日志文件} {-k:Kappa文件} []表示必须,{}表示可选。对ESRI grid,图像指定到目录名;对个人geodatabase(通过Access数据库保存)的Raster dataset,以geodb.mdb\raster指定;文件geodatabase的Raster dataset,以geodb.gdb\raster指定。如果指定日志文件,在屏幕上输出的内容将同时保存到日志文件中;如果指定Kappa文件,则将Kappa系数单独保存在此文件中。此两选项开关在批处理有用。 运行需求 dotnet framework 2.0 运行平台 运行在Windows系统。但由于工具由C#编写,调用ArcGIS ArcObjects相关API,如果在Linux上有安装ArcGIS desktop 9.2,结合MONO runtime,本工具应当可以被编译成适合于Linux平台。 Binaries和source codes可以Email联系我。 3/25/2008 在ArcGIS中应用脚本实现批处理Zhuotong Nan(南卓铜) zhn1@pitt.edu ArcGIS 9.2提供了脚本功能,可以方便地实现批处理功能。可用脚本包括JS, VBS和Python。以下示例利用Python实现批处理ASCII grid文件到ESRI Binary grid转换的功能。 问题ASCII grid由matlab代码生成,存储于 LDAS.data 目录。ASCII grid内容如下: ncols 32 各ASCII grids命名有以下规律: nbwi3.[yyyy].[mm].[dd].[hh]h.txt 其中[yyyy]是4位年份,[mm]是月份,[dd]是2位日期,[hh]是24制的小时。比如,nbwi3.2001.07.08.15h.txt等。 生成的ESRI Binary grid有以下命名规律:n[yy][mm][dd][hh],其中[yy]是2位年份,[mm]是月份,[dd]是2位日期,[hh]是24制的小时。如n01070814。注意,ESRI grid的命名和长度是有一定要求限制的,所以我们必须要选择合适的,并能区别数据的命名方式。 我们需要做的是将数百个ASCII grids转换成对应的ESRI binary grids。 实现脚本编写环境我们这里采用免费的PyDev/Eclipse。Python脚本存储在与LDAS.data并列的src目录下。事实上,可以使用任何文本编辑软件来用脚本,但Eclipse提供很多编程增强功能,如智能提示等。
首先,需要通过import arcgisscripting,将arcgisscripting导入Python。arcgisscripting事实上是位于C:\Program Files\arcgis\bin目录下的arcgisscripting.dll。如果在运行时,提示找不到arcgisscripting库,则需要配置Python库路径。 库导入成功后,gp=arcgisscripting.create() 创建script对象,此后通过“gp.命令”的方式调用script支持的命令。一般来讲,可以在arcgis command window里使用的命令,都会有对象的script调用方式。比如, ASCIIToRaster的命令语法是ASCIIToRaster_conversion <in_ascii_file> <out_raster> {INTEGER | FLOAT},对应的脚本语法是ASCIIToRaster_conversion (in_ascii_file, out_raster, data_type)。我们可以在ArcGIS Desktop帮助文档里找到。 此外,gp还有一些专用的script命令,比如ListRasters、GetMessage等,大家可以在ArcGIS Desktop帮助文档查询Geoprocessor object。这些命令对于进行批处理迭代时十分有用。 在以上代码中,与geoprocessor有关的代码有,
workspace设置了当前的工作目录,相当于在command window里执行 “workspace 目录”。 ASCIIToRaster执行实质的转换工作。如果此处我们需要执行位于ArcGIS扩展模块的命令,则需要在调用命令前,先对扩展模块(如spatial analysis)进行checkout。使用以下命令:
否则CellStatistic_sa会抱怨说没有License可用。 代码其余部分是常规Python代码。以下取得指定目录下的txt扩展名的全部文件名,并生成对应的grid文件名。
Python十分有趣,如果有其它语言基础,学习起来并不难。对我们写ArcGIS脚本,有一般的Python知识就足够了。尽管效率不如传统的arcinfo AML高,但在功能上则不逊色。如果需要实现十分复杂的GIS功能,则建议使用c++, vb或.net语言操作ArcObjects。 2/1/2008 Stuck when updating ArcGIS 9.2 sdk for .net sp4When I install ArcGIS 9.2 developer SDK for .net framework 2.0 SP4, it will be stuck with time remaining 0 sec. So strange. It turns out to be caused by VC# express edition. A trick is to remove VCExpress process in Task Manager, thanks to contribution from ESRI forum posting. The installation will then continue. Stupid ESRI. Every tool is empty in ArcToolbox 9.2I met a problem when I were running a routine in Command Line Window. Many effort to figure it out by looking through Internet. Solution is rather simple. Now they get back. 1/25/2008 太糟糕了 ArcGIS 9.0与IE 7冲突,表现在运行ArcToolbox的任何命令,都会关闭整个app。 以为是我机器的问题,figure it out花了好几个小时 后来发现是本身的问题,ArcGIS 9.1提供了Patch,ArcGIS 9.2已经兼容 但ArcGIS 9.0是manual support,建议将IE 7卸掉。 ESRI不是一般的黑。变着法子让大家花钱去升级。 See here for official statement. 1/15/2008 Advanced Areal Weighted Interpolation by ArcView 9.2 - draft versionPart III Advanced areal weighted interpolationZhuotong Nan (南卓铜) (zhn1@pitt.edu) Motivation and objectiveArcView 9.2 comes with some basic interpolation approaches, for example, inverse distance weighted, Kringing, etc. In some cases, we want interpolate based on areal weighted. For example, Radar measurement can produce rainfall data over a study area. In order to use those Radar rainfall in hydrological model, e.g., VIC model, with a 1/8 degree spatial resolution, we need to do interpolation from a higher resolution, e.g., 4km by 4km. As shown in Figure 1, each grey cell has a measured value from Radar. We would like to generate an appropriate value for a VIC cell which might cover several Radar cells. In this part, we will illustrate an areal weighted approach. Figure 1 Radar rainfall cells and 1/8 deg VIC cells 1. Create VIC grid polygonsInstall Fishnet script with ArcView 9.2ArcView 9.2 comes with a fishnet function (Data Management Tools → Feature Class → Create Fishnet) which is capable of generating a regular grid lines. However due to the limitation of ArcView license, it’s hard to implement conversion from polyline to polygon which is necessary to do areal weighted interpolation to be introduced in this section. Therefore, we will employ a free yet powerful script from ArcScripts website.
Figure 2 Customization dialog Drag Create Fishnet to any place on toolbar. You will see Note, to uninstall the script, you can open Customize dialog again, and drag fishnet icon Create 1/8 degree VIC grid polygonsVIC is a macroscale hydrologic model that solves full water and energy balances. It runs on basis of VIC grid. See http://ldas.gsfc.nasa.gov/LDAS8th/LDASspecs/LDASspecs.shtml for details of grid extent. We will generate VIC grid polygons using Fishnet utility download from ArcScripts in a scale of 1/8 degree. Figure 3 Parameters for creating 1/8 degree VIC grid
Reproject VIC grid polygons to Albers equal-area projection system
Figure 4 Reproject to Albers Equal Area projection system The produced vicgrd8_alb.shp now is in Albers Equal Area projection system. Note here we specified a transformation method to convert NAD_1927 to NAD_1983. Remember vicgrd8.shp is in NAD_1927 system and now vicgrd8_alb.shp is in NAD_1983 system.
2. Generate polygons for XMRG radar data file
xster=hrapx*4762.5 - 401*4762.5 Copy 0703200407z.asc to 0703200407z_ster.asc. Then open 0703200407z_ster.asc using any text editor, change its header to, ncols 335 Save 0703200407z_ster.asc.
ASCIIToRaster c:\workspace\lab2\0703200407z_ster.asc c:\workspace\lab2\g0703200407z FLOAT
In ArcCatalog, right click g0703200407z to open its Properties window. Navigate to Spatial Reference section, click Edit… to define its spatial reference. Choose Define the coordinate system interactively. Select Stereographic (Polar view) and configure it as shown below. Figure 5 Parameters for Polar Ster projection system
The conversion from raster to polygon only support grid file in integer. To do this, run following commands in Command Line Window. Times_sa c:\workspace\lab2\g0703200407z 100 c:\workspace\lab2\g07032004_100 Int_sa c:\workspace\lab2\g07032004_100 c:\workspace\lab2\g07032004int At this point, the produced g07032004int is already an integer grid file. RasterToPolygon c:\workspace\lab2\g07032004int c:\workspace\lab2\g0703200407_poly NO_SIMPLIFY VALUE A field “GRIDCODE” in the generated polygon (g0703200407_poly) is corresponding to cell values in g07032004int, which is 100 times real rainfall value.
Using Data Management Tools → Projections and Transformations → Feature → Project in ArcToolbox to project g0703200407_poly in Polar Stereographic coordinate system to g0703200407_alb in Albers Equal Area Coordinate System. This target coordinate system can be imported from vicgrd8_alb.shp. 3. Calculate area contribution to each VIC cellCalculate area for each VIC cellUsing CalculateAreas command to calculate area for each VIC cell in Command Line Window. CalculateAreas c:\workspace\lab2\vicgrd8_alb.shp c:\workspace\lab2\vicgrd8_alb_area.shp The field “F_AREA” in vicgrd8_alb_area.shp indicates area in square meter. OverlayIntersect utility is used to calculate areal contribution from XMRG polygons to each VIC cell.
Workspace c:\workspace\lab2
Figure 6 Intersect input parameters
Figure 7 Attribute table of intersect.shp Here FID_vicgrd and F_AREA come from VIC cells, while FID_g07032 and GRIDCODE come from XMRG polygon file. FID_vicgrd uniquely represents each VIC cell whose area is show in F_AREA field. GRIDCODE is actually equal to 100 * rainfall. Querying attribute, for example FID_vicgrd = 1400, will extract all small polygons consisting a VIC cell. Calculate areal weighted rainfall
Open intersect.shp’s attribute table, Click Options → Add Field… Figure 8 Add a new field Click the header of VIC_AREA column to select this field, right click it then select Field Calculator…, Yes upon warning message. Input [F_AREA] in the lower textbox then click OK to start calculation. Figure 9 Field calculator
CalculateAreas intersect c:\workspace\lab2\inters_area
Figure 10 Calculate Percentage field
Make inters_area layer visible, and make sure there is no selection in this layer. Otherwise use Figure 11 Summary statistics Link interpolated rainfall data to VIC cells
Figure 12 Join to rainfalls.dbf
Figure 13 Make field name self-explanatory In order to use in combination with other raster, we can also convert this polygon shapefile to raster using FeatureToRaster command in Command Line Window. 4. Visualization
Figure 20 Symbology
Figure 21 Exported map ConclusionAlthough ArcView 9.2 has already included some basic interpolation approaches, it turns out in many cases hard to meet our specific requirements. This handout walks through how to interpolate Radar rainfall data to 1/8 degree VIC grid, illustrating necessary steps to implement areal weighted interpolation approach using ArcView. This handout also show us essential GIS operations such as project, clip, intersect, export, manipulate attribute table, link feature class to external table, etc, as well as making use of third party script. (转载请保持信息的完整,并加以适当引用) 1/14/2008 SimCity开源了On January 10 2008 the SimCity source code was released under the free software GPL 3 license under the name Micropolis. http://en.wikipedia.org/wiki/SimCity (国内可能要加代理才能访问) http://simcitysocieties.ea.com/about.php?languageCode=1 12/18/2007 Extending ArcGIS Command: A case tutorial (II)ArcGIS command扩展:ArcGIS 9.2/C# 2的实现 (上节介绍了如何使用VS 2005 C# express来帮助我们生成ArcGIS Command扩展的代码框架。) 下面我们来介绍框架代码各部分的具体含义。
ArcGIS是基于COM构建的,它只支持同样符合COM规范的动态链接库(Class library)。Guid必须不与任何一个COM组件相同。默认会生成一个新的全局标识符。我们也可以使用ArcGIS菜单里Developer Tools下面的Guid Generator来获取新的标识符(图10)。 ClassInterface和ProgId仍然是作为将.net类库导出成COM需要的一些属性。seal关键词指定了本命令不能再被继承。需要注意的是此类从BaseCommand上继承过来,BaseCommand实现了ICommand接口。9.2里BaseCommand放到ADF.BaseClasses命名空间下面,在之前版本是放在Utilities.BaseClasses下面。同时一些BaseCommand有关的辅助命令现在也放到了ADF.CATIDs空间。Utilities命名空间仍然存在,但当使用该空间下的BaseCommand在编译时会有deprecated的警告。 COM Registration Function(s)折叠起来的代码用于实现DLL到COM的自动注册和卸载过程。对于一般的应用,使用其生成代码就足够。 public BatchedChangeDatasource()构造函数里初始化了一些Command必要的信息,比如该Command所在的类别,这是以后在使用命令的时候存放的类别(如图11),同时也连接了一个命令表示的图标(m_bitmap)。这些变量是其基类BaseCommand里继承过来的。
如果不使用默认图标,则需要更改这里的名称。 Overriden Class Methods区域是需要开发者具体完成实现的地方。OnCreate在命令附加到ArcGIS时调用,一般这里传入的Object就是具体的Application,这里将Application对象存储到m_hookHelper.Hook属性里。通过Hook属性可以与ArcGIS Application进行必要的互访问。默认的OnCreate功能十分简单,只是判断了Application是否打开,Application是否有活动的View,如果有则使本命令可用。更多的判断则需要开发者来实现。 OnClick()是用户在点击Command后进行的操作。本案例中进行批量更改DataSource等功能便需要在这里实现。 此外,框架代码还将Project Build Properties设置成 Register for COM interop。对于手工生成的项目,必须记得设置此项。
在具体添加代码前,我们先编译一下,看是否有问题。不幸的是默认的框架编译时会提示缺少引用。我们添加引用后(图13)编译通过。 在类最前面添加私有变量声明。
_app接管Hook对象保管Application。_layerNameToBeReplaced指定要被替换Data Source的Layer名。同名的Layer会存在于不同的Data Frame里面。 因为我们需要实现的功能只对ArcMap有用,所以需要判断宿主应用程序是否MxApplication,如否,则禁用本命令。将OnCreate里的下面代码:
更改成:
现在主要的功能是在OnClick里实现。要完成批量替代Data Source的功能,一般的思路是这样:在当前的Document(一个.Mxd文件即Document)里找到各个Data Frame(在ArcObjects,每个Data Frame就是一个Map),迭代各Map。在每个Map里迭代各Layer,判断此Layer是否具备指定的_layerNameToBeReplaced的名称,如是,将该Layer的Data Source代换成指定的。为了实现时间序列的代换,则还需要先形成目标Dataset Name的List,然后逐一代换。以下代码实现了将一个给定Layer Name的Feature层替换成固定的某个存储在File Geodatabase里的FeatureClass。targetGDBpath指定File Geodatabase的路径,具体的FeatureClass由 fcn.Name指定。如果此FeatureClass是存储在Geodatabase里的某个Feature Dataset里,可由fcn.FeatureDatasetName来指定。最终的Data Source的更换由IDataLayer.Connect来实现。
COM风格的编程经常会看到很多的接口,不同的接口间不停的转换。其实接口一般是按功能进行分类,一个类通常实现了多个接口。比如FeatureLayer会实现不同的例如IDataLayer, IFeatureLayer, IDataset等,IDataLayer负责与数据源有关的操作,IFeatureLayer负责跟具备FeatureClass有关的操作,而IDataset实现了FeatureLayer作为Dataset有关的一些操作。 对Interface的熟悉应用建立在对相关类熟知的基础上。.net help十分全面,查找某接口,可以回溯到应用该接口的全面Class,而每个Class也会给出其实现的各个接口。通过这种方法,我们可以在一定程度上知道哪些接口是可以相互转换的。比如,IMap.get_Layer()查找帮助我们知道是返回ILayer,再结合我们期望是找到一个FeatureLayer,所以寻找FeatureLayerClass的实现的接口,发现其与数据源有关的操作封装在IDataLayer和IDataLayer2里。于是我们将layer cast成IDataLayer,再进行Connect操作。 以上代码中,fGDBWorkspaceFromString方法实现如下,作用是通过构建连接字符串来生成IWorkspace。
至此,我们完成了一个很简单的可运行的Command扩展。回到构造函数,将m_category赋为“tong's Extensions”。编译后,打开ArcMap,打开tools菜单下的Customize...,弹出窗口如图14。左边的Categories可以找到tong's Extensions,右边的Commands可以看到我们的BatchedChangeDatasource。选定该命令,可以拖拉到任何工具栏。Close此Customize窗口后,命令就可以如内置一样运行。 剩余的问题 对前面设定的期望目标,我们可以通过以下方法形成一个时间序列Dataset的名称。
在Connect的时候,根据次序可以赋给不同的RasterName。在更换数据源时,如果确保都在同一Workspace下,则可以通过下面代码简单代换。
如果不在同一Workspace,IName还需要指定IWorkspaceName。 结论 本文结合实际工作的一个案例,演示了如何应用Visual Studio 2005 C# Express来开发扩展ArcGIS Command。以上演示还有很多需要改进的地方,比如要代换的Layer名,不能内置在代码里,我们可以通过生成一个Dialog让使用者来决定替换哪一层,再比如,我们可以设置更漂亮的图标以区别于已有的图标。但这些都已经不是本tutorial的内容。本tutorial的目的是希望大家通过阅读本文可以初步掌握如何使用C#进行ArcGIS扩展,大家更多需要关注的是OnClick里的Business logic。 有什么问题有与我联系或留言。转载请保留帖子全部信息。 Extending ArcGIS command: a case tutorialArcGIS command扩展:ArcGIS 9.2/C# 2的实现 为什么要做扩展? 很简单,ArcGIS提供了通用的功能,但不可能提供每个大家需要的功能。而且,对一些专业(如水文)也许最实用的功能都没有。这时候便需要对现有的ArcGIS进行扩展。 如何扩展? 有很多方法了,比如AML来扩展ArcInfo Workstation——我以前写过一个AML的简要指南,Google应该能找到。在Desktop下,可以用VBA扩展,或者用任何支持COM的现代语言来扩展。这里用Visual Studio C# 2005 Express来开发。对于独立应用程序,应当购买ArcEngine。ArcEngine可以认为是ArcObjects的一个子集。 准备工作 需要ArcGIS desktop .net developer kit。如果最初安装ArcGIS 9.2的时候没有安装上,那么到安装/删除程序里去重新修改安装。注意事先机器上得已经存在.net framework SDK,如果没有,安装ArcGIS看不到.net developer kit选项。.net SDK不同于平时大家安装的redistribution .net framework runtime。请到微软官方网站下载。 安装Visual Studio C# 2005 Express,建议在安装ArcGIS desktop .net developer kit之前进行,ArcGIS desktop .net developer kit将在Visual Studio C# 2005 Express上生成一些项目模板(如ArcMap class library),应用这些模板进行开发会节省很多时间。 我们的工作 如图1所示,要在一个Document里生成多个Map(多个Data Framework),Map里的内容是时间序列的小时降水量(不同的Raster Dataset)。右图仅演示了1天24小时的图。我们的挑战是要做10天,而且必须各个图采用同样的图例。 解决方法 先设计好一个Data Frame,设置好Legend(不能是sketch,否则系列图就没有意义)。然后复制24份Data Frame,应用ArcMap的页面排版功能进行排版。然后将此文档复制10份(10天)。现在的问题是如何去更改每个Data Frame里的Data Source。我们需要的是实现一个批量处理的方法。采用ArcObjects进行二次开发,生成一个Command来完成这个事情,是个不错的方案。 建立一个新项目,点击File>New Project...(图2)。因为我们只想进行基于ArcMap的扩展,这里选择ArcMap Class Library(图3),敲入项目名称“MyArcGISClassLibrary”(不包括引号)。一般而言,项目按功能进行归类,一个可以实现很多的Command或者Tools扩展。所以没有必要对每个Command或者Tool都建项目。 在随后出现的ArcGIS Project Wizard(图4),添加必要的引用。这里选择ESRI.ArcGIS.ArcMap,ESRI.ArcGIS.ArcMapUI,ESRI.ArcGIS.Carto,ESRI.ArcGIS.DataSourceGDB,ESRI.ArcGIS.DataSourceRaster,ESRI.ArcGIS.Framework,ESRI.ArcGIS.Geodatabase,ESRI.ArcGIS.System。这些都是常用的库,添加的这些库,会出现在VS项目的Reference里。如果这里不添加,也可以以后根据需要再行添加(如图4.1)。需要注意的是,这里用的ESRI.ArcGIS.DataSourceGDB是9.2新出来的File Geodatabase,据称比Personal Geodatabase性能要好,而且有更大的存储许可。点击Finish结束。 该向导帮助我们添加了必要的Reference,并新建了Class1.cs。但我们不需要它。如图5所示,删除。 移动Solution Explorer窗口的项目上,如图6,添加一个新项,点击New Item...。在新弹出的窗口中选择Base Command(图7)。并设置名称为"BatchedChangeDatasource.cs"。在New Item Wizard Options里选择ArcMap Command(如图8)。 点击OK,Wizard生成足够多的东西(如图9),我们在此基础上再写一些代码以完成我们的预期功能。
(下一节我们将介绍代码的作用,和如何添加自己的功能以实现既定目标。) 11/22/2007 GeneratePolygonsByPoints utility Purpose: to generate polygons (rectangles) by connecting neighboring points Author: Zhuotong Nan Email: zhn1@pitt.edu Date: Nov 21, 2007 ver: 1.0.0 Usage: GeneratePolygonsByPoints [data_file_name] {output shapefile name} Rows*Cols (for ex, 260*250): (enter numbers of rows and cols for the source data file with a format rows*cols. Incorrect input will stop the tool.) data_file_name: source data file name; path can be included. output shapefile name: optional, as its literal stated. path can be includes. Supporting environment: Microsoft dotnet framework 2.0, ArcGIS 9.2 with dotnet assemblies, as well as a valid ArcInfo license. Remarks: Data file should be organized row by row (you should know exact row and column number, which will be required to be entered after starting), starting from lower left corner. In my initial case, the data file is generated by a modified Read_XMRG2 utility for XMRG radar data file. The modified Read_XMRG2 will generate data with geographical coordinates instead of HRAP coordinates as does original Read_XMRG2. Anyway, GeneratePolygonsByPoints will also run against data file generated by original Read_XMRG2, however, with output shapefile being in HRAP coordination. Data file content looks like following: -121.177570 37.897155 0.000000 -121.132468 37.907464 0.000000 -121.087345 37.917746 0.000000 -121.042201 37.928001 0.000000 -120.997037 37.938229 0.000000 The first column is longitude, second latitude, and the third precipitation value. The first two columns represent that cells' lower left coordinations. The first row indicates the lower left cell; second is the next cell right to the first cell; after finishing a row, then begin a row up the first row, and move upwards. Output shapefile will be of geographic NAD83 datum. The first two columns will be converted to points' geographic location. Values (precp value in above example) will be lost. A new field named "Index" will be generated to record this polygon's lower left corner's coordination with a format of "lat_lon", for ex. 37.897155_-121.177570 for the first created cell. However, you cannot depend on this field to link original source data file. In order to do link, you can "ID" field in shapefile attribute table, which increases by one in consitence with source data file. As stated above, each cell is referred by its lower left corner's coordination. The most upper cells cannot be generated due to missing of necessary points (we only have lower edge's coord). Likewise, the most right cells are also missed. The distribution also includes a test data file: xmrg0101199900z.out, with a 39*48 (rows*cols) dimension. For more information, please contact the author at zhn1@pitt.edu. 10/12/2007 ArcIMS ArcXML 元数据搜索中文关键词问题或者在c#代码中直接用中文字符构建 SEARCH_METADATA将搜索失败,提示非法的ArcXML 解决方法是使用中文的unicode表示,即旞类似的方式 提供了一个转换函数: /// <summary> /// 将汉字变成 黑&27827;的ascii编码 /// </summary> /// <param name="text"></param> /// <returns></returns> public static string UnicodeEncode(string text) { char[] chars = System.Web.HttpUtility.HtmlEncode(text).ToCharArray(); System.Text.StringBuilder result = new System.Text.StringBuilder(text.Length + (int)(text.Length * 0.1)); foreach (char c in chars) { int value = Convert.ToInt32(c); if (value > 127) result.AppendFormat("&#{0};", value); else result.Append(c); } return result.ToString(); } ESRI本身提供的metadata explorer搜索中文关键词时有问题,是因为它的代码将中文解释成了 &26789;类似,而不是梥,可能是将&再次解释了,搜索时将不返回结果。不知道9.1及以后版本的arcims metadata explorer里是否已经更正。 10/11/2006 ArcCatalog使用iso元数据标准为了系统只使用iso标准,ArcCatalog(以下称ac)做为发布端,需要做如下工作:
8/4/2006 SQL server master库损坏的解决方案SQL server 2k master db corruption due to power cutoff, causing sql server cannot start up. In this server, ArcSDE 9 and ArcIMS 9 are associated with Sql Server 2k sp4. and worse, no backup have been created prior to this disaster.
solution:
1. Backup possibly effected dbs, i.e., sde db, and westdc db. 2. run rebuildm.exe to reconstruct the master db. all logins are lost after that operation. sde amd westdc dbs cannot be found in the rebuilt master db. 3. attach the original sde db and westdc db using sa as the db owner. 4. create lost logins, for example, westdc, sde, etc. Fortunately, I have backed up all these information. 5. using enterprise manager, open sde and westdc dbs, isolated users can be found under the users leaf. So we have to assign the appropriate logins to those isolated users. use commands as follow: USE sde;
GO sp_change_users_login @Action='Report'; GO USE westdc;
GO sp_change_users_login @Action='update_one', @UserNamePattern='westdc', @LoginName='westdc'; GO the first set of commands is used to report the isolated users in database sde. the second set of commands will assign an existing login named westdc to the isolated user westdc.
6. restart the arcsde service, then arcims services. DONE! Lessons: We always are required to backup databases in a regular interval. 6/21/2006 南宅影像图最近google Earth更新了一些数据,浏览到我家的时候,发现可能是由于附近有个海事边哨,覆盖我老家的是一景分辨率较高的影像(估计是QuickBird这类),可以分辨到我们家的屋顶,剪裁下来与大家共享。 |
|
|