添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
跑龙套的葫芦  ·  D3.js SVG JSON ...·  1 年前    · 
腼腆的手链  ·  debian下编译安装poco - ...·  2 年前    · 
叛逆的乒乓球  ·  excel - How to ...·  2 年前    · 

Hi All,

I'm new to python scripting and I was wondering if there is a way to select features with a unique combination of values from multiple fields. I would like to take each selection set of features and complete additional geoprocessing tasks on them and move on to the next selection of features with the same field values and repeat.

The closest I have got so far is to produce a list of values that are unique in the feature class. I feel like this is not heading in the direction I would like it to. I am open to running the python in or outside of ArcGIS Pro.

import arcpy
import numpy

fc = "C:\Temp\ProjectModel.gdb\TempAvgs_ExportFeatures1"

arr = arcpy.da.FeatureClassToNumPyArray(fc, ['GeologicUnit', 'Analyte'])

uniqueRows = numpy.unique(arr)
print uniqueRows

The arcpy way of doing this:

import arcpy
fc = "C:\Temp\ProjectModel.gdb\TempAvgs_ExportFeatures1"
fields = ['GeologicUnit', 'Analyte']
unique_combinations = {
    for row in arcpy.da.SearchCursor(fc, fields)
for unit, analyte in unique_combinations:
    print(unit, analyte)
    # create a layer with all rows of that values combination
    sql = f"GeologicUnit = {unit} AND Analyte = {analyte}"  # add single quotes around {unit} and {analyte} if those fields are strings
    layer = arcpy.management.MakeFeatureLayer(fc, f"{unit}_{analyte}", sql)
    # do your geoprocessing on this layer
    arcpy.analysis.Intersect([layer, some_other_layer], f"Intersect_{unit}_{analyte}")

concatenate the two fields into a new field (comma and or space separated), then export to an array.  Bring over the original fields and any other fields that you want for the analysis

Or, you can do the searchcursor thing, or use SplitByAttribute tool if you want to process as separate files (using the new field as the split field)

Split By Attributes (Analysis)—ArcGIS Pro | Documentation

But if you aren't working with complex geometry functionality, it is sometimes easier to just do the work in numpy (or even pandas).  You can always use arcpy's ExtendTable to bring back tabular results into Pro

The arcpy way of doing this:

import arcpy
fc = "C:\Temp\ProjectModel.gdb\TempAvgs_ExportFeatures1"
fields = ['GeologicUnit', 'Analyte']
unique_combinations = {
    for row in arcpy.da.SearchCursor(fc, fields)
for unit, analyte in unique_combinations:
    print(unit, analyte)
    # create a layer with all rows of that values combination
    sql = f"GeologicUnit = {unit} AND Analyte = {analyte}"  # add single quotes around {unit} and {analyte} if those fields are strings
    layer = arcpy.management.MakeFeatureLayer(fc, f"{unit}_{analyte}", sql)
    # do your geoprocessing on this layer
    arcpy.analysis.Intersect([layer, some_other_layer], f"Intersect_{unit}_{analyte}")