Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a multipart feature class of cities. I want to run a search cursor on a cities feature class where:

  1. one city is selected and a select layer by location is run to select all parcels that are within a certain distance X;
  2. Values from the selected parcels are then summed together;
  3. move on to the next city record

Currently, I am having trouble getting my select by location statement correct. Instead of only selecting the parcels that are within distance X of one city, it's selecting all the parcels that are within distance X of all the cities in the feature class.

    arcpy.MakeFeatureLayer_management(city, c_layer)
    cCursor = arcpy.SearchCursor(c_layer)
    print "Created search cursor on c_layer"

arcpy.MakeFeatureLayer_management(parcel, p_layer)

for row in cCursor:
    geoName = row.getValue("GEO_NAME")
    print geoName
    geoID = row.getValue("GEO_ID")
    print geoID     

    arcpy.SelectLayerByLocation_management(p_layer, "WITHIN_A_DISTANCE", c_layer, search_radius, "NEW_SELECTION")
    print "Completed select by location on p_layer"
    y = arcpy.GetCount_management(p_layer)
    print y
share|improve this question
    
I think the easiest solution to this is to convert multipart to single part, so 1 row in your table is 1 city. Use this tool to convert to single part. –  Hornbydd Sep 10 '13 at 15:42
    
I tried using the multipart to singlepart management on the city layer earlier and it still didn't work. –  user21681 Sep 10 '13 at 15:49
    
OK assuming you are working from single part features, what exactly is search_radius set to? I think it should be in the format of "1000 Meters" and not just "1000". Are your datasets in different projections? For example you are attempting to do a spatial selection from a dataset that is in meter units onto something that is in decimal degrees. –  Hornbydd Sep 10 '13 at 16:00
    
My search_radius is defined as: search_distance = "5" search_units = "METERS" search_radius = str(search_distance) + " " + search_units All the files have the same projection. –  user21681 Sep 10 '13 at 16:17
    
what are you doing with geoName and geoID? You get them, print them and appear to do nothing else with them. Also your selectbylocation is within the cursor loop but nothing alters. Did you intend to have the cursor to select a city with the geoID and THEN use that selected point to select parcels within 5m? If so you need to put in a selectbyattribute call before the selectbylocation. –  Hornbydd Sep 10 '13 at 17:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.