Select to view content in your preferred language

Select Data from one feature based on a different feature that is selected

585
1
05-07-2010 05:19 AM
PaulMcBride
Occasional Contributor
Anyone have any suggestion of how to select a point feature by attribute based upon a selected polygon feature.  Both features have identical fields that correspond to each other but I can't get them to talk to one another. 

The purpose of the tool is to select a polling location based upon the user's address.  I have the model/script to select the voting precinct, but now need to select the polling location based on that selected voting precinct.
0 Kudos
1 Reply
DarshaHardy
Emerging Contributor
Not sure if this is what you're after

Outer loop though feature class to extract an attribute from specified field
Use value to construct 'where' clause
Inner loop selects features(s) in second feature class

Selection syntax is assuming a string field in a shapefile and I'm using ArcGIS 9.2

import arcgisscripting
gp = arcgisscripting.create()
gp.OverwriteOutput = 1

fcPoly = "C:/test_polygons.shp"
fcPoint = "C:/test_points.shp"
myField = "TEST_FIELD"

gp.MakeFeatureLayer(fcPoint,"fcPoint_lyr")

outers = gp.SearchCursor(fcPoly)
outer = outers.Next()
# Print road name and road type
while outer:
    myVal = outer.GetValue(myField)

    strWhere = '"' + myField + '"' + " = '" + myVal + "'"   
    gp.SelectLayerbyAttribute_management("fcPoint_lyr", "NEW_SELECTION", strWhere)
    
    inners = gp.SearchCursor("fcPoint_lyr")
    inner = inners.Next()
    while inner:
        # do stuff here with the selected rows
        inner = inners.Next()      
   
    outer = outers.Next()

print "done looping"
0 Kudos