We have just installed ArcGIS 10.1 and MS Visual Studio 10 to develop automation tools for select by attribute and select by Location.
We developed a new add-in button in ArcMAP, and clicking it should do 4 queries, 2 of them are attribute queries and other 2 are spatial queries. order (1 attribute, 1 spatial, 1 attribute, 1 spatial)
Suffering from very slow performance when using our code to perform the spatial queries.
Here after is the used code:
Public Function p_GenSelectByLocation(ByVal SourceLayerName As String, ByVal TargetLayerName As String, ByVal Whereclause As String, ByVal SelectionType As esriSelectionResultEnum, ByVal RelationType As esriSpatialRelEnum) As Integer Try Dim pboolSrcFound As Boolean = False Dim pboolTrgtFound As Boolean = False Dim pEnumLayer As IEnumLayer = My.ArcMap.Document.ActiveView.FocusMap.Layers(Nothing, True) Dim pSrcFLayer As IFeatureLayer = Nothing Dim pTrgtFLayer As IFeatureLayer = Nothing Dim pLoopLayer As ILayer = pEnumLayer.Next() pEnumLayer.Reset() Do Until pLoopLayer Is Nothing If TypeOf pLoopLayer Is IFeatureLayer Then If pLoopLayer.Name = SourceLayerName Then pSrcFLayer = pLoopLayer pboolSrcFound = True End If If pLoopLayer.Name = TargetLayerName Then pTrgtFLayer = pLoopLayer pboolTrgtFound = True End If End If If pboolSrcFound = True And pboolTrgtFound = True Then Exit Do pLoopLayer = pEnumLayer.Next() Loop If pSrcFLayer Is Nothing Or pTrgtFLayer Is Nothing Then Exit Try Dim pSrcFeatureSelection As IFeatureSelection = pSrcFLayer Dim pGeomToUnion As IGeometryCollection = New GeometryBag() If pSrcFeatureSelection.SelectionSet.Count = 0 Then Exit Try 'Get union of Geometry of all selected features Dim pCursor As ICursor = Nothing pSrcFeatureSelection.SelectionSet.Search(Nothing, False, pCursor) If pCursor Is Nothing Then Exit Try Dim pfeatureCursor As IFeatureCursor = pCursor Dim pFeature As IFeature = pfeatureCursor.NextFeature Dim pGeometry As IGeometry pGeometry = pFeature.Shape Dim pCount As Integer = 0 Do Until pFeature Is Nothing pCount += 1 pGeometry = pFeature.Shape pGeomToUnion.AddGeometry(pGeometry) pFeature = pfeatureCursor.NextFeature Loop Dim pEnumGeometry As IEnumGeometry = pGeomToUnion 'Dim pgeometrybag As IGeometryBag = pEnumGeometry Dim pResultGeom As ITopologicalOperator = Nothing If pGeometry.GeometryType = esriGeometryType.esriGeometryPolyline Then pResultGeom = New Polyline pResultGeom.ConstructUnion(pEnumGeometry) ElseIf pGeometry.GeometryType = esriGeometryType.esriGeometryPolygon Then pResultGeom = New Polygon pResultGeom.ConstructUnion(pEnumGeometry) End If If pResultGeom Is Nothing Then Exit Try 'define the spatial filter and select the features based on the union Geometry Dim pSFilter As ISpatialFilter = New SpatialFilter 'If pTrgtFLayer Is Nothing Then Exit Try Dim pnameOfShapeField As System.String = pTrgtFLayer.FeatureClass.ShapeFieldName pSFilter.GeometryField = pnameOfShapeField pSFilter.Geometry = TryCast(pResultGeom, IGeometry) pSFilter.SpatialRel = RelationType Dim pTrgtFeatureSelection As IFeatureSelection = pTrgtFLayer pTrgtFeatureSelection.SelectFeatures(TryCast(pSFilter, ESRI.ArcGIS.Geodatabase.ISpatialFilter), SelectionType, False) Return pTrgtFeatureSelection.SelectionSet.Count Catch ex As Exception pFuncReturnDebug(ex) Return -1 End Try End Function
ArcGIS 10.1 was retired from support over three years ago. The current release is 10.8.1.
Your issue may be release independent, but there's really no way to tell, since you haven't mentioned data format, indexing, data volume, or actual timing (in seconds).
Please help us to help you by including enough details to make an answer possible.
Thank you for replying, hereafter are the details: we are using FGDB data, the Target Layer includes 700,000+ features, and the Source Layer includes 200,000+ features. using the "Select by Location" built-in tool in ArcMap takes ~1.5 mins; however, using the code we have provided above takes ~6.5 mins. After Debugging, more than 5.5 mins is delayed in the following line of code: pTrgtFeatureSelection.SelectFeatures(TryCast(pSFilter, ESRI.ArcGIS.Geodatabase.ISpatialFilter), SelectionType, False)
it is very critical performance issue, and I need to select the features in that layer in order to perform additional queries (attributes & spatial).
We are also trying to find another way/method than "SelectFeatures" to select the features in the Target layer, however still not sure if there is.
Additionally, and after investigation, when we change the esriSelectionResultEnum from "Add to Selection" to"New", the performance increased 6 times (~1min). Thus, to narrow down the perfromance issue, it seems related to "Add to selection" option. However, the query requires this option. Any Advise!
Low hanging fruit on file geodatabase query performance includes:
Spatial queries on badly fragmented datasets can also take a long time, even with a fresh spatial index. I use relational databases, not file geodatabase, to juggle tens to hundreds of millions of rows, and I always make sure my data is physically organized from left to right and top to bottom in chunks (e.g., countries by UTM Zone and MGRS tile; counties by state, from west to east). The same physical ordering options are available for file geodatabase as enterprise, but they're rarely as necessary in the smaller table sizes (under 100-200k rows).
Tech Support can be of use with modern software, but when using something ancient you'd need to test against something modern to see if it's already been addressed.