chulia

replace dbf files and create a new map

Discussion created by chulia on Sep 5, 2011
Latest reply on Sep 5, 2011 by chulia
Hello,

I do not have any experiences with Python and especially with Python and ArcGis. I now have to write a script which creates automatically a map of Germany with different contents.
I've got one mxd file which I use as template. And I've got a lot of dbf. files. I'd like to replace the dbf file of my mxd with the other dbf files. I mean, when Python is finished he should automatically delet the old dbf file and replace the new one. All maps shall have the same layout. So Python has to take over the layout from the older dbf file. And after this he should print a map as .tiff file.
At the moment my script replaces the dbf files, then Python creates a new layer with my new dbf file and put it into the mxd file. But the layout update doesn't work.
If I didn't update the new layer with an older one, ArcGis only shows a map with unique values, but I need graduated colors.
If I update the new layer with an older one, then ArcGis takes over the symbology and the old name, but ArcGis doesn't change the name of the new value.

For a better understandig i uploaded my skript and some pictures.

#!/usr/bin/env python
#-*- coding: iso-8859-1 -*-

import arcpy, sys, numpy, os, csv
sys.path.append('C:\Python26\Lib\site-packages')
import PIL
from PIL import Image


#removes the dbf File from my mxd file (template)

os.remove('F:\pommeren\Pflanzenbis56\Vorlage_Current56_einzeln_Copy\Current56.dbf')

# renames my new dbf file --- from Current56_20 to Current56 (same name as my template)

os.renames('F:\\pommeren\\Pflanzenbis56\\dbf_Copy\\Current56_20.dbf',
    'F:\\pommeren\\Pflanzenbis56\\Vorlage_Current56_einzeln_Copy\\Current56.dbf')


arcpy.gp.overwriteOutput = True
# Workspace
workspace = arcpy.env.workspace ='F:\pommeren\Pflanzenbis56\Vorlage_Current56_einzeln_Copy'

featureClasses = arcpy.ListFeatureClasses()

# template
mxd = arcpy.mapping.MapDocument(r"F:\pommeren\Pflanzenbis56\Vorlage_Current56_einzeln_Copy\Current56.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
layer = arcpy.mapping.ListLayers(mxd)[0]

item=featureClasses[0] # because there are more then one feature class

# now I create the new layer

newLyr = 'map_'
arcpy.MakeFeatureLayer_management(item,  newLyr)

lyrFile = arcpy.mapping.Layer(newLyr)

arcpy.mapping.AddLayer(df, lyrFile,"BOTTOM")
layers = arcpy.mapping.ListLayers(mxd)

# here i update my ne layer

updateLayer = layers[3]
sourceLayer = layers [1]
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer)


#save a mxd and tiff

temp = os.path.abspath(r'F:\pommeren\Pflanzenbis56\end\temp.mxd')
mxd.saveACopy(temp)
arcpy.mapping.ExportToTIFF(mxd, r"F:\pommeren\temp.tif",resolution=200)



I know that this script is not really good commented, but it's my first script and I haven't any programming knowledge.

the first sreenshot shows you my template. Current56 is the old layer and can be removed. The update Layer is only necessary for updating my new dbf file. Both have got the same Attributtable
[URL=http://img198.imageshack.us/i/screenshot1gg.png/][/URL]

The second screenshot shows my new dbf file which I would like to replace. Only the last column is different. The rest is in every dbf file the same.
[URL=http://img7.imageshack.us/i/screenshot2vl.png/][/URL]

the next screenshot shows you my result after I have run my script.
the first shows you my mxd file with an updated new layer (map_) and the new Attributtable
the second one shows you my mxdfile without any updates.
[URL=http://img94.imageshack.us/i/screenshot3hpy.png/][/URL]
[URL=http://img4.imageshack.us/i/screenshot4zi.png/][/URL]

it would be nice if anybody can halb me.
Thanks a lot!!!

Outcomes