7

Every week I need to update the same shapefiles that are used to produce up to date maps. The files are downloaded from 3 different web-servers.

The thing I want to do is to have a script that can search my folder where I put my downloaded shapefiles and replace the ones I've already got. This shouldn't be a problem when the shapefiles have the same name. But still, I can't seem to figure out how to solve this problem. What to use, model builder? Python script?

2
  • 1
    I agree with Alex that writing Python script is the way to do this. Once written you may want to place it behind a scheduled task so that you can just place shapefiles in a folder for them to be processed next time it runs.
    – PolyGeo
    Feb 28, 2012 at 11:53
  • Is that similiar to the one with "Set Data Source(s) .." when you right click on the mxd file ?
    – PROBERT
    Feb 28, 2012 at 17:48

2 Answers 2

10

If you are convenient with Python then writing script for this task is preferred. Take a look at these key things:

  1. Get a list of featureclasses/shapefiles in gdb/folder - ListFeatureClasses. In the bottom of this help article there is also an example "Copy shapefiles to a geodatabase" which you can use to start writing script.
  2. Check for existence of featureclass/shapefile - Exists function.
  3. Delete featureclass - Delete tool.
  4. Copy shapefile to Geodatabase - Copy Features tool.
1
  • Great, thanks for the hints. Iv'e started a script and it seems working so far.
    – Olov Melin
    Feb 28, 2012 at 12:58
3

Here's a simple script that would run in same directory and check for and delete shapefiles... You can just run it from IDLE or ArcGIS python window or you could create a toolbox and add it as a script and add parameters.

    import arcpy, sys

    OutputFC = sys.path[0] + "\\downloaded1.shp"
    if arcpy.Exists(OutputFC):
        arcpy.Delete_management(OutputFC)
        print "deleting " + OutputFC
1
  • +1 for nice simple immediately workable example. Note that using sys.path[0] converts to "full path to the directory containing the script being run". Since the name of the shapefile is hard coded anyway one might as well hard code the full path. Using sys.path adds needless confusion in the mind of someone who is new to the whole scripting world, as is the case here. Follow up with a link to (or example from) Understanding script tool parameters for how to not hard code. Feb 29, 2012 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.