This is my first stab at python/arcpy and need some help!
I have numerous point shapefiles that I am trying to apply a specific symbology to and create jpeg files of the same map for each symbolized shapefile. I am trying to make the filenames and the input and output paths dynamic based on my file structure (right now I am only working with the 'Jan' files).
When running the script (version provided below) in the ArcMap python window the shapefiles are added with the desired symbology (see below).
.
However, the output jpeg does not contain the desired symbology (see image below). I think it may have to do with saving the mxd before the jpeg is created? It doesn't seem like the mxd is being updated?
Using mxd as "CURRENT" and mxd.save() commands, the symbology is not applied appropriately when the shapefiles are added to the document. I have tried saving a copy mxd and exporting from that file but that doesn't seem to get the job done either as the symbology is again, not applied.
Running the script externally with mxd.save() all 26 of the jpeg images are of the first shapefile added without the desired symbology. Something funky is going on.
Thanks in advance!
import arcpy, shutil, globfrom arcpy import envmonth_dir = ["Jan"]#, "Feb", "Mar", "Apr", "May", "Jun", "July", "Aug", "Sep", "Oct", "Nov", "Dec"]#####assigns the mxd file location to a variable#####mxd = arcpy.mapping.MapDocument(r"C:\Users\Craig\OneDrive\Documents\GraduateSchool\Thesis\Data\GIS_Data\WaterQualityData\WQ_Maps.mxd")#mxd = arcpy.mapping.MapDocument("CURRENT")copy_mxd = arcpy.mapping.MapDocument(r"C:\Users\Craig\OneDrive\Documents\GraduateSchool\Thesis\Data\GIS_Data\WaterQualityData\WQ_Maps_copy.mxd")#####returns a list of DataFrame objects that exist in the mxd#####df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]sourceLayer = arcpy.mapping.Layer(r"C:\Users\Craig\OneDrive\Documents\GraduateSchool\Thesis\Data\GIS_Data\WaterQualityData\ptSymbology.lyr")for month in month_dir: arcpy.env.workspace = r"C:\Users\Craig\OneDrive\Documents\GraduateSchool\Thesis\Data\GIS_Data\WaterQualityData\WaterQualityMacros\CSVFiles\%s\shpfiles" % month pdf_output_wrkspace = r"C:\Users\Craig\OneDrive\Documents\GraduateSchool\Thesis\Data\GIS_Data\WaterQualityData\WaterQualityMacros\CSVFiles\%s\pdfs" % month shpfile_list = glob.glob(env.workspace + "\*.shp")for layer in shpfile_list: addlayer = arcpy.mapping.Layer(layer) #print addlayer arcpy.mapping.AddLayer(df, addlayer, "TOP") #####the following lines will update the layers symbology type to the type specified as source layer##### arcpy.mapping.UpdateLayer(df, addlayer, sourceLayer, True) #####the following will apply the desired symbology settings to shpfile##### if addlayer.symbologyType == "GRADUATED_COLORS": value_field = "Year_" + layer.rpartition(month + "Max")[2] value_field = value_field.rpartition(".shp")[0] print value_field addlayer.symbology.valueField = value_field arcpy.ApplySymbologyFromLayer_management(addlayer, sourceLayer) arcpy.RefreshTOC() arcpy.RefreshActiveView() #mxd.save() #mxd.saveACopy(copy_mxd) jpeg_path = pdf_output_wrkspace + '\\' + str(addlayer) + ".jpg" arcpy.mapping.ExportToJPEG(mxd, jpeg_path) addlayer.visible = False
أكثر...
I have numerous point shapefiles that I am trying to apply a specific symbology to and create jpeg files of the same map for each symbolized shapefile. I am trying to make the filenames and the input and output paths dynamic based on my file structure (right now I am only working with the 'Jan' files).
When running the script (version provided below) in the ArcMap python window the shapefiles are added with the desired symbology (see below).

However, the output jpeg does not contain the desired symbology (see image below). I think it may have to do with saving the mxd before the jpeg is created? It doesn't seem like the mxd is being updated?

Using mxd as "CURRENT" and mxd.save() commands, the symbology is not applied appropriately when the shapefiles are added to the document. I have tried saving a copy mxd and exporting from that file but that doesn't seem to get the job done either as the symbology is again, not applied.
Running the script externally with mxd.save() all 26 of the jpeg images are of the first shapefile added without the desired symbology. Something funky is going on.
Thanks in advance!
import arcpy, shutil, globfrom arcpy import envmonth_dir = ["Jan"]#, "Feb", "Mar", "Apr", "May", "Jun", "July", "Aug", "Sep", "Oct", "Nov", "Dec"]#####assigns the mxd file location to a variable#####mxd = arcpy.mapping.MapDocument(r"C:\Users\Craig\OneDrive\Documents\GraduateSchool\Thesis\Data\GIS_Data\WaterQualityData\WQ_Maps.mxd")#mxd = arcpy.mapping.MapDocument("CURRENT")copy_mxd = arcpy.mapping.MapDocument(r"C:\Users\Craig\OneDrive\Documents\GraduateSchool\Thesis\Data\GIS_Data\WaterQualityData\WQ_Maps_copy.mxd")#####returns a list of DataFrame objects that exist in the mxd#####df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]sourceLayer = arcpy.mapping.Layer(r"C:\Users\Craig\OneDrive\Documents\GraduateSchool\Thesis\Data\GIS_Data\WaterQualityData\ptSymbology.lyr")for month in month_dir: arcpy.env.workspace = r"C:\Users\Craig\OneDrive\Documents\GraduateSchool\Thesis\Data\GIS_Data\WaterQualityData\WaterQualityMacros\CSVFiles\%s\shpfiles" % month pdf_output_wrkspace = r"C:\Users\Craig\OneDrive\Documents\GraduateSchool\Thesis\Data\GIS_Data\WaterQualityData\WaterQualityMacros\CSVFiles\%s\pdfs" % month shpfile_list = glob.glob(env.workspace + "\*.shp")for layer in shpfile_list: addlayer = arcpy.mapping.Layer(layer) #print addlayer arcpy.mapping.AddLayer(df, addlayer, "TOP") #####the following lines will update the layers symbology type to the type specified as source layer##### arcpy.mapping.UpdateLayer(df, addlayer, sourceLayer, True) #####the following will apply the desired symbology settings to shpfile##### if addlayer.symbologyType == "GRADUATED_COLORS": value_field = "Year_" + layer.rpartition(month + "Max")[2] value_field = value_field.rpartition(".shp")[0] print value_field addlayer.symbology.valueField = value_field arcpy.ApplySymbologyFromLayer_management(addlayer, sourceLayer) arcpy.RefreshTOC() arcpy.RefreshActiveView() #mxd.save() #mxd.saveACopy(copy_mxd) jpeg_path = pdf_output_wrkspace + '\\' + str(addlayer) + ".jpg" arcpy.mapping.ExportToJPEG(mxd, jpeg_path) addlayer.visible = False
أكثر...