Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

I bet this is a no-brainer question, but I'm stuck here :)

share|improve this question
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 '12 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 '12 at 17:48

2 Answers 2

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.
share|improve this answer
    
Great, thanks for the hints. Iv'e started a script and it seems working so far. –  Olov Melin Feb 28 '12 at 12:58

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
share|improve this answer
    
+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. –  matt wilkie Feb 29 '12 at 21:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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