IFeatureCursor containsCursor = null; IFeatureClass featureClass = null; ISpatialFilter spatialFilter = new SpatialFilterClass(); IFeature tempFeature = null; try { featureClass = workspace.OpenFeatureClass("tablename"); spatialFilter.Geometry = operationalUnit.Shape; spatialFilter.GeometryField = featureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; containsCursor = featureClass.Search(spatialFilter, true); tempFeature = containsCursor.NextFeature(); String whereClause = null; String fieldName = tempFeature.Table.OIDFieldName; while (tempFeature != null) { if (tempFeature.HasOID) { whereClause = whereClause + String.Format(" and {0} <> {1}", tempFeature.Table.OIDFieldName, tempFeature.OID); } tempFeature = containsCursor.NextFeature(); } (do something with the where clause) } finally { Helper.ReleaseObject(featureClass); Helper.ReleaseObject(tempFeature); Helper.ReleaseObject(containsCursor); Helper.ReleaseObject(spatialFilter); }
IFeatureCursor containsCursor = null; IFeatureClass featureClass = null; ISpatialFilter spatialFilter = new SpatialFilterClass(); IFeature tempFeature = null; try { featureClass = workspace.OpenFeatureClass("tablename"); spatialFilter.Geometry = operationalUnit.Shape; spatialFilter.GeometryField = featureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; containsCursor = featureClass.Search(spatialFilter, true); tempFeature = containsCursor.NextFeature(); StringBuilder whereClauseBuilder = new StringBuilder(); String fieldName = tempFeature.Table.OIDFieldName;; while (tempFeature != null) { if (tempFeature.HasOID) { // put tempFeature.Table in a variable and release here so that you release each instance in the loop whereClauseBuilder.Append( String.Format(" and {0} <> {1}", tempFeature.Table.OIDFieldName, tempFeature.OID )); } // release 'tempFeature' here so that you release each instance in the loop tempFeature = containsCursor.NextFeature(); } String whereClause = whereClauseBuilder.ToString(); // do something with the where clause } finally { Helper.ReleaseObject(featureClass); Helper.ReleaseObject(tempFeature); Helper.ReleaseObject(containsCursor); Helper.ReleaseObject(spatialFilter); }
I compile the process to run as 64 bit in order to bind to the server.
ArcObjects is 32 bits, are you running this inside an ArcGIS server SOC?
ArcObjects is 32 bits, are you running this inside an ArcGIS server SOC?
Check how long it takes to get the first feature, that is usually when the query is executed on the database side. The creation of the cursor usually just validates the query but doesn't perform it. If the return of the first feature is slow, then it is slow on the database.
Server and Workstation modes of the Garbage Collector algorithm are slightly different, which may account for some or all of the differences between your development machine and the server machine.
http://msdn.microsoft.com/en-us/library/bb680014.aspx
Those are very valid points.
Thanks ScJPike
I will try them.
As for the string builder, I already did that, and didn't help so much.
IFeatureCursor containsCursor = null; IFeatureClass featureClass = null; ISpatialFilter spatialFilter = new SpatialFilterClass(); IFeature tempFeature = null; ITable table = null; try { featureClass = workspace.OpenFeatureClass("tablename"); spatialFilter.Geometry = operationalUnit.Shape; spatialFilter.GeometryField = featureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; containsCursor = featureClass.Search(spatialFilter, true); tempFeature = containsCursor.NextFeature(); table = tempFeature.Table; String fieldName = table.OIDFieldName; String andOIDFieldNotEqual = " and " + fieldName + " <> "; StringBuilder whereClauseBuilder = new StringBuilder(); while (tempFeature != null) { if (tempFeature.HasOID) { whereClauseBuilder.Append(andOIDFieldNotEqual); whereClauseBuilder.Append(tempFeature.OID); } Helper.ReleaseObject(tempFeature); tempFeature = containsCursor.NextFeature(); } String whereClause = whereClauseBuilder.ToString(); (do something with the where clause) } finally { Helper.ReleaseObject(table); Helper.ReleaseObject(featureClass); Helper.ReleaseObject(tempFeature); Helper.ReleaseObject(containsCursor); Helper.ReleaseObject(spatialFilter); }
Releasing a reference to tempFeature inside the while loop? How would the while loop continue?
Helper.ReleaseObject(tempFeature); tempFeature = containsCursor.NextFeature();
Great solution and works fine for me. I have an Console Application using ArcObjects SDK 10.3.1 thats run in a Windows 64bits Server and didn´t work after some loops, for example, it reads 20 features and did not anything more.
Regards
Fabio