<?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 Re: Finding adjacent neighbors for Cellular Automata in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306316#M23765</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Stacy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you very much!&amp;nbsp; That got me through that part of the code.&amp;nbsp; I hope I can ask you something else.&amp;nbsp; The select layer by location is getting an error now.&amp;nbsp; Do you know what I would need to do to resolve this error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exec codeObject in __main__.__dict__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Users\Flash\Documents\School\CA\CellularAutomata.py", line 37, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Adj_Neighbors = arcpy.SelectLayerbyLocation_management("shp_lyr", "Boundary_Touches", "shp_lyr ", " ", "New Selection")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AttributeError: 'module' object has no attribute 'SelectLayerbyLocation_management'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does this mean that the new selection has no attributes associated with it?&amp;nbsp; I'm not sure how to solve this?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any help!&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Linda&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 27 Sep 2011 12:35:31 GMT</pubDate>
    <dc:creator>LindaVasil</dc:creator>
    <dc:date>2011-09-27T12:35:31Z</dc:date>
    <item>
      <title>Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306314#M23763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to write a simple cellular automata code on a reclassified land use point shapefile.&amp;nbsp; It is reclassified by likelihood of land use conversion based on the number of like adjacent neighbors.&amp;nbsp; I would like to the code to run cell by cell and do the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Find adjacent neighbors&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Get Grid_Code value&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Find out if there is 4 of more cells with same land use grid code&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If there is and this value is greater than the center cell, then the center cell converts.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've written the following code, but it gets caught in select by attribute command.&amp;nbsp; The error that comes back is the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exec codeObject in __main__.__dict__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Users\Flash\Documents\School\CA\CellularAutomata.py", line 32, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(shp, "New_Selection", sql)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 4259, in SelectLayerByAttribute&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The value cannot be a feature class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000840: The value is not a Raster Layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000840: The value is not a Mosaic Layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SelectLayerByAttribute).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code itself:&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Import arc geoprocessing module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, sys&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Set variable to the point shapefile&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;shp = sys.argv[1]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Add LRG_Value to the point shapefile&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddField_management(shp, "LRG_Value", "Long")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Place an update cursor in the point shapefile table&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#move to the first record in the table&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cur = arcpy.UpdateCursor(shp)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;row = cur.next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Loop through each record in the table&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;while row:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Extract Grid Code and Object ID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GCP = row.getValue("Grid_Code")&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #GCP = Grid Code of Processing Cell&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PIP = row.getValue("PointID")&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #PIP = Point ID of Processing Cell&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Put ObjectID in sequential order&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sql = "PointID" + " = " + str(PIP)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Select the sequential order of Object ID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(shp, "New_Selection", sql)&amp;nbsp; #Where the mess up is!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Select only the Object ID that are surrounding the cursor cell&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Adj_Neighbors = arcpy.SelectLayerbyLocation_management(shp, "Boundary_Touches", shp, " ", "New Selection")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for codes in Adj_Neighbors:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GCA = row.getValue("Grid_Code")&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; #GCA = Grid Codes from adjacent cells&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Put Grid codes in a list&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GCA_List = list(GCA)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Sort Grid Codes from smallest to largest&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; srt_GCA_List = sorted(GCA_List)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #select the largest number in the list (last number in sequence)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LR_Value = srt_GCA_List[-1]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #count the number of times the largest occurs&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tie_LR = GCA_List.count(LR_Value)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if tie_LR &amp;gt;= 4 and LR_Value &amp;gt; GCA:&amp;nbsp; #is this syntax correct...seems a little messy to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("LRG_Value", LR_Value)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #else: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp;&amp;nbsp; LR_Value = srt_GCA_List[-2]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #keep going until the end of the list -- I will write this later&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Update the row values&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cur.updateRow(row)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Delect temporary Variables&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del GCP, OIP, sql, result, GCA, GCA_List, srt_GCA_List, LR_Value, tie_LR&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #move to the next row&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = cur.next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #delete row and cursor object, arcpy, module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del cur, row, arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would appreciate any help on that line, or any other lines that are obviously wrong.&amp;nbsp; I'm pretty new to the code writing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Linda&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Sep 2011 19:39:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306314#M23763</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2011-09-26T19:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306315#M23764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think you need to make your feature class into a feature layer before you can select by attributes (making a feature layer is like adding it to the map - it makes it active). i.e.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.MakeFeatureLayer_management(shp, "shp_lyr")
