2

I am building a script to integrate into a model that iterates through data. I've been able to get two submodels to iterate through the original data and create large numbers of features in file geodatabase. One submodel creates point features the other creates polygons. I would like to select features (one point and one polygon) based on similar names from the file geodatabase. The point features are civic addresses that fall within a catchment area of each facility. The polygon is the 25 min drive time (service area) from each facility. The point ID of the facility has been integrated into the names of the points and the polygons. I was hoping to select the features from the geodatabase based on the actual name of the feature class which contains the point ID as seen in the screen shot below. Ex: SA207900045_01 polygon the point ID is 207900045. The corresponding point file is nscafPL207900045_01. The point and polygon features do not contain the point ID information. I was hoping something could be done with 'list features' in python then 'select where' the names are the same but I'm having no luck finding this function. I want to be able to loop this selection. So I would select the point and polygon that have similar names then feed them into a tool in model builder then loop back and find another pair of point and polygon features and feed them into the tool. Is there anyway to do this in python or model builder? I'm new to both. Below is an image of some sample data. I'm using ArcGIS for desktop 10.2.2enter image description here

  • 1
    Can you show us a screenshot of your attribute table. Also what what field has the Name in it, and what name do you want to look for? – ed.hank Feb 24 '16 at 16:39
  • I was hoping to select based on the actual name of the feature class which contains the point ID as seen in the screen shot above. Ex: SA207900045_01 polygon the point ID is 207900045. The corresponding point file is nscafPL207900045_01. The point and polygon features do not contain the point ID information. I was hoping something could be done with 'list features' in python then 'select where' the names are the same but I'm having no luck finding this function. – MMcInnis Feb 24 '16 at 17:51
  • 1
    Can you please edit your question and add this relevant information? Also are you wanting to select all features in each matching layer, or specific features based on some other criteria? – Midavalo Feb 24 '16 at 18:25
  • thanks for the comment. I've added the info the question and I think I've answered you're question. I'm trying to select a pair of point and polygon features to feed into a tool. I then want to loop back and find another pair of point and polygon features to feed into the tool. – MMcInnis Feb 24 '16 at 18:34
  • how do we identify the features you want to select? or is it all features in that one layer/feature class? – Midavalo Feb 24 '16 at 19:11
4

An arcpy/python way to find like named layers in a gdb would be to use the string .find() method, see example below:

import os
commonSearchText = ['207900045', 'xyz', '1234']
workspace = "C:/Temp/New File Geodatabase.gdb"
for nameX in commonSearchText:
    foundLayersList = []
    walk = arcpy.da.Walk(workspace, datatype="FeatureClass")
    for dirpath, dirnames, filenames in walk:
        for filename in filenames:
            found = filename.find(nameX)
            if found >-1:
                foundLayersList.append(os.path.join(dirpath, filename))
    # next do something with two found layers in the foundLayers list....

Alternatively, you could do this in one line combining the if condition and in method:

# same code as noted above before walk statement
walk = arcpy.da.Walk(workspace, datatype="FeatureClass")
for dirpath, dirnames, filenames in walk:
    for filename in filenames:
        if commonSearchText in (filename):
            foundLayersList.append(os.path.join(dirpath, filename))
# ....

You could put all your common names in the commonSearchText list and loop over those if all layers are in one gdb.

  • Can I use this as a script in model builder to find features with similar names (not identical) in a file geodatabase select them and feed them into the next tool in the model? – MMcInnis Feb 24 '16 at 19:26
  • Your question has changed focus from map layers to gdb layers. Instead of using arcpy.mapping.ListLayers method you could use arcpy.da.walk to loop through layers in a gdb and use the various examples I noted above to identify like layer name values (desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-data-access/…). Yes,you may call a arcpy/python script from a Model. – artwork21 Feb 24 '16 at 22:38
  • I'm not sure I understand the examples you give and I would like to select the features from the file geodatabase, not the map doc. Specifically, commonNames = ['207900045, 'xyz', '1234']. what is 'xyz' and '1234' referencing? and is there a way for it to automatically select the next feature name while ignoring the beginning of it's name? – MMcInnis Feb 26 '16 at 12:48
  • @MMcInnis, updated my answer to search against gdb instead of layers in mxd – artwork21 Feb 26 '16 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.