<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Use a cursor to select each row for input into another function. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/use-a-cursor-to-select-each-row-for-input-into/m-p/451924#M35403</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a python tool that uses a select by attribute to get each record of a feature class and then feed that selection into a zonal statistics function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I thought there was a way to use a search cursor and something like row.Shape to select each row, then feed that row into another tool, thereby speeding up the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I can't find any example of using a cursor to select each row then use that selection as in input parameter into another function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Help please.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 May 2012 14:29:29 GMT</pubDate>
    <dc:creator>GerryGabrisch</dc:creator>
    <dc:date>2012-05-18T14:29:29Z</dc:date>
    <item>
      <title>Use a cursor to select each row for input into another function.</title>
      <link>https://community.esri.com/t5/python-questions/use-a-cursor-to-select-each-row-for-input-into/m-p/451924#M35403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a python tool that uses a select by attribute to get each record of a feature class and then feed that selection into a zonal statistics function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I thought there was a way to use a search cursor and something like row.Shape to select each row, then feed that row into another tool, thereby speeding up the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I can't find any example of using a cursor to select each row then use that selection as in input parameter into another function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Help please.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 May 2012 14:29:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-a-cursor-to-select-each-row-for-input-into/m-p/451924#M35403</guid>
      <dc:creator>GerryGabrisch</dc:creator>
      <dc:date>2012-05-18T14:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Use a cursor to select each row for input into another function.</title>
      <link>https://community.esri.com/t5/python-questions/use-a-cursor-to-select-each-row-for-input-into/m-p/451925#M35404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think this is what you are looking for: &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Using_geometry_objects_with_geoprocessing_tools/002z0000001z000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Using_geometry_objects_with_geoprocessing_tools/002z0000001z000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've done some limited stuff with this, and it seems to work well... The idea is the geometry stuff is evaluated in RAM anyway... why not just keep it there as an object you can use instead of always reading/writting a featureclass from disk? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a practical example... an elaboration of some ESRI-authored code (I wrote the search tree part to get at a solution quicker)... Builds approximate maximum inscribed circles inside a polygon featureclass. Note that there is a bug with the ESRI buffer tool in v10.0 that prevents this from "always" being the actual maximum inscribed circle. Also, this code needs some refining on my part, but it should work well as-is.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy, os, sys, traceback

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.overwriteOutput = True
&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Get the input feature class or layer
##&amp;nbsp;&amp;nbsp;&amp;nbsp; inFeatures = arcpy.GetParameterAsText(0)
##&amp;nbsp;&amp;nbsp;&amp;nbsp; outFeatures = arcpy.GetParameterAsText(1)

&amp;nbsp;&amp;nbsp;&amp;nbsp; inFeatures = r"C:\csny490\habitat_frag_analysis_20110919\circles.gdb\mature_interior_forest"
&amp;nbsp;&amp;nbsp;&amp;nbsp; outFeatures = r"C:\csny490\habitat_frag_analysis_20110919\circles.gdb\out_polys"

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Some housekeeping
&amp;nbsp;&amp;nbsp;&amp;nbsp; inDesc = arcpy.Describe(inFeatures)
&amp;nbsp;&amp;nbsp;&amp;nbsp; oidName = str(inDesc.OIDFieldName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if inDesc.dataType == "FeatureClass":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inFeatures = arcpy.MakeFeatureLayer_management(inFeatures)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; sR = inDesc.spatialReference
&amp;nbsp;&amp;nbsp;&amp;nbsp; xyTol = sR.XYTolerance
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.overwriteOutput = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Create the stub output feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(inFeatures,outFeatures)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(outFeatures, "BUFFDIST", "DOUBLE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; OIDFieldName = arcpy.Describe(outFeatures).OIDFieldName
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MinimumBoundingGeometry_management(outFeatures, "in_memory\\br", "RECTANGLE_BY_WIDTH", "NONE", "", "MBG_FIELDS")
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Create dictionary of ORIG_FID,MBR_WIDTH
&amp;nbsp;&amp;nbsp;&amp;nbsp; fidWidthDict = dict([(r.ORIG_FID, r.MBG_WIDTH) for r in arcpy.SearchCursor("in_memory\\br")]) #
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("in_memory\\br")
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Calculate the inscribed circles
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.UpdateCursor(outFeatures)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Processing polygon " + str(row.getValue(OIDFieldName))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inShape = row.shape
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aGeom = arcpy.Geometry()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maxBuffDist = fidWidthDict[row.getValue(OIDFieldName)] / 2
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; minBuffDist = xyTol
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geomList = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (maxBuffDist - minBuffDist) &amp;gt;= xyTol:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; midBuffDist = (minBuffDist + maxBuffDist) / 2.0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Checking buffer distance = " + str(midBuffDist * -1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geomList = arcpy.Buffer_analysis(inShape, aGeom, midBuffDist * -1, "FULL","", "NONE", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(geomList) &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; minBuffDist = midBuffDist
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maxBuffDist = midBuffDist
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geomList = arcpy.Buffer_analysis(inShape, aGeom, (midBuffDist - (2 * xyTol)) * -1, "FULL","", "NONE", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inPoint = arcpy.FeatureToPoint_management(geomList[0], aGeom, "INSIDE")[0]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geomList = arcpy.Buffer_analysis(inPoint, aGeom, (midBuffDist - xyTol), "FULL" ,"", "NONE", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.BUFFDIST = midBuffDist * -1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.shape = geomList[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; del row, rows
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Done!!!"

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\n*** LAST GEOPROCESSOR MESSAGE (may not be source of the error)***"
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\n*** PYTHON ERRORS *** "
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Python Error Info: " +&amp;nbsp; str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:10:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-a-cursor-to-select-each-row-for-input-into/m-p/451925#M35404</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T20:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Use a cursor to select each row for input into another function.</title>
      <link>https://community.esri.com/t5/python-questions/use-a-cursor-to-select-each-row-for-input-into/m-p/451926#M35405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Gerry,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In v9.2(where I'm currently stuck), the Describe object has an OIDFieldName property. You could use that for building the where clause of a SelectLayerByAttribute.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 May 2012 15:37:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-a-cursor-to-select-each-row-for-input-into/m-p/451926#M35405</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2012-05-18T15:37:38Z</dc:date>
    </item>
  </channel>
</rss>

