<?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: Choice of esriSpatialRelEnum can slow IFeatureCursor NextFeature performance in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109974#M2879</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is the slow part the First call to nextfeature or every call to next feature?&amp;nbsp; My experience, after running rdbms traces on feature cursors using only attribute clauses, the database (oracle in my case) parses the query when search is called.&amp;nbsp; The query is actually executed when the first nextfeature is called.&amp;nbsp; The search was fast but it wasn't really doing the query, just preparing the cursor with the right fields and parsing the query to make sure it was valid.&amp;nbsp; The first call to nextfeature was very slow and the trace showed that is where the query was done.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I would expect different spatial queries to have different performance since the nature of geometric operation varies.&amp;nbsp; One trick to speed things up is to look at your spatial index on the featureclass, it may need some adjustments.&amp;nbsp; It also depends on the geometry type SDE and Oracle will have SDO geometry and ST geometry, spatial queries don't perform the same for both.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Sep 2011 12:02:41 GMT</pubDate>
    <dc:creator>AlexanderGray</dc:creator>
    <dc:date>2011-09-14T12:02:41Z</dc:date>
    <item>
      <title>Choice of esriSpatialRelEnum can slow IFeatureCursor NextFeature performance</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109973#M2878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Environment: Programming add-ins for ArcGIS 10.0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Has anyone noticed performance differences when looping through features returned from a search, depending on which esriSpatialRelEnum you used?&amp;nbsp; esriSpatialRelIntersects seems to be much faster than esriSpatialRelContains.&amp;nbsp; Note that the search itself is fast, but what is slow is looping through features in the cursor returned from the search.&amp;nbsp; I didn't think esriSpatialRelEnum had anything to do with IFeatureCursor.NextFeature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I doing something wrong with my setup of the spatial filter?&amp;nbsp; Is there a workaround? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To test, create an add-in with a button and attach this code to it.&amp;nbsp; Then add a polygon layer to ArcMap.&amp;nbsp; I used the example Globe data on my computer at C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcGlobeData\continent.shp. Click the button and see how long it takes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code uses ESRI.ArcGIS.ADF, ESRI.ArcGIS.Carto, and ESRI.ArcGIS.Geodatabase.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
// Get a polygon layer, the first layer in the map
IFeatureLayer layer = ArcMap.Document.FocusMap.Layer[0] as IFeatureLayer;
IFeatureClass featureClass = layer.FeatureClass;
// Use an ObjectID from your feature class to get a feature
IFeature feature = featureClass.GetFeature(1);

// Create a filter using geometry from the feature
ISpatialFilter filter = new SpatialFilterClass();
filter.Geometry = feature.ShapeCopy;
// esriSpatialRelIntersects is fast. esriSpatialRelContains is slow.
filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

using (ComReleaser comReleaser = new ComReleaser())
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; IFeatureCursor cursor = featureClass.Search(filter, true);
&amp;nbsp;&amp;nbsp;&amp;nbsp; comReleaser.ManageLifetime(cursor);

