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()
# 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
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.
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"
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...