#Select the sequential order of Object ID
arcpy.SelectLayerByAttribute_management("shp_lyr", "New_Selection", sql)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After that, if you need it, refer to "shp_lyr"...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:39:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306315#M23764</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T14:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306316#M23765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Stacy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you very much!&amp;nbsp; That got me through that part of the code.&amp;nbsp; I hope I can ask you something else.&amp;nbsp; The select layer by location is getting an error now.&amp;nbsp; Do you know what I would need to do to resolve this error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exec codeObject in __main__.__dict__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Users\Flash\Documents\School\CA\CellularAutomata.py", line 37, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Adj_Neighbors = arcpy.SelectLayerbyLocation_management("shp_lyr", "Boundary_Touches", "shp_lyr ", " ", "New Selection")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AttributeError: 'module' object has no attribute 'SelectLayerbyLocation_management'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does this mean that the new selection has no attributes associated with it?&amp;nbsp; I'm not sure how to solve this?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any help!&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Linda&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2011 12:35:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306316#M23765</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2011-09-27T12:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306317#M23766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;arcpy.SelectLayerByLocation_management&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;not&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerbyLocation_management&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ciao,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AC&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2011 12:55:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306317#M23766</guid>
      <dc:creator>AlessandroCinnirella</dc:creator>
      <dc:date>2011-09-27T12:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306318#M23767</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you!&amp;nbsp; Good eye...you guys are awesome!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Linda&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2011 15:51:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306318#M23767</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2011-09-27T15:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306319#M23768</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So I know I'm like a child that's bugging you guys (anyone please!).&amp;nbsp; So hopefully you guys will continue to pick out my silly errors.&amp;nbsp; Ok, so I changed the select by location to right syntax.&amp;nbsp; I changed the boundary touches to intersect because I read boundary touches only works for line and polygon shapefiles and I want to do this on a point shapefile.&amp;nbsp; So the new command I have is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; #Select only the Point ID that are surrounding the cursor cell&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Adj_Neighbors = arcpy.SelectLayerByLocation_management("shp_lyr", "INTERSECT", "shp_lyr", "0 meter", "New Selection")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I put 0 meter in for search distance because when I just left it as " ", the error comes back as "cannot set input parameter search_distance".&amp;nbsp; Now with the 0 meter as the search distance, I get the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; Adj_Neighbors = arcpy.SelectLayerByLocation_management("shp_lyr", "INTERSECT", "shp_lyr", "0 meter", "New Selection")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 4381, in SelectLayerByLocation&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000800: The value is not a member of NEW_SELECTION | ADD_TO_SELECTION | REMOVE_FROM_SELECTION | SUBSET_SELECTION | SWITCH_SELECTION.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SelectLayerByLocation).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have to say "huh?" to that error.&amp;nbsp; Again I appreciate anyone who would hold my hand like I'm a child and help me decipher what I'm doing wrong.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for any help,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Linda&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2011 16:08:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306319#M23768</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2011-09-27T16:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306320#M23769</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Never mind about the last post.&amp;nbsp; I just deleted the last two parameters from the command and it ran!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2011 16:19:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306320#M23769</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2011-09-27T16:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306321#M23770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;FYI,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Adj_Neighbors = arcpy.SelectLayerByLocation_management("shp_lyr", "INTERSECT", "shp_lyr", "0 meter", "NEW_SELECTION")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;not&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Adj_Neighbors = arcpy.SelectLayerByLocation_management("shp_lyr", "INTERSECT", "shp_lyr", "0 meter", "New Selection")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ehehee,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ciao,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AC&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2011 19:28:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306321#M23770</guid>
      <dc:creator>AlessandroCinnirella</dc:creator>
      <dc:date>2011-09-27T19:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306322#M23771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just a comment, but depending on how many points you have (I am guessing these points were derived from a raster), this sort of vector based analysis could take an extremely long time. For example, if your original grid was only 1000 x 1000 cells, your code would need to loop 1,000,000 times. Assuming it takes even just 1 second to do your SelectbyLocation and SelectByAttributes (most likely more than 1 second!), your process will take about 12 days to run.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This analysis would be much better handled using a Python dictionary object (a numpy array is another option, but one I don't have any experience with). Dictionaries are an in memory data structure meaning that once you load your data from disk, the processing is, well, light speed. The basic idea is that you load your land use data into a dictionary by using the column and row order as the keys:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dict = {}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict[1,1] = 4 #the cell existing at column = 1, row = 1 has a landuse code of 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict[2,1] = 4 #the cell existing at column = 2, row = 1 has a landuse code of 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict[1,2] = 1 #the cell existing at column = 1, row = 2 has a landuse code of 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dict[2,2] = 2 #the cell existing at column = 2, row = 2 has a landuse code of 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, look into using Python dictionaries or numpy arrays to do this sort of thing... It will be immensely faster and cooler. This sort or "neighbor notation" capability was actually built in functionality in good ole' Workstation ArcInfo Grid. However, ESRI chose not to port neighbor notation forward to ArcGIS, and so we are stuck devising our own data structures and algorithms to deal with ESRI apathy.:mad:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hmmm...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2011 20:20:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306322#M23771</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2011-09-27T20:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306323#M23772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am fresh to a lot of this subject matter, but a project I am working on in my spare time (I'm actually just a designer) is getting me into things I have no idea where to start in, but I think it is in the same vein as the land use CA model you are discussing here.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a basic understanding of programming (Python, Java and Processing) and I programmed a CA in Processing to test its functionality but I need to find out where to learn to program in an actual geospatial program so my analysis can be properly visualized. Would anyone point me in the right direction to start?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Elijah Kafer&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Nov 2011 17:33:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306323#M23772</guid>
      <dc:creator>ElijahKafer</dc:creator>
      <dc:date>2011-11-28T17:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306324#M23773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks very much...that is exactly what I had to do.&amp;nbsp; My basin had 250,000 points in it.&amp;nbsp; I had no other choice but to code up as a matrix in python, not only for the time to run, but I would also run out of memory.&amp;nbsp; Now with python, it runs 85 simulations in 2:20 seconds.&amp;nbsp; I would suggest to anyone doing something similar is to export your FID and Grid Codes to a text file and have python read it in as a dictionary.&amp;nbsp; And do all the rest of through python as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wish I would have come back and read your post sooner...it would have saved me some time and frustration.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Just a comment, but depending on how many points you have (I am guessing these points were derived from a raster), this sort of vector based analysis could take an extremely long time. For example, if your original grid was only 1000 x 1000 cells, your code would need to loop 1,000,000 times. Assuming it takes even just 1 second to do your SelectbyLocation and SelectByAttributes (most likely more than 1 second!), your process will take about 12 days to run.&lt;BR /&gt;&lt;BR /&gt;This analysis would be much better handled using a Python dictionary object (a numpy array is another option, but one I don't have any experience with). Dictionaries are an in memory data structure meaning that once you load your data from disk, the processing is, well, light speed. The basic idea is that you load your land use data into a dictionary by using the column and row order as the keys:&lt;BR /&gt;&lt;BR /&gt;dict = {}&lt;BR /&gt;dict[1,1] = 4 #the cell existing at column = 1, row = 1 has a landuse code of 4&lt;BR /&gt;dict[2,1] = 4 #the cell existing at column = 2, row = 1 has a landuse code of 4&lt;BR /&gt;dict[1,2] = 1 #the cell existing at column = 1, row = 2 has a landuse code of 1&lt;BR /&gt;dict[2,2] = 2 #the cell existing at column = 2, row = 2 has a landuse code of 2&lt;BR /&gt;&lt;BR /&gt;Anyway, look into using Python dictionaries or numpy arrays to do this sort of thing... It will be immensely faster and cooler. This sort or "neighbor notation" capability was actually built in functionality in good ole' Workstation ArcInfo Grid. However, ESRI chose not to port neighbor notation forward to ArcGIS, and so we are stuck devising our own data structures and algorithms to deal with ESRI apathy.:mad:&lt;BR /&gt;&lt;BR /&gt;Hmmm...&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2012 19:10:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306324#M23773</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2012-03-05T19:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306325#M23774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;'Python Dictionary' is my answer to almost everything these days - It's an extremely powerful data structure for doing iterative-type analyses... as long as all your data fits.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2012 22:14:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306325#M23774</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-03-05T22:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306326#M23775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks very much...that is exactly what I had to do.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;Get Grid_Code value&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Find out if there is 4 of more cells with same land use grid code&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;If there is and this value is greater than the center cell, then the center cell converts&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Linda, can you share your code here? I'm curious how you loaded the info into the dict and how you worked with it once it was there. Neat that you got pretty nice performance with a generic python dictionary.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing to think about in this kind of analysis is whether the cell changes are "destructive", ie, when you move to the next cell to the right, and do the analysis again looking at the land use codes: does the analysis for the new location use the changed value, or the original?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good old Workstation grid neighborhood notation does not do that, it always looks back at the original raster.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2012 22:51:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306326#M23775</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-03-05T22:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306327#M23776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'll second that request. If you are willing to share, I'd also like to see that code too.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2012 23:04:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306327#M23776</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-03-05T23:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306328#M23777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;if i understood all the posts correctly, i recently tried something similar. i went with a raster/numpy-array approach.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;it works, but not nearly as fast as linda´s approach (hoping for her code/approach to be posted here as well)...i just slightly modified my stuff and timed a random 250x250 cell raster @ ~20s.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import numpy as np
