Slow response when doing spatial queries.

1394
11
Jump to solution
12-23-2013 05:56 AM
DaleShearer
Occasional Contributor
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"))
                Else
                    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"))
                    Else
                        theAddressZipCode = ""
                    End If
                    If theZipCode <> theAddressZipCode Then
                        B.Writeline(pFeat.OID & "," & theAddressZipCode & "," & theAddressStatus & "," & thecounter & ", ")
                        End If
                    pFeat = pFeatCur.NextFeature()
                Loop
                '*******************************************************************
                'Method to clean memory.
                '****************************************************************
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatCur)
                '****************************************************************
                pZipFeature = pZipFeatureCursor.NextFeature()
            Loop
0 Kudos
11 Replies
VinceAngelo
Esri Esteemed Contributor
If FGDB flies, it should be possible for a SQL-Server GEOMETRY to fly as well (maybe
not as fast, but it should be able to at least get into the air with the right set of index
options).

I don't ask questions, just answer them, so I've never seen it, but the UI should have a
blue checkmark on all posts in a question thread that you started, much the way all posts
have blue "up" (and sometimes "down", if not greyed out) arrows on the upper-right side
of each post, just below the arrows. If you click on it, it should turn green.

- V
0 Kudos
DaleShearer
Occasional Contributor
Well, there is a checkmark over there right in plain sight......  Thank you very much.  Now when I talk to the server side of the house I know a lot more than I did.

If you want to take a look at another problem, I have a similar question on ArcGIS for Desktop - General:  I am just trying to count files in folders, runs fast on my machine, slow on the server. 

Thank you again for the help, it got me a lot further along.  Dale
0 Kudos