&amp;nbsp;&amp;nbsp;&amp;nbsp; // Time the loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; int counter = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; DateTime d = DateTime.Now;
&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((feature = cursor.NextFeature()) != null) // The slow part
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; counter++;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; // Report the result
&amp;nbsp;&amp;nbsp;&amp;nbsp; string time = DateTime.Now.Subtract(d).TotalMilliseconds.ToString();
&amp;nbsp;&amp;nbsp;&amp;nbsp; string msg = counter.ToString() + " feature(s) found in " + time + " ms";
&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show(msg);
}&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2011 20:53:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109973#M2878</guid>
      <dc:creator>TimWhiteaker</dc:creator>
      <dc:date>2011-09-13T20:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Choice of esriSpatialRelEnum can slow IFeatureCursor NextFeature performance</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109974#M2879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is the slow part the First call to nextfeature or every call to next feature?&amp;nbsp; My experience, after running rdbms traces on feature cursors using only attribute clauses, the database (oracle in my case) parses the query when search is called.&amp;nbsp; The query is actually executed when the first nextfeature is called.&amp;nbsp; The search was fast but it wasn't really doing the query, just preparing the cursor with the right fields and parsing the query to make sure it was valid.&amp;nbsp; The first call to nextfeature was very slow and the trace showed that is where the query was done.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I would expect different spatial queries to have different performance since the nature of geometric operation varies.&amp;nbsp; One trick to speed things up is to look at your spatial index on the featureclass, it may need some adjustments.&amp;nbsp; It also depends on the geometry type SDE and Oracle will have SDO geometry and ST geometry, spatial queries don't perform the same for both.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Sep 2011 12:02:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109974#M2879</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2011-09-14T12:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Choice of esriSpatialRelEnum can slow IFeatureCursor NextFeature performance</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109975#M2880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Is the slow part the First call to nextfeature or every call to next feature?&amp;nbsp; &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You're right.&amp;nbsp; The slow part is the first call to next feature.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried creating new feature classes in my personal geodatabase to play with spatial indexes, appending my existing data to the new feature classes for each test.&amp;nbsp; The data are in geographic coordinates and cover the Gulf of Mexico.&amp;nbsp; I tried grid sizes of 18, 1, and 0.1, and got roughly the same poor performance each time.&amp;nbsp; Hmmmm.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Oct 2011 15:40:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109975#M2880</guid>
      <dc:creator>TimWhiteaker</dc:creator>
      <dc:date>2011-10-25T15:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Choice of esriSpatialRelEnum can slow IFeatureCursor NextFeature performance</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109976#M2881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;the grid size depends on the size of your features.&amp;nbsp; The spatial query typically uses the grids as a first cut to narrow down the candidate features.&amp;nbsp; A grid size too big will result in too many features being evaluated.&amp;nbsp; A grid size too small will result in too many grid cells that need to be pre-evaluated.&amp;nbsp; There are guidlines for grid sizes in the help document and ways to evaluate them.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have you tried a file geodatabase rather than a a personal geodatabase.&amp;nbsp; Also you should compact the geodatabase if there has been a lot of editing or if the data was loaded without placing the database in load only mode.&amp;nbsp; Personal and file geodatabases have adds and deletes tables internally too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Other factors are at play such as the complexity of the search feature.&amp;nbsp; Having a very complex feature can slow things down too.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Oct 2011 15:53:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109976#M2881</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2011-10-25T15:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: Choice of esriSpatialRelEnum can slow IFeatureCursor NextFeature performance</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109977#M2882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Tim,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't program in c# so when I looked at your code I noticed something that I would not do. So this could be a&lt;/SPAN&gt;&lt;STRONG&gt; red herring &lt;/STRONG&gt;&lt;SPAN&gt;and may be what you are doing is simply slicker than how I program? Anyway the line that I thought unusual was:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;while ((feature = cursor.NextFeature()) != null)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't know if this is a preference thing but I would have done (in VB):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pFeature = pCursor.NextFeature&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; do while not pFeature is nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; counter = counter +1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; pFeature = pCursor.NextFeature&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; loop&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So the retrieving of the feature that you are testing is done in the loop and not on the line that is evaluating if it is nothing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duncan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Oct 2011 13:26:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109977#M2882</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2011-10-26T13:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Choice of esriSpatialRelEnum can slow IFeatureCursor NextFeature performance</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109978#M2883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;agray1, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for all the guidance!&amp;nbsp; I found some tips for tuning spatial indexes at:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://webhelp.esri.com/arcgisserver/9.3/java/index.htm#geodatabases/tuning_-450163403.htm"&gt;http://webhelp.esri.com/arcgisserver/9.3/java/index.htm#geodatabases/tuning_-450163403.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I followed the tips and tried the query both with and without multiple indexes, since some features are thousands of times larger than others in this dataset.&amp;nbsp; No real improvement.&amp;nbsp; File GDB didn't significantly help either.&amp;nbsp; Also tried compacting the database. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The features are mostly rectangles, and I'm searching using a rectangle from one of the feature's shapes for testing purposes.&amp;nbsp; They're in a geographic coordinate system, but projecting them didn't help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I did find two things that helped significantly.&amp;nbsp; Exploding multipart features to single features (about 2% of the 628 features are multipart) improved performance by a factor of 4.&amp;nbsp; Opening an edit session and moving features around so that fewer of them overlapped, improved performance by a factor of 100.&amp;nbsp; Pretty much every feature overlaps another feature, like leaves in a pile.&amp;nbsp; That seems to be my biggest problem, but that's the nature of this dataset.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I probably should have included a better description of this dataset in my original post.&amp;nbsp; I didn't realize the overlapping features would be the culprit, so shame on my intuition.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duncan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for keeping an eye out for red herrings.&amp;nbsp; I took a double take at that C# code pattern the first time I saw it as well.&amp;nbsp; The portion in parentheses where the feature variable is being assigned the next object in the cursor, is being evaluated before comparing the result of that operation to null.&amp;nbsp; So the code runs fine, and in a test just now, it took the same time to complete as when I edited the code to match the style you use in your VB.NET programming.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For an example of ESRI using the same practice, see:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002m1000000"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002m1000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ah, the nuances of programming.&amp;nbsp; I'm still learning!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Nov 2011 19:57:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/choice-of-esrispatialrelenum-can-slow/m-p/109978#M2883</guid>
      <dc:creator>TimWhiteaker</dc:creator>
      <dc:date>2011-11-07T19:57:24Z</dc:date>
    </item>
  </channel>
</rss>

