UpdateLayer and ApplySymbologyFromLayer doesn't seem to be working

المشرف العام

Administrator
طاقم الإدارة
Working environment/Modules

import arcpyimport arcpy.mapping

arcpy.env.workspace = "C:\GEP_662\nyc_data.gdb"

Permit overwrite data

arcpy.env.overwriteOutput = True

fc = "TB_CORE_DATA"

fc = "C:\GEP_662\jenn_test.gdb\TB_CORE_DATA"

fc1 = "Tampa_Water"rasterLayer = "C:\GEP_662\Final_Project\TOC_IDW1.lyr"

checks if feature class file exist

if arcpy.Exists(fc):

#print "It exists!"

else:

#print "doesn't Exist"

arcpy.CheckOutExtension("GeoStats")

Create An Inverse Distance Weighting Raster Using Geostatistical Analyst Wizard

arcpy.IDW_ga(fc, "TOC", "", "TOC_IDW", "1.45839999753707E-03", "2", arcpy.SearchNeighborhoodStandard(0.15416857624789992, 0.15416857624789992, 0, 15, 10, "ONE_SECTOR"), "")

arcpy.CheckInExtension("GeoStats")

print "Geostats Done"

The following code will load a TOC_IDW raster into a new raster layer, add it to the first dataframe of the specified mxd, and then save the mxd.

It will also add Tampa_Water & TB_CORE_DATA feature classes to map

mxdPath = r'C:\GEP_662\Final_Project\Final_Project.mxd'rasterPath = r'TOC_IDW'rasterLayerName = 'TOC_IDW_LYR'

md = arcpy.mapping.MapDocument(mxdPath)df = arcpy.mapping.ListDataFrames(md)[0]result = arcpy.MakeRasterLayer_management(rasterPath, rasterLayerName)layer = result.getOutput(0)arcpy.mapping.AddLayer(df, layer, 'BOTTOM')

print " Raster Layer Done"

Add Tampa_Water & TB_CORE_DATA to map

ReferenceLayer = arcpy.mapping.ListLayers(md, layer, df)[0]result1 = arcpy.MakeFeatureLayer_management(fc1, "Tampa_Water_Lyr")result2 = arcpy.MakeFeatureLayer_management(fc, "TB_CORE_DATA_Lyr")layer1 = arcpy.mapping.Layer("Tampa_Water_Lyr")layer2 = arcpy.mapping.Layer("TB_CORE_DATA_Lyr")arcpy.mapping.InsertLayer(df, ReferenceLayer, layer1, "Before")arcpy.mapping.InsertLayer(df, ReferenceLayer, layer2, "After") md.save()

print 'Feature Layer Done'

Apply the symbology from the symbology layer to the input layer

arcpy.ApplySymbologyFromLayer_management(rasterLayerName, rasterLayer)

Updates Layer symbology

UpdateLayer = arcpy.mapping.ListLayers(md, layer, df)[0]SourceLayer= arcpy.mapping.Layer(r"C:\GEP_662\Final_Project\TOC_IDW1.lyr")arcpy.mapping.UpdateLayer(df, SourceLayer, UpdateLayer, True)

print " Symbology Done"

Here is the problem I have been having, I have been trying to update the symbology of my raster layer file but nothing is happening. I don't get any error messages from using updateLayer or ApplySymbologyFromLayer. It also printed symbology done like everything was succesful but when I open the .mxd to check, I don't see any changes in my raster. Can anyone tell me what I am doing wrong? Any help will be much appreciated

Also I have been trying to clip my raster IDW layer by the Tampa water feature class file with no luck. I know how to do it using the ArcGIS data frame properties but not with scripting...does anyone know how to script it?



أكثر...
 
أعلى