操作方法
在 ArcGIS Pro 中,可使用“计算字段”工具中的 Python 解析器从字符串字段中提取前导文本、中间文本和结尾文本。 这对于数据管理、提高可读性和识别唯一标识符非常有用。 例如,在处理文本字段中包含详细位置描述的数据集时,提取文本的不同部分可简化空间查询和分类任务。
本文提供了使用“计算字段”工具中的 Python 解析器从字符串字段中提取前导文本、中间文本和结尾文本以将其填充到另一个字段中的工作流。 在本例中,从名为 Location_Description 的字段中提取结尾文本。
extract_characters(!Field_Name!)
def extract_characters(sentence):
space_index = sentence.find(' ')
first_word = sentence[:space_index] if space_index != -1 else sentence
num_characters = len(first_word)
extracted_characters = first_word[:num_characters]
return extracted_characters
def extract_characters(sentence):
space_index = sentence.find(' ')
last_space_index = sentence.rfind(' ')
middle_word = sentence[space_index + 1:last_space_index] if space_index != -1 and space_index != last_space_index else sentence
num_characters = len(middle_word)
extracted_characters = middle_word[:num_characters]
return extracted_characters
def extract_characters(sentence):
space_index = sentence.rfind(' ')
last_word = sentence[space_index + 1:] if space_index != -1 else sentence
num_characters = len(last_word)
extracted_characters = last_word[:num_characters]
return extracted_characters

下图显示了属性表中的 Ext_Description 字段,其中包含从 Location_Description 字段中提取的结尾文本。

文章 ID: 000031954
获取来自 ArcGIS 专家的帮助
立即开始聊天