Home arrow Site Info arrow Latest Portal Content arrow Delete and Reload Features in SDE
Delete and Reload Features in SDE PDF Print E-mail

Written by Bert Granberg,

Best practices for database management employ the least amount of schema changes. While it may be convenient and fast to delete a feature class from SDE and then replace it with a new feature class with the same name and the updated data, this poses several problems, especially if you have external users (including ArcMap users and applications like ArcIMS and ArcGIS Server) consuming the data.

While it is potentially much slower that the 'delete feature class' method, using a python script to empty the feature class (delete just the features and leaving the existings schema alone) and appending the updated data into the existing, now empty feature class is much safer and friendlier for all of your users. It does take longer but if the code to do the delete and reload features is run as a windows scheduled task in the middle of the night, this should minimize the impact in a majority of cases.

Here is example code for how to do the delete and reload features in python: 

# ---------------------------------------------------------------------------
# delete_reload_example.py
# Created on: Wed Oct 10 2007 03:36:06 PM
# (modified/cleaned up from ArcGIS/ModelBuilder export to Python)
# AGRC, bgranberg
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")


# Local variables...
SourceFeatureClass = "C:\\Documents and Settings\\BGRANBERG\\Desktop\\nhd.gdb\\StreamsNHDHighRes"
TargetFeatureClass = "Database Connections\\DC_U024@ This e-mail address is being protected from spam bots, you need JavaScript enabled to view it "
                    # Note: DC_U024@ This e-mail address is being protected from spam bots, you need JavaScript enabled to view it is the name of my SDE database connection with editing privileges as it appears
                    # in ArcCatalog

# Process: Delete Features...
gp.DeleteFeatures_management(TargetFeatureClass)

# Process: Append...
gp.Append_management(SourceFeatureClass, TargetFeatureClass, "NO_TEST", "#")

Users' Comments  
 

Display 4 of 4 comments

1. Tue, 03-25-2008 at 02:41 PM

I'm new to python, but i was hoping you could point me in the correct direction. The script above will import from another database, but i wanted to take a shapefile and have it load it into a SDE database. I keep getting the below error: 
Traceback (most recent call last): 
File "C:Delete and Add - Subdivisions.py", line 27, in ? 
gp.Append_management(SourceFea tureClass, TargetFeatureClass, "NO_TEST", "#") 
RuntimeError:  
Failed to execute. Parameters are not valid. 
Inputs must be either all FeatureClasses, Tables or Rasters; not mixed 
Failed to execute (Append).
 
Any Ideas? Thanks.

2. Tue, 03-25-2008 at 04:23 PM

Parameters are not valid. Inputs must be either all FeatureClasses, Tables or Rasters; not mixed 
 
The "SourceFeatureClass" / "TargetFeatureClass" are variables that contain text strings to a valid feature class path. For a shapefile you'll need something like: 
 
myVar = r"C:tempmyShapefile.shp"  
 
Note that python handles slashes as escape characters, so you need to put an "r" in front of the quoted path as above. You could also use "C:tempmyShapefile.shp"

3. Tue, 03-25-2008 at 05:05 PM

Thank you.. That was the missing piece i was looking for.

4. Wed, 03-26-2008 at 08:29 AM

It looks as if my slashes never made it into the paths that i wrote in my last comment. imagine a slash between C: and temp and myShapefile.shp... maybe this online editor ditches slashes... 
 
.../.../.../...

Display 4 of 4 comments

Add your comment

25, Oct. 2007
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for