POST
|
Sorry for bothering you, but it finally came out, that my university still has the version 10.0. Recently, hey were just speaking about the update, and not as I thought, realising it... 😞 But thanks anyway!
... View more
04-19-2013
04:23 AM
|
0
|
0
|
250
|
POST
|
I try to export a bunch of layers with the arcpy.mapping.ListLayoutElements function. Each layer should be exported as a single .jpg-map and each with a legend. Because not all layers have the same number of classes the legends have different sizes. To approach this issue, i wanted to use the following piece of code: #LEGENDSTUFF: print "legende generieren" legend=arcpy.mapping.ListLayoutElements(mxd,"LEGEND_ELEMENT","Legend")[0] legend.autoAdd = True while legend.isOverflowing == True: legend.elementHeight = legend.elementHeight +0.1 Here I was obviously inspired by the 2nd legend example on the official help page: http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000041000000 But i get the followong error message: Traceback (most recent call last): File "H:\Desktop\Masterarbeit\Python scripts\map_production_test 6.py", line 98, in <module> while legend.isOverflowing == True: AttributeError: 'LegendElement' object has no attribute 'isOverflowing' >>> Does anyone see, what I do wrong? I use ArcGIS 10.1... (even if it seems i've got an older version)... To better convey to the relationship i post here my whole code. But tob e honest, i dont think that is necessary (and i has still several constructions sites..)... Even the print messages or some comments are sometimes in german: Sorry for that... print "START map production" print "arcpy and os importieren" import arcpy import os, sys, string print "done arcpy and os and so on import" #Workspacedefinitionen workspace = r"H:\Desktop\Masterarbeit\test\RESULTATE" arcpy.env.workspace = workspace out_dir=r"H:\\Desktop\\maps\\e95ci\\" counter = 1 name_var= "test__" + str(counter) + ".jpg" outfile = os.path.join (out_dir, name_var) #Specifies layer file with the symbology you want to apply to the other raster layers sourceLayer1 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_95CI.lyr") sourceLayer2 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_95CI_diff.lyr") sourceLayer3 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_mean.lyr") sourceLayer4 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_mean_diff.lyr") sourceLayer5 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_depos_diff.lyr") sourceLayer6 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_deposited.lyr") sourceLayer7 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_pass_diff.lyr") sourceLayer8 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_passages.lyr") sourceLayer9 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_tree_impacts.lyr") sourceLayer10 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_95CI.lyr") sourceLayer11 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_95CI_diff.lyr") sourceLayer12 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_mean.lyr") sourceLayer13 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_mean_diff.lyr") sourceLayer14 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Reach Probability [%].lyr") sourceLayer15 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Reach_prob_diff.lyr") sourceLayer16 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Rvol.lyr") sourceLayer17 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Rvol_diff.lyr") sourceLayer18 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Tree_impact_heights .lyr") sourceLayer19 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Vmax.lyr") sourceLayer20 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Vmax_diff.lyr") #Specifies Functions def shortname(name): name = name.rpartition("\\SH_")[2] print name name = name.replace(".","_") name = name.replace("\\","_") name = name.replace("_mdb_","_") print "this is the used name: "+ name return name print "specify mxd" #Specifies mxd mxd = arcpy.mapping.MapDocument(r"H:\\Desktop\\Masterarbeit\\test\\test1.mxd") print "done mxd spezifizieren" print "specify dataframe" #Specifies dataframe of interest df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] print "done specify df " #Turns all layers off print "turn visibility of all layers off" for lyr in arcpy.mapping.ListLayers(mxd,"",df): lyr.visible = False arcpy.RefreshTOC() arcpy.RefreshActiveView() print "visibility = False" #Turns backgroundlayers on print "turn backgroundlayer on: Visibility = true" for lyr in arcpy.mapping.ListLayers(mxd, "hill*", df): print lyr lyr.visible = True arcpy.RefreshTOC() arcpy.RefreshActiveView() for lyr in arcpy.mapping.ListLayers(mxd, "up*", df): print lyr lyr.visible = True arcpy.RefreshTOC() arcpy.RefreshActiveView() for lyr in arcpy.mapping.ListLayers(mxd, "swiss*", df): print lyr lyr.visible = True arcpy.RefreshTOC() arcpy.RefreshActiveView() print "background = visible" #lEGENDSTUFF: print "legende generieren" legend=arcpy.mapping.ListLayoutElements(mxd,"LEGEND_ELEMENT","Legend")[0] legend.autoAdd = True while legend.isOverflowing == True: legend.elementHeight = legend.elementHeight +0.1 print "start withE_95CI" #Loops through the layers given in the quotas (eg. beginning with E_95CI) and creates a list of Layers: for lyr in arcpy.mapping.ListLayers(mxd, "E_95CI", df): print lyr if lyr.isRasterLayer: arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer1) #For Each: Turn it on: lyr.visible = True print " visible: on" name =lyr.dataSource name=shortname(name) #name = name.rpartition("\\SH_")[2] #print name #name = name.replace(".","_") #name = name.replace("\\","_") #name = name.replace("_mdb_","_") print "this is the used name: "+ name arcpy.RefreshTOC() print " TOC refreshed" arcpy.RefreshActiveView() print " Active View refreshed" print "exporting .JPG" mxd.activeView = "PAGE_LAYOUT" arcpy.mapping.ExportToJPEG(mxd, r"H:\\Desktop\\maps\\e95ci\\SH_" + name+ ".jpg") lyr.visible = False #legend=arcpy.mapping.ListLayoutElements(mxd,"LEGEND_ELEMENT","")[0] #legend=arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0] #legend.autoAdd = True #newlz added lazers will be automaticallz added to the legend #legend.elementHeight=4 #legend.elementWidth=4 for lyr in arcpy.mapping.ListLayers(mxd, "N*", df): print lyr if lyr.isRasterLayer: arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer6) #For Each: Turn it on: lyr.visible = True print " visible: on" print " this is the Source" name =lyr.dataSource name=shortname(name) print "this is the used name: "+ name arcpy.RefreshTOC() print " TOC refreshed" arcpy.RefreshActiveView() print " Active View refreshed" print "exporting .JPG" mxd.activeView = "PAGE_LAYOUT" arcpy.mapping.ExportToJPEG(mxd, r"H:\\Desktop\\maps\\nr_deposited\\SH_" + name + ".jpg") lyr.visible = False # #print legend #legend=arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0] #legend.autoAdd = True #newlz added lazers will be automaticallz added to the legend #legend.elementHeight=4 #legend.elementWidth=4 print "done_" #print "start reach_probability" ##Loops through the layers given in the quotas (eg. reach_probability) and creates a list of Layers: #for lyr in arcpy.mapping.ListLayers(mxd, "reach_probability", df): #For Each: Turn it on: # lyr.visible= True # arcpy.RefreshTOC() # arcpy.RefreshActiveView() # arcpy.mapping.ExportToJPEG(mxd, r"H:\\Desktop\\map_export\\" + outfile, df) #print"done_2" #Saves mxd print "__________________________________________" print "_xxx____xx___xx___x__xxxxx________________" print "_x__x__x__x__x_x__x__x____________________" print "_x__x__x__x__x__x_x__xxx__________________" print "_xxx____xx___x___xx__xxxxx________________" print "__________________________________________" #Deletes the reference to the mxd from memory (not the actual mxd file) del mxd
... View more
04-18-2013
12:36 PM
|
0
|
2
|
378
|
POST
|
I tried your, kamkashem, proposed version. After importing "os", one error message disappeared :D. But the problem of over writing each output ("str(X)") with the next one is not solved yet. So, How can i accomplish that str(x) is something like Str(Xi) for i=1...80 Or even nicer i = name of group layer. Because the jpeg format is more sympathetic to me, i inspired me also from this thread: http://forums.arcgis.com/threads/63173-Problem-accessing-ModelBuilder-variable-in-a-python-script (especially the record from 07-27-2012 08:40 PM ). my actual piece of code is the following: # ---------------------------------------------------------------------------
# map_production.py
#
# Description: "Should" generate jpg layout outputs of the input layernames
# ---------------------------------------------------------------------------
print "START map production"
print "arcpy and os importieren"
import arcpy
import os, sys, string, arcgisscripting
print "done arcpy and os and so on import"
gp = arcgisscripting.create(9.3)
scriptVar=gp.GetParameterAsText(0)
outfile = "test" + scriptVar +".jpg"
print "specify mxd"
#Specifies mxd
mxd = arcpy.mapping.MapDocument(r"H:/Desktop/Masterarbeit/test/Besprechung_Schmitten_Neu_6.mxd")
print "done mxd spezifizieren"
print "specify dataframe"
#Specifies dataframe of interest
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
print "done specify df "
#Turns all layers off
print "turn visibility of all layers off"
for lyr in arcpy.mapping.ListLayers(mxd,"",df):
lyr.visible = False
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
print "visibility = False "
#Turns backgroundlayers on
print "turn backgroundlayer on: Visibility = true"
for lyr in arcpy.mapping.ListLayers(mxd, "hillshade*", df):
lyr.visible = True
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
print "background = visible"
print "start withE_95CI"
#Loops through the layers given in the quotas (eg. beginning with E_95CI) and creates a list of Layers:
for lyr in arcpy.mapping.ListLayers(mxd, "E_95CI", df):
print" produced list"
#For Each: Turn it on:
lyr.visible = True
print " visible: on"
arcpy.RefreshTOC()
print " TOC refreshed"
arcpy.RefreshActiveView()
print " Active View refreshed"
print "exporting for each layer starting with ""E_95CI"" a JPEG map within the folder map_export and the name construction ""outfile"" "
arcpy.mapping.ExportToJPEG(mxd, r"H://Desktop/map_export/" + outfile, df,df_export_width=1600, df_export_height=1200)
print "done_"
mxd.save()
print "done_ 20"
#Deletes the reference to the mxd from memory (not the actual mxd file)
del mxd While it is possible to generate a the list E_95CI, the export to jpeg fails. The python Shell output looks like this: START map production
arcpy and os importieren
done arcpy and os and so on import
specify mxd
done mxd spezifizieren
specify dataframe
done specify df
turn visibility of all layers off
visibility = False
turn backgroundlayer on: Visibility = true
background = visible
start withE_95CI
produced list
visible: on
TOC refreshed
Active View refreshed
exporting for each layer starting with E_95CI a JPEG map within the folder map_export and the name construction outfile
Traceback (most recent call last):
File "H:\Desktop\Masterarbeit\Python scripts\test2.py", line 60, in <module>
arcpy.mapping.ExportToJPEG(mxd, r"H://Desktop/map_export/" + outfile, df,df_export_width=1600, df_export_height=1200)
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_
return fn(*args, **kw)
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\mapping.py", line 686, in ExportToJPEG
layout.exportToJPEG(*args)
AttributeError: DataFrameObject: Error in executing ExportToJPEG Does anyone see a pissible solution? I am very happy to every answer!
... View more
03-21-2013
01:31 AM
|
0
|
0
|
281
|
POST
|
I tested it empirically. The solution is 3 layers can be input in a single query, but you can list many query in a row...
... View more
03-21-2013
01:28 AM
|
0
|
0
|
830
|
POST
|
Hi there, I have got aswell some problems with the Extract multi values to point tool. I exported the pythonscript of the tool and expanded it up to 72 inputlayers. Like that, it crashed. When I alter it in the manner, that just 3 Layers should be evaluated, it worked fine. So i ask myself: is there a maximum number of attachable layers to this tool? If so: How many? Thanks Cheers!
... View more
03-16-2013
06:37 AM
|
0
|
0
|
830
|
POST
|
Hi there, I'm trying to automate the map production of several rockfall-model outputs: I have got different rasterlayers (e.g. rockenergy, reach probability, passing height, ...) from different model scenarios (e.g. without forest, with forest, with forest gaps, ...). All with the same name in different grouplayers. All thogether there are more than 200 .asc rasters, that i want to get out of the GIS on to the paper. Unfortuately i haven't found an "out of the box" tool, so i began with my poor knowledge of python and the arcpy.mapper. Beneth is my result so far
# ---------------------------------------------------------------------------
# map_production.py
#
# Description: "Should" generate jpg layout outputs of the input layernames
# ---------------------------------------------------------------------------
print "START map production"
print "arcpy importieren"
import arcpy
print "done arcpy import"
print "mxd spezifizieren"
#Specifies mxd
mxd = arcpy.mapping.MapDocument(r"H:/Desktop/Masterarbeit/test/Besprechung_Schmitten_Neu_6.mxd")
print "done mxd spezifizieren"
print "dataframe spezifizieren"
#Specifies dataframe of interest
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
print "done df spezifizieren"
#Turns all layers off
"alle Layer unsichtbar machen"
for lyr in arcpy.mapping.ListLayers(mxd,"",df):
lyr.visible = False
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
"alle Layer unsichtbar gemacht"
#Turns backgroundlayers on
"Hintergrundlayer sichtbar machen"
for lyr in arcpy.mapping.ListLayers(mxd, "hillshade*", df):
lyr.visible = True
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
print "start E_95CI"
#Loops through the layers given in the quotas (eg. beginning with E_95CI) and creates a list of Layers:
for lyr in arcpy.mapping.ListLayers(mxd, "E_95CI", df):
#For Each: Turn it on:
lyr.visible= True
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
arcpy.mapping.ExportToJPEG(mxd, r"H://Desktop/e95_cl_jpg.test.jpg")
print "done_ 1"
#print "start reach_probability"
##Loops through the layers given in the quotas (eg. reach_probability) and creates a list of Layers:
#for lyr in arcpy.mapping.ListLayers(mxd, "reach_probability", df):
#For Each: Turn it on:
# lyr.visible= True
# arcpy.RefreshTOC()
# arcpy.RefreshActiveView()
# arcpy.mapping.ExportToJPEG(mxd, r"H://Desktop/e95_cl_jpg.test.jpg")
#print"done_2"
#Saves mxd
mxd.save()
print "done_ 20"
#Deletes the reference to the mxd from memory (not the actual mxd file)
del mxd
One main problem is, that after one exportet .jpg-map, the second would overwrite the first, which produces an error. How can i get an variable .jpg-output name? It would be perfect, when the name would differ by the name of the group-layer. The next one is, that there is nothing visible in the jpg. output beside the northarrow and scalebar. Not even the Background :S Does someone see my faults? Or does someone know an already existing tool for my problem :cool: ? Thanks a lot!
... View more
03-08-2013
01:55 AM
|
0
|
3
|
751
|
POST
|
Hi there, My aim is to get the weighted mean of different polygons (from the layer forest density) along different profiles (rockfall paths) according to the length of the line segments. This single value per profile is used for a rockfall-model (see http://www.rockfor.net), which takes the forest into account. [ATTACH=CONFIG]20481[/ATTACH] I know, it would be possible to get with the #intersect# tool the length of the profile within each polygon and then i could calculate the weighted mean by hand (length A*ValueA +Length B*value B ...). But because i want to do it for a lot of profiles, i am wondering, whether there is already such a tool implemented (Im using ArcGIS 10.1). It would be something in between #extract value to point# and #Line Statistics# --> Add Statistics to Line or so... Thanks for advices...
... View more
01-05-2013
10:20 PM
|
0
|
0
|
1620
|
POST
|
Hi Mel, I got the problem, why it stopped after two layers: it was due to the mxd.save() after every second layer symbolisation. Thanks a lot for all your Help and your Time you have invested! Now i can really work with the data, compare them and make useful maps!
... View more
01-03-2013
05:39 AM
|
0
|
0
|
785
|
POST
|
Hi, to load the layers to the mxd wasn't that hard. But instead of altering the code for each of the 20 (i recounted them:cool:) and dispatch them all one by one, i thought it should be possible to nest them. The result is the following code. First the nice thing about: the script worked totally through, all the 20. "dones" were printed. But when i opened afterwards the mxd i realised, that just the symbology of sourceLayer1 and sourceLayer2 were adapted. Do you see the fault or problem? # ---------------------------------------------------------------------------
# iteration durch raster_und symbol.py
# Created on: 2012-12-31 01:39:43.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------
import arcpy
#Specifies mxd
mxd = arcpy.mapping.MapDocument(r"H:/Desktop/Masterarbeit/test/Besprechung_Crap Ses.mxd")
#Specifies dataframe of interest
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
#Specifies layer file with the symbology you want to apply to the other raster layers
sourceLayer1 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_95CI.lyr")
sourceLayer2 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_95CI_diff.lyr")
sourceLayer3 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_mean.lyr")
sourceLayer4 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_mean_diff.lyr")
sourceLayer5 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_depos_diff.lyr")
sourceLayer6 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_deposited.lyr")
sourceLayer7 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_pass_diff.lyr")
sourceLayer8 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_passages.lyr")
sourceLayer9 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_tree_impacts.lyr")
sourceLayer10 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_95CI.lyr")
sourceLayer11 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_95CI_diff.lyr")
sourceLayer12 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_mean.lyr")
sourceLayer13 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_mean_diff.lyr")
sourceLayer14 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Reach Probability [%].lyr")
sourceLayer15 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Reach_prob_diff.lyr")
sourceLayer16 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Rvol.lyr")
sourceLayer17 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Rvol_diff.lyr")
sourceLayer18 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Tree_impact_heights .lyr")
sourceLayer19 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Vmax.lyr")
sourceLayer20 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Vmax_diff.lyr")
#Loops through layers in the first data frame in your mxd and
#creates a list of Layers starting with Reach_probability:
for lyr in arcpy.mapping.ListLayers(mxd, "E_95CI", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer1)
print "done_ 1"
for lyr in arcpy.mapping.ListLayers(mxd, "E_95CI_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer2)
#Saves mxd
mxd.save()
print "done_2"
for lyr in arcpy.mapping.ListLayers(mxd, "E_mean", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer3)
print "done_3"
for lyr in arcpy.mapping.ListLayers(mxd, "E_mean_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer4)
#Saves mxd
mxd.save()
print "done_4"
for lyr in arcpy.mapping.ListLayers(mxd, "Nr_depos_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer5)
print "done_5"
for lyr in arcpy.mapping.ListLayers(mxd, "Nr_deposited", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer6)
#Saves mxd
mxd.save()
print "done_6"
for lyr in arcpy.mapping.ListLayers(mxd, "Nr_pass_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer7)
print "done_7"
for lyr in arcpy.mapping.ListLayers(mxd, "Nr_passages", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer8)
#Saves mxd
mxd.save()
print "done_8"
for lyr in arcpy.mapping.ListLayers(mxd, "Nr_tree_impacts*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer9)
print "done_9"
for lyr in arcpy.mapping.ListLayers(mxd, "Ph_95CI", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer10)
#Saves mxd
mxd.save()
print "done_10"
for lyr in arcpy.mapping.ListLayers(mxd, "Ph_95CI_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer11)
print "done_11"
for lyr in arcpy.mapping.ListLayers(mxd, "Ph_mean", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer12)
#Saves mxd
mxd.save()
print "done_12"
for lyr in arcpy.mapping.ListLayers(mxd, "Ph_mean_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer13)
print "done_13"
for lyr in arcpy.mapping.ListLayers(mxd, "Reach Probability [%]*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer14)
#Saves mxd
mxd.save()
print "done_14"
for lyr in arcpy.mapping.ListLayers(mxd, "Reach_prob_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer15)
print "done_15"
for lyr in arcpy.mapping.ListLayers(mxd, "Rvol", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer16)
#Saves mxd
mxd.save()
print "done_15"
for lyr in arcpy.mapping.ListLayers(mxd, "Rvol_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer17)
print "done_17"
for lyr in arcpy.mapping.ListLayers(mxd, "Tree_impact_heights *", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer18)
#Saves mxd
mxd.save()
print "done_18"
for lyr in arcpy.mapping.ListLayers(mxd, "Vmax", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer19)
print "done_19"
for lyr in arcpy.mapping.ListLayers(mxd, "Vmax_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer20)
#Saves mxd
mxd.save()
print "done_ 20! :D ! "
#Deletes the reference to the mxd from memory (not the actual mxd file)
del mxd
In the "search function", i had intentionally dropped the * within the "E_95CI", because the layers are called exactly like this and there are other layers called E_95CI_diff_... . Suggestions are welcome. Also for the walk function, I arranged more a workaround (with a long typing code..) than to delve into the walk-function...
... View more
01-02-2013
11:00 AM
|
1
|
0
|
785
|
POST
|
Wow cool, this script worked well:), Thanks!! I asked for looping through a folder, because i haven't loaded yet all raster-layers into the .mxd. This is a bit extra work, because i have to generate sub- and sub-sub-folders. But by now, i have prepared my seven different .lyr-source files. Next step will be to load all layers into the map and then i will apply the script again to all layers with all different source layers...
... View more
01-02-2013
04:03 AM
|
0
|
0
|
785
|
POST
|
My current version looks like this import arcpy mxd = arcpy.mapping.MapDocument(r"H:/Desktop/Masterarbeit/test/Besprechung_Crap Ses.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] lyrFile = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files\Reach Probability [%].lyr") for lyr in arcpy.mapping.ListLayers(mxd, "Reach_probability", df): arcpy.mapping.UpdateLayer(df, lyr, lyrFile, True) if lyr.isRasterLayer == TRUE: lyr.symbology.reclassify() del mxd, df, lyr, lyrFile which implies this error message Traceback (most recent call last): File "H:/Desktop/Masterarbeit/test_1", line 19, in <module> arcpy.mapping.UpdateLayer(df, lyr, lyrFile, True) File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\mapping.py", line 1460, in UpdateLayer update_layer._arc_object.renderer = source_layer._arc_object.renderer RuntimeError: LayerObject: Set attribute renderer does not exist Am I on the right track? how can I set the attribute renderer? Thanks for feedbacks
... View more
01-01-2013
08:45 AM
|
0
|
0
|
785
|
POST
|
Hi Melanie, Thanks for your reply and the remark, that the "iterations" just works within the modelbuilder. The mentioned for-loop construction within a map document (.mxd) would be useful, even better would be one within a workspace or folder. But as far as I can assess it (-> ListLayers), this is not possible this way. Thanks for your help, I would really appreciate a code example... 🙂 i'm trying and trying... but dont get anywhere...
... View more
01-01-2013
03:07 AM
|
0
|
0
|
785
|
POST
|
HI THERE i have to szmbolyse a lot of rasterdatasets the same way. as I allready read, it should be possible to use arcpy.mapper i tried it to create a iteration< to get all rasters with the name #Reach_probability# out of my workspace. afterwards it would be realz nice< if those rasters (and not justone, all thogether > multiple) could figure as input rasters of the tool #apply symbology from layer#... but this is not working.. here my code *exported from modelbuilder# # --------------------------------------------------------------------------- # iteration durch raster_und symbol.py # Created on: 2012-12-31 01:39:43.00000 # (generated by ArcGIS/ModelBuilder) # Description: # --------------------------------------------------------------------------- # Import arcpy module import arcpy # Load required toolboxes arcpy.ImportToolbox("Model Functions") # Local variables: RESULTATE = "\\\\ad.geo.unizh.ch\\home\\myhome\\Desktop\\Masterarbeit\\test\\RESULTATE" Reach_Probability_____lyr = "\\\\ad.geo.unizh.ch\\home\\myhome\\Desktop\\Masterarbeit\\test\\RESULTATE\\lyr_files\\Reach Probability [%].lyr" # Process: Iterate Rasters arcpy.IterateRasters_mb(RESULTATE, "Reach_probability*", "ASC", "RECURSIVE") # Process: Apply Symbology From Layer tempEnvironment0 = arcpy.env.extent arcpy.env.extent = "\\\\ad.geo.unizh.ch\\home\\myhome\\Desktop\\Masterarbeit\\test\\RESULTATE\\Raster" arcpy.ApplySymbologyFromLayer_management("", Reach_Probability_____lyr) arcpy.env.extent = tempEnvironment0 thanks for any help or tips
... View more
12-30-2012
02:53 PM
|
1
|
8
|
3822
|
Title | Kudos | Posted |
---|---|---|
1 | 01-02-2013 11:00 AM | |
1 | 12-30-2012 02:53 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|