<?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: Nested Cursor- why is it bad? in Transportation Questions</title>
    <link>https://community.esri.com/t5/transportation-questions/nested-cursor-why-is-it-bad/m-p/23998#M95</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: luke.kaim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I did not rule out a spatial join. When I solved this issue with tables I did use a spatial join. But joins do take a long time and I thought a cursor could be faster. Now I want to solve this issue programmatically. Why are nested cursors a bad idea?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Apr 2013 02:22:27 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2013-04-22T02:22:27Z</dc:date>
    <item>
      <title>Nested Cursor- why is it bad?</title>
      <link>https://community.esri.com/t5/transportation-questions/nested-cursor-why-is-it-bad/m-p/23996#M93</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: luke.kaim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have heard nested cursors are bad. Why is that? If I want to test if a point is in a particular polygon wouldn't I need nested cursors? &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Something like this would work well. Why is nested cursors not a good idea? Thank you for your help&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;for row1 in arcpy.SearchCursor(shapefile1): &amp;nbsp;&amp;nbsp;&amp;nbsp; for row2 in arcpy.SearchCursor(shapefile2): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row1.shape.contains(row2.shape): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return True&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Luke Kaim&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 00:07:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/nested-cursor-why-is-it-bad/m-p/23996#M93</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-04-22T00:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Cursor- why is it bad?</title>
      <link>https://community.esri.com/t5/transportation-questions/nested-cursor-why-is-it-bad/m-p/23997#M94</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;you ruled out a spatial join?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 01:59:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/nested-cursor-why-is-it-bad/m-p/23997#M94</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-04-22T01:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Cursor- why is it bad?</title>
      <link>https://community.esri.com/t5/transportation-questions/nested-cursor-why-is-it-bad/m-p/23998#M95</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: luke.kaim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I did not rule out a spatial join. When I solved this issue with tables I did use a spatial join. But joins do take a long time and I thought a cursor could be faster. Now I want to solve this issue programmatically. Why are nested cursors a bad idea?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 02:22:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/nested-cursor-why-is-it-bad/m-p/23998#M95</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-04-22T02:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Cursor- why is it bad?</title>
      <link>https://community.esri.com/t5/transportation-questions/nested-cursor-why-is-it-bad/m-p/23999#M96</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I did not rule out a spatial join. When I solved this issue with tables I did use a spatial join. But joins do take a long time and I thought a cursor could be faster. Now I want to solve this issue programmatically. Why are nested cursors a bad idea?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't think there's a problem with nested cursors, as long as the datasets accessed inside the loops don't participate in the cursors. A cursor opens a file lock on the table you opened, so if you run a tool that accesses that dataset you are accessing it twice at the same time -- this is what can get you into trouble.&amp;nbsp; Your example does not do this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Feel free to try this, but if there's a tool that will do the same thing, it's unlikely a cursor would be faster because most standard tools are written in C++, which will usually be much faster than Python. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my experience, the most effective way to speed up a really slow geoprocessing workflow is to try a different approach that more efficiently solves your problem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 11:19:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/nested-cursor-why-is-it-bad/m-p/23999#M96</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-04-22T11:19:15Z</dc:date>
    </item>
  </channel>
</rss>

