HowTo: Extract values from a field and write them to a text file using Python at ArcGIS 10.x
【相关信息】
Article ID: 41442
Software:
ArcGIS - ArcEditor 10
ArcGIS - ArcInfo 10
ArcGIS - ArcView 10
ArcGIS for Desktop Advanced 10.1, 10.2
ArcGIS for Desktop Standard 10.1, 10.2
ArcGIS for Desktop Basic 10.1, 10.2
Platforms:
Windows Vista, Server 2008, Windows 7, Windows 8, Server 2012
【问题描述】
Instructions provided describe how to select a feature by an attribute, select all the features that share a boundary with it, and then export the values of all of the features to a text file. This article is specific to using the ArcPy module installed with ArcGIS 10.x.
To complete this procedure using Python requires the use of the Search Cursor method to iterate through the values of the field.
Article ID: 41442
Software:
ArcGIS - ArcEditor 10
ArcGIS - ArcInfo 10
ArcGIS - ArcView 10
ArcGIS for Desktop Advanced 10.1, 10.2
ArcGIS for Desktop Standard 10.1, 10.2
ArcGIS for Desktop Basic 10.1, 10.2
Platforms:
Windows Vista, Server 2008, Windows 7, Windows 8, Server 2012
【问题描述】
Instructions provided describe how to select a feature by an attribute, select all the features that share a boundary with it, and then export the values of all of the features to a text file. This article is specific to using the ArcPy module installed with ArcGIS 10.x.
To complete this procedure using Python requires the use of the Search Cursor method to iterate through the values of the field.
1 个回复
易智瑞技术支持
赞同来自:
Below are the general steps for the procedure followed by code examples using a zip code polygon shapefile.
1.Set up the environment and define needed variables:
2.Convert the input shapefile into a Feature Layer, so it can be used in the Select Layer by Attributes and Location tools.
3.Create the text file to which the output is to be written. If it does not already exist, Python will create it in this step.
4. Build the first Search Cursor to iterate through the polygon shapefile that contains the values in the field. There is a second kind of cursor that can be used at version 10.1 and later; skip to the final step for that sample.
5.Construct a loop that runs all the needed processes on each value from the field, in this case, Select Layer by Attribute and Select Layer by Location. The Select by Attribute needs a specific value from the field for each iteration, so an expression variable (exp) is created for this.
6.Build another search cursor within this loop to iterate through all the values associated with the rows found in the Select by Location process and write those values in the text file. This step is completely contained within the loop.
7.Outside of the loop, close the text file and release all the variables from memory.
8.If using the Data Access Search Cursor in this process, the final part of the code is similar to this:
【其它相关参考】
【创建及修改时间】
Created: 7/25/2013
Last Modified: 8/8/2013
【原文链接】
http://support.esri.com/en/kno ... 41442
要回复问题请先登录或注册