
如何通过DOS命令、EXCEL、ArcGIS的Command line批量生成所需文件。
此方法适用于由同一源数据利用ArcGis的Command获得大量数据。
首先,介绍DOS命令的用处,主要是用来获取用于分析、裁切、提取等等的数据(以下简称目标数据)的路径及文件名、以及用于被分析、裁切、提取等等的数据(以下简称源数据)的路径及文件名,以及经分析、裁切、提取等等获得的数据(以下简称结果数据)的路径及文件名。
一、运用到的DOS命令cd、dir、md、copy。运行Dos命令窗口,在XP系统下可通过“开始”的“运行”中敲入“CMD”启动。
(1)“cd”命令,用于改变DOS命令窗口的当前路径。
当Dos命令窗口启动后,其显示的当前路径默认的为“C:\\Documents and Settings\\****”(****为你登入系统的用户名,不影响程序运行)
可以再“C:\\Documents and Settings\\****>”敲入“cd”,空格空一格,再敲入(或拷贝右键粘贴)目标数据、源数据的路径(最好二者在同一路径下),然后回车,然后再敲入目标数据、源数据的路径的盘符加冒号如“F:”,这样DOS命令窗口显示的当前路径就是目标数据、源数据的路径。
(2)“dir”命令:为显示某一路径下文件夹及文件,用于获得目标数据、源数据的路径及文件名。
当(1)操作完成后,在DOS中敲入“dir >1.xls /b/s”,会在目标数据、源数据的路径下生成一个“1.xls”,用EXCEL打开,可以看到“1.xls”中数据为目标数据、源数据的路径下所有文件夹、文件及文件夹内的文件的路径及名称。从“1.xls”中筛选出需要应用到目标数据、源数据的路径及名称。
(3)“md”命令:为创建文件夹,用于创建存放结果数据的文件夹。
如在DOS中敲入“md F:\est”,就会在F盘根目录下创建一个“test”的文件夹。
(4)“copy”命令:为拷贝文件,可用于拷贝模板文件到所要存放的路径下,并改成你所要的文件名。
如在DOS中敲入“copy F:\est.mdb F:\est\est1.mdb”,会把F盘根目录下的“test.mdb”拷贝到“F:\est”中,并改名为test1.mdb
二、ArcGIS的Command line
(一)Command line窗口可以在菜单栏“Window”下“Command line”中或工具栏的“Show/hide command line window”启动或隐藏。
(二)以裁切功能介绍如何通过Command line来裁切数据。
裁切功能的command line 的语法如下:
Clip_analysis 其中参数 {cluster_tolerance}为容限值,为可选项。 在Command line 的输入如下内容: Clip_analysis F:\est_orig.shp F:\est_clip.shp F:\est_ClipResult.shp 然后按回车,就可以得到以test_orig.sh为数据源,以test_clip.shp为裁切数据,通过裁切功能获得裁切后的数据test_ClipResult.shp (三)Command line中的功能命令与arctoolbox中的自带功能工具对应的,如果不清楚功能命令的拼写,可以在Command line中敲入对应的arctoolbox中的工具名,Command line会自动索引到对应的Command line的命令。 三、EXCEL作用 EXCEL作用主要是在EXCEL中设置好需要运行的DOS、ArcGIS的Command line 命令的参数语句。 如下表以clip(裁切)为例。 注:command line 命令参数间的语句要用空格分隔。 四、综合例子 以clip_analysis命令为例,以F盘test文件夹下test_orig.shp为被裁切数据,以F盘test文件夹下clip文件夹内的test_clip1.shp、test_clip2.shp、test_clip3.shp、test_clip4.shp、test_clip5.shp为裁切数据,裁切结果数据分别对应放在test文件夹下clip1文件夹、clip2文件夹、clip3文件夹、clip4文件夹、、clip5文件夹内的ClipResult1.mdb、ClipResult2.mdb、ClipResult3.mdb、、ClipResult4.mdb、ClipResult5.mdb(为Personal Geodatabase格式)内,每个结果数据的文件名分别为Result1、Result12、ClipResult3、Result4、Result5,其中clip1文件夹、clip2文件夹、clip3文件夹、clip4文件夹、、clip5文件夹以及Clip1.mdb、Clip2.mdb、Clip3.mdb、、Clip4.mdb、Clip5.mdb都未创建。 步骤: (一)获取test文件夹内的test_orig.shp,及clip文件夹内的test_clip1.shp、test_clip2.shp、test_clip3.shp、test_clip4.shp、test_clip5.shp的文件路径及名称 1、运行DOS命名窗口,在“开始”的“运行”栏中敲入CMD,启动DOS命令窗口; 2、改变DOS命名窗口的当前路径为F:\est, (1)在DOS命令窗口中敲入CD F:\est(注,F:\est可以直接拷贝右键粘贴在CD后)然后回车,CD与F:\est间需要空格一格 (2)在DOS命令窗口中敲入要转到的路径盘符 F:(为“F”加英文的“:“),然后回车,DOS窗口的当前路径就转到F:\est。 3、 获取F:\est内的文件数据信息。 在DOS命令窗口“F:\est>”后敲入 dir >1.xls /b/s(dir、>1.xls“注为英文的大于号)”、/b/s间都要空格一格),打开F:\est下新生成的1.xls文件,其内容如表1. 通过筛选整理得表2内容: (1)通过DOS的MD创建存放的文件夹,所有语句表3。 (2)在(1)创建文件夹基础上,拷贝创建存放的文件。 首先先创建个MDB文件,如F:\est\clipResult.mdb,然后通过COPY拷贝改名为特定文件名的文件。所有语句如表4. (三)接下来就是要整理command line 中的clip_analysis的语句 (1)在(二)的(2)步骤基础上确定 以上就是ARCGIS不懂编程也可以批量生成数据文件的方法说明。 若有不明之处,可以Email:magicwls@126.com
可以把上表中的command line 命令语句的五条记录直接拷贝到Command line 窗口中,按回车,这样就实现了批处理的功能,可以连续生成5个结果文件。{cluster_tolerance} command line 命令语句 F:\est_orig.shp F:\est_clip1.shp F:\est_ClipResult1.shp Clip_analysis F:\est_orig.shp F:\est_clip1.shp F:\est_ClipResult1.shp F:\est_orig.shp F:\est_clip2.shp F:\est_ClipResult2.shp Clip_analysis F:\est_orig.shp F:\est_clip2.shp F:\est_ClipResult2.shp F:\est_orig.shp F:\est_clip3.shp F:\est_ClipResult3.shp Clip_analysis F:\est_orig.shp F:\est_clip3.shp F:\est_ClipResult3.shp F:\est_orig.shp F:\est_clip4.shp F:\est_ClipResult4.shp Clip_analysis F:\est_orig.shp F:\est_clip4.shp F:\est_ClipResult4.shp F:\est_orig.shp F:\est_clip5.shp F:\est_ClipResult5.shp Clip_analysis F:\est_orig.shp F:\est_clip5.shp F:\est_ClipResult5.shp
4、F:\est\\1.xls F:\est\\clip F:\est\est_orig.dbf F:\est\est_orig.prj F:\est\est_orig.sbn F:\est\est_orig.sbx F:\est\est_orig.shp F:\est\est_orig.shp.xml F:\est\est_orig.shx F:\est\\clip\est_clip1.dbf F:\est\\clip\est_clip1.prj F:\est\\clip\est_clip1.shp F:\est\\clip\est_clip1.shp.xml F:\est\\clip\est_clip1.shx F:\est\\clip\est_clip2.dbf F:\est\\clip\est_clip2.prj F:\est\\clip\est_clip2.shp F:\est\\clip\est_clip2.shp.xml F:\est\\clip\est_clip2.shx F:\est\\clip\est_clip3.dbf F:\est\\clip\est_clip3.prj F:\est\\clip\est_clip3.shp F:\est\\clip\est_clip3.shp.xml F:\est\\clip\est_clip3.shx F:\est\\clip\est_clip4.dbf F:\est\\clip\est_clip4.prj F:\est\\clip\est_clip4.shp F:\est\\clip\est_clip4.shp.xml F:\est\\clip\est_clip4.shx F:\est\\clip\est_clip5.dbf F:\est\\clip\est_clip5.prj F:\est\\clip\est_clip5.shp F:\est\\clip\est_clip5.shp.xml F:\est\\clip\est_clip5.shx
(二)现在需要创建裁切结果数据存放的文件夹及文件。{cluster_tolerance} command line 命令语句 F:\est\est_orig.shp F:\est\\clip\est_clip1.shp F:\est\est_orig.shp F:\est\\clip\est_clip2.shp F:\est\est_orig.shp F:\est\\clip\est_clip3.shp F:\est\est_orig.shp F:\est\\clip\est_clip4.shp F:\est\est_orig.shp F:\est\\clip\est_clip5.shp
将5条DOS命令语句直接拷贝右键粘贴到DOS窗口中,就可以自动生成五个文件夹创建文件夹命令语句 md F:\est\\clip1 md F:\est\\clip2 md F:\est\\clip3 md F:\est\\clip4 md F:\est\\clip5
将5条DOS命令语句直接拷贝右键粘贴到DOS窗口中,就可以自动生成五个文件。创建文件命令语句 copy F:\est\\clipResult.mdb F:\est\\clip1\ClipResult1.mdb copy F:\est\\clipResult.mdb F:\est\\clip2\ClipResult2.mdb copy F:\est\\clipResult.mdb F:\est\\clip3\ClipResult3.mdb copy F:\est\\clipResult.mdb F:\est\\clip4\ClipResult4.mdb copy F:\est\\clipResult.mdb F:\est\\clip5\ClipResult5.mdb
(2)表5基础上整理command line 中的clip_analysis的命令语句,如表6{cluster_tolerance} command line 命令语句 F:\est\est_orig.shp F:\est\\clip\est_clip1.shp F:\est\\clip1\ClipResult1.mdb\\Result1 F:\est\est_orig.shp F:\est\\clip\est_clip2.shp F:\est\\clip2\ClipResult2.mdb\\Result2 F:\est\est_orig.shp F:\est\\clip\est_clip3.shp F:\est\\clip3\ClipResult3.mdb\\Result3 F:\est\est_orig.shp F:\est\\clip\est_clip4.shp F:\est\\clip4\ClipResult4.mdb\\Result4 F:\est\est_orig.shp F:\est\\clip\est_clip5.shp F:\est\\clip5\ClipResult5.mdb\\Result5
将5条command line 命令语句拷贝粘贴到ArcGIS的command line窗口中,按回车运行就可以批处理生成五个结果。{cluster_tolerance} command line 命令语句 F:\est\est_orig.shp F:\est\\clip\est_clip1.shp F:\est\\clip1\ClipResult1.mdb\\Result1 Clip_analysis F:\est\est_orig.shp F:\est\\clip\est_clip1.shp F:\est\\clip1\\ClipResult1.mdb\\Result1 F:\est\est_orig.shp F:\est\\clip\est_clip2.shp F:\est\\clip2\ClipResult2.mdb\\Result2 Clip_analysis F:\est\est_orig.shp F:\est\\clip\est_clip2.shp F:\est\\clip2\\ClipResult2.mdb\\Result2 F:\est\est_orig.shp F:\est\\clip\est_clip3.shp F:\est\\clip3\ClipResult3.mdb\\Result3 Clip_analysis F:\est\est_orig.shp F:\est\\clip\est_clip3.shp F:\est\\clip3\\ClipResult3.mdb\\Result3 F:\est\est_orig.shp F:\est\\clip\est_clip4.shp F:\est\\clip4\ClipResult4.mdb\\Result4 Clip_analysis F:\est\est_orig.shp F:\est\\clip\est_clip4.shp F:\est\\clip4\\ClipResult4.mdb\\Result4 F:\est\est_orig.shp F:\est\\clip\est_clip5.shp F:\est\\clip5\ClipResult5.mdb\\Result5 Clip_analysis F:\est\est_orig.shp F:\est\\clip\est_clip5.shp F:\est\\clip5\\ClipResult5.mdb\\Result5
