POST
|
Hi, I am trying to automate the export of several rasters applied to a certain Layout.mxd using the following steps (simplified): mxd = arcpy.mapping.MapDocument(r'D:\MyFolder\MyLayout.mxd')
df = arcpy.mapping.ListDataFrames(mxd)[0] source_lyr = arcpy.mapping.ListLayers(mxd, "sym_lyr", df)[0] target_lyr = arcpy.mapping.ListLayers(mxd, "tar_lyr", df)[0] arcpy.mapping.UpdateLayer(df, target_lyr, source_lyr) The target_lyr- Layers are imported rasters and the import works perfectly - the same for the PDF-export directly after this code sample. The problem is that "UpdateLayer" basically has no effect at all. When I try to run the above code in ArcMap Desktop, it won't work neither unless I replace mxd = arcpy.mapping.MapDocument(r'D:\MyFolder\MyLayout.mxd') with mxd = arcpy.mapping.MapDocument("CURRENT") However, I can't apply "CURRENT" in my Python script because it is not running in Foreground of the opened "MyLayout.mxd". It is also impossible for me to implement my Python Script as an AddIn of ArcMap because the export-map only is a subroutine of a complex program that needs to output maps. In addition, I tried the following: Adding "symbology_only = True" Applying arcpy.RefreshActiveView () and arcpy.RefreshTOC on multiple places Several other ways of writing the path in arcpy.mapping.MapDocument(path) Other methods of adding layers, but this seems odd because mxd.saveACopy(copy.mxd) shows that copy.mxd perfectly looks like it should look, only without the desired symbology; but using arcpy.mapping.MapDocument("CURRENT") directly in copy.mxd with the above code sequence will apply the desired symbology! Using arcpy.ApplySymbologyFromLayer_management(target_lyr, source_lyr) Does anyone have an idea how else I can apply the symbology of source_lyr to target_lyr or how I can define step-by-step the symbology using a defined classified colorjet (the colors are very important in this case)? Otherwise, does anyone know what exactly makes that "CURRENT" works but the "ABSOLUTE_PATH" does not, resp., how I can fix the issue? (I'm using the ArcGISx6410.5 python interpreter) I am grateful for any idea or proposition. Sebastian
... View more
02-27-2018
11:15 AM
|
0
|
0
|
891
|
POST
|
Hi, Map processing can take time - for other python applications, I successfully applied the concurrent.future package but python crashes in combination with arcpy. My guess is a problem with the license CheckOut (server licenses) which works fine with multiple calls of the ArcGIS 10.5 GUI but not with python. Here an example of my code: import concurrent.futures
import arcpy
def sub(parameter): arcpy.CheckOutExtension('Spatial') lifespan = Lifespan_Assessment(parameter) arcpy.CheckInExtension('Spatial') # release license def main(): test_parameters = np.array(["parameter1", "parameter2", "parameter3"]) with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor: executor.submit(sub, test_parameters[0]) executor.submit(sub, test_parameters[1]) executor.submit(sub, test_parameters[2]) if __name__ == "__main__": main() Running this code leads to either: 1) Program crashes or 2) Program is non-responsive (without crashing but is has the same utility as crashing though) Alternatively, I tried calling CheckOutExtension('Spatial') before the "executor.submit(...)" or within my class "Lifespan_Assessment()". Both options lead to python crashes. Does anyone have experience with applying concurrent.features on arcpy? What am I doing wrong? Does anyone know alternatives? I'm grateful for any kind of hint - thanks in advance, Sebastian
... View more
12-14-2017
12:00 PM
|
0
|
0
|
582
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|