AnsweredAssumed Answered

Slow response when doing spatial queries.

Question asked by dalejs on Dec 23, 2013
Latest reply on Dec 30, 2013 by dalejs
I am using Visual Studio 2010 Professional - Version 10.0.40219.1  SP1Rel.  Microsoft .NET Framework - Version 4.5.50938 SP1Rel.  ArcGIS 10.1 SP1 for Desktop - Build 3143.

I am doing a spatialquery to retreive all address points within a zipcode boundary, so all points within a polygon.

If I have the point layer and polygon layer loaded in the ArcMap session and the end result is 15,000 points within the polygon it may run 10-15 minutes, if I do it on the server it runs out of memory.

I believe the problem lies in how the Visual Studio is setup, I did not set it up, it was just installed on my machine.  In looking for a resolution I found in the Advanced Compiler Settings to change the Target CPU, from the AnyCPU setting it was set on, to x86.  After I did that it would run on the server (very slow) and occassionally run out of memory, not great, but an improvement.

It also appears that I go loop the zipcodes it just gets slower and slower.  If I close and restart the session, the speed (what there is of it) picks back up and then starts slowing down.

I have always done small spatialqueries, one point, or points in a neighborhood, but not this large of query.  Yes, I am releasing the cursor after each spatialquery.

I will post the code I am using, thank you for looking at this. 

In the code I am finding all the points within the zipcode boundary and verifying that the zipcode on the point matches the zipcode boundary it is within.

Before this code starts I am getting all the zipcodes that I will be looking at which is ZipFeature.
       Dim pSpatialQ As ISpatialFilter = New SpatialFilter
            pSpatialQ.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
       Do Until pZipFeature Is Nothing
                If Not (IsDBNull(pZipFeature.Value(pZipFeature.Fields.FindField("Zipcode")))) Then
                    theZipCode = pZipFeature.Value(pZipFeature.Fields.FindField("Zipcode"))
                    theZipCode = ""
                End If
                pSpatialQ.Geometry = pZipFeature.Shape
                Dim pFeatCur As IFeatureCursor = pAddressesLayer.Search(pSpatialQ, False)
                Dim pFeat As IFeature = pFeatCur.NextFeature
                Do Until pFeat Is Nothing
                    If Not (IsDBNull(pFeat.Value(pFeat.Fields.FindField("Zipcode")))) Then
                        theAddressZipCode = pFeat.Value(pFeat.Fields.FindField("Zipcode"))
                        theAddressZipCode = ""
                    End If
                    If theZipCode <> theAddressZipCode Then
                        B.Writeline(pFeat.OID & "," & theAddressZipCode & "," & theAddressStatus & "," & thecounter & ", ")
                        End If
                    pFeat = pFeatCur.NextFeature()
                'Method to clean memory.
                pZipFeature = pZipFeatureCursor.NextFeature()