import arcpy

def chkNeighbors(arr, x, y):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&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; left = arr[(x-1, y)] if x-1 &amp;gt;= 0 else 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; right = arr[(x+1, y)] if x+1 &amp;lt;= (np.shape(arr)[0]-1) else 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; top = arr[(x, y-1)] if y-1 &amp;gt;= 0 else 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bottom = arr[(x, y+1)] if y+1 &amp;lt;= (np.shape(arr)[1]-1) else 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; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hVal = 3
&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; if all([left &amp;gt; hVal, right &amp;gt; hVal, top &amp;gt; hVal, bottom &amp;gt; hVal]) \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and left == right == top == bottom:&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; return top
&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; return arr[x,y]
&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; except IndexError:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "error@", x,y

def doanalysis():&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arr = arcpy.RasterToNumPyArray(r"C:\Default.gdb\Reclass_test500")
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print np.shape(arr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; itemindex = zip(*np.where(arr))&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; i=0 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(0,len(arr.flat)):
&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; arr[itemindex&lt;I&gt;] = chkNeighbors(arr, *itemindex&lt;I&gt;)
&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; ras = arcpy.NumPyArrayToRaster(arr)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ras.save(r"C:\Default.gdb\testraster")

&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:39:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306328#M23777</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2021-12-11T14:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Finding adjacent neighbors for Cellular Automata</title>
      <link>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306329#M23778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;if i understood all the posts correctly, i recently tried something similar. i went with a raster/numpy-array approach.&lt;BR /&gt;it works, but not nearly as fast as linda´s approach (hoping for her code/approach to be posted here as well)...i just slightly modified my stuff and timed a random 250x250 cell raster @ ~20s.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import numpy as np
import arcpy

def chkNeighbors(arr, x, y):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&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; left = arr[(x-1, y)] if x-1 &amp;gt;= 0 else 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; right = arr[(x+1, y)] if x+1 &amp;lt;= (np.shape(arr)[0]-1) else 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; top = arr[(x, y-1)] if y-1 &amp;gt;= 0 else 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bottom = arr[(x, y+1)] if y+1 &amp;lt;= (np.shape(arr)[1]-1) else 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; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hVal = 3
&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; if all([left &amp;gt; hVal, right &amp;gt; hVal, top &amp;gt; hVal, bottom &amp;gt; hVal]) \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and left == right == top == bottom:&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; return top
&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; return arr[x,y]
&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; except IndexError:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "error@", x,y

def doanalysis():&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arr = arcpy.RasterToNumPyArray(r"C:\Default.gdb\Reclass_test500")
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print np.shape(arr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; itemindex = zip(*np.where(arr))&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; i=0 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(0,len(arr.flat)):
&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; arr[itemindex&lt;I&gt;] = chkNeighbors(arr, *itemindex&lt;I&gt;)
&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; ras = arcpy.NumPyArrayToRaster(arr)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ras.save(r"C:\Default.gdb\testraster")

&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would be very highly appreciated if you help me with writing up a code for the following statements:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. IF the cell is water, THEN no growth is allowed at this cell.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. IF the cell is road, THEN no growth is allowed at this cell.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. IF cell is residential OR commercial, THEN keep this cell the same without any change.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. IF the cell is either forest OR pasture OR row crops AND there are 4 commercial cells in the neighborhood, THEN change the cell to commercial.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. IF the center cell is either forest OR pasture OR row crops AND there are 4 residential in the neighborhood, THEN change the cell to residential.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks for the help,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;best&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jamal&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:39:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/finding-adjacent-neighbors-for-cellular-automata/m-p/306329#M23778</guid>
      <dc:creator>JamalNUMAN</dc:creator>
      <dc:date>2021-12-11T14:39:41Z</dc:date>
    </item>
  </channel>
</rss>

