How do you use python to recalculate the Spatial Index of a feature class in SDE?

3996
7
09-28-2015 01:46 PM
ChristopherLong
New Contributor III

Hello,

We are looking for a way to script the "Recalculate" of a spatial Index button with python, but are having some problems finding a way that works... We first became aware of a problem when it was taking 25 + seconds to complete a identify of a feature. When we started investigating the problem we found that the extent of our bounding box was off (were located in Virginia). We have found that we can go into the properties of the feature class and click the Recalculate button and this fixes the problem but since that is a manual process it is not what were looking for. We have also found that by clicking the Recalculate button and then running the compress on the feature class, the parcels feature class's bounding box is broken again.

We have tried fixing this with python and with model builder and recommendations from this postBatch recalculate spatial index but nothing has worked yet. Below there is information about the model we created at the recommendation of the forum post and some information about the feature class we are trying to fix.

Any information on how to script the recalculate button would be great thanks!

Background information:

Feature class - Parcels that are being populated through a stored procedure in SQL

Number of records - 131,366

Arcmap version - 10.1

0 Kudos
7 Replies
WesMiller
Regular Contributor III

I haven't tested any of this and it looks like there are times when you don't want to do it this way. Please read the links below

Rebuild a spatial index—ArcGIS Help | ArcGIS for Desktop

Remove Spatial Index—Help | ArcGIS for Desktop

Add Spatial Index—Help | ArcGIS for Desktop

ChristopherLong
New Contributor III

Thanks for the links!

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Hi Christopher,

It may be worth while to investigate the stored procedure that is updating the feature class if the spatial index is getting out of whack after an update.

One thing to test is to perform some updates using ArcMap and see if the same issue occurs.  If it does not, this would lead me to believe that the stored procedure is the culprit.

ChristopherLong
New Contributor III

Jake,

We're thinking the same thing i.e. that the problem may be in the stored procedure. It was made by a contractor and then given to us so we don't know that much about its properties, or how to change/fix it. Does ESRI have any resources on this updating or fixing the spatial reference with a stored procedure?

When you say "perform some updates" do you mean edit the parcels?

Thanks!

Chris

0 Kudos
NeilAyres
MVP Frequent Contributor

Yes, that extent looks pretty strange.

I was going to post here the help on AddSpatialIndex_management etc here, but that seems to be what you are doing in your model anyway.

Are you absolutely sure that your coordinate system is correct for this data or that there isn't a small piece of geometry out by the moon somewhere?

ChristopherLong
New Contributor III

Neil,

Thanks for the response! We did a selection of the parcels to get everything in the county boundary and then reversed the selection to see if any features existed outside of the county but no such luck... looks like everything is good there but thanks for the suggestion.

Chris

0 Kudos
NeilAyres
MVP Frequent Contributor

Also check for null geometries. A spatial select wouldn't find these. Maybe repair would work, but if these are in SDE, that might be a non-starter.

0 Kudos