Select to view content in your preferred language

Return value of a variable

669
3
Jump to solution
04-03-2012 01:08 PM
ChadFoster
Deactivated User
I have a script for Parcel Noticing , it uses a subject parcel, determines its size, and then starts selecting parcels within a specified radius.  If 31 parcels are not captured within the initial radius, then the radius increases by 25 feet until 31 total parcels are selected. 
I am enclosing the script and have a question, I want to start scripting the mapping portion of the noticing and would like to use the distance of the final radius later on, but can not figure out how to capture this number.  Will someone please look at this and try to provide some feedback?

import arcpy  layer = arcpy.GetParameterAsText(0) apn = arcpy.GetParameterAsText(1) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames (mxd, "LAYERS")[0]  def select_parcels(layer, distance):     while True:         print_search_distance(distance)         arcpy.SelectLayerByLocation_management(layer, "WITHIN_A_DISTANCE", layer, "%i Feet"%(distance),"NEW_SELECTION")         if get_count(layer):             r = arcpy.GetCount_management(layer)             cnt = int(r.getOutput(0))             print "%i Features selected at a distance of %i Feet."%(cnt, distance)             arcpy.AddMessage("%i Features selected at a distance of %i Feet."%(int(cnt),distance))             break         layer = reselect(layer, selstring)         distance += 25 ## End select_parcels function  def get_count(layer):     result = arcpy.GetCount_management(layer)     if int(result.getOutput(0)) >= 31:         return True     else:         return False ## End get_count function  def reselect(layer, selection_string):     arcpy.SelectLayerByAttribute_management(layer,'CLEAR_SELECTION')     arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", selection_string)     return layer ## End clear_selection function  def print_search_distance(distance):     arcpy.AddMessage('Searching %i Feet'%(distance))   arcpy.AddMessage(apn) selstring = """TAG = '{0}'""".format(apn) arcpy.AddMessage("Selection string = " + selstring)  if not arcpy.Describe(layer).datatype == 'FeatureLayer':     layer = arcpy.MakeFeatureLayer_management(layer, 'flayer')  arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", selstring)  rows = arcpy.SearchCursor(layer) n = 0 val = 0.0 for row in rows:     val = val + row.tmp_pacres     n = n + 1  arcpy.AddMessage("Sum of PACRES = " + str(val)) if n > 1:     arcpy.Message("More than one record found")   if val <= 1.0:     select_parcels(layer, 300) elif (val > 1.0 and val <= 40.0):     select_parcels(layer, 600) else:     select_parcels(layer, 1200)



Thanks,

Chad
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Alum
Don't you calculate the radius in the function 'select_parcels'? Return the distance...

def select_parcels(layer, distance):     while True:         print_search_distance(distance)         arcpy.SelectLayerByLocation_management(layer, "WITHIN_A_DISTANCE", layer, "%i Feet"%(distance),"NEW_SELECTION")         if get_count(layer):             r = arcpy.GetCount_management(layer)             cnt = int(r.getOutput(0))             print "%i Features selected at a distance of %i Feet."%(cnt, distance)             arcpy.AddMessage("%i Features selected at a distance of %i Feet."%(int(cnt),distance))             break         layer = reselect(layer, selstring)         distance += 25     return distance ## End select_parcels function


And assign it to a variable ('radius')...
if val <= 1.0:     radius = select_parcels(layer, 300) elif (val > 1.0 and val <= 40.0):     radius = select_parcels(layer, 600) else:     radius = select_parcels(layer, 1200)


edit: "distance of the final radius" - are you looking for the radius or circumference of your final circle?

View solution in original post

0 Kudos
3 Replies
Zeke
by
Honored Contributor
I don't know if it's a property you retrieve the value from, although it seems like it should be.
Anyway, you could keep track of the number of times you increase the radius and just add then up. Or, if the buffer is a circle, get the circumference (shape.length) and use this formula to get the radius:
R=c/pi/2 

#R = radius, c = circimference

Caveat - I'm not a mathematician, formula from Google.
0 Kudos
DarrenWiens2
MVP Alum
Don't you calculate the radius in the function 'select_parcels'? Return the distance...

def select_parcels(layer, distance):     while True:         print_search_distance(distance)         arcpy.SelectLayerByLocation_management(layer, "WITHIN_A_DISTANCE", layer, "%i Feet"%(distance),"NEW_SELECTION")         if get_count(layer):             r = arcpy.GetCount_management(layer)             cnt = int(r.getOutput(0))             print "%i Features selected at a distance of %i Feet."%(cnt, distance)             arcpy.AddMessage("%i Features selected at a distance of %i Feet."%(int(cnt),distance))             break         layer = reselect(layer, selstring)         distance += 25     return distance ## End select_parcels function


And assign it to a variable ('radius')...
if val <= 1.0:     radius = select_parcels(layer, 300) elif (val > 1.0 and val <= 40.0):     radius = select_parcels(layer, 600) else:     radius = select_parcels(layer, 1200)


edit: "distance of the final radius" - are you looking for the radius or circumference of your final circle?
0 Kudos
ChadFoster
Deactivated User
Darren,

Thanks so much, that worked great!!
0 Kudos