当前位置:网站首页>Arcpy -- use of insertlayer() function: adding layers to map documents

Arcpy -- use of insertlayer() function: adding layers to map documents

2022-06-26 13:10:00 YuanYWRS

【 Statement 】: The code and data of this book come from 【 be based on arcgis Of python Programming tips 】.

【 Ideas 】:insertlayer() Function can be used to add and insert data into a certain position of the layer , It requires a reference layer to specify the location , The new layer will be added above or below the specified reference layer .

【 Be careful 】:InsertLayer() The function requires a reference layer , Use this function for all data frames that cannot be empty .

【 operation 】:

 Insert picture description here

>>> import arcpy.mapping as mapping   # Used to import arcpy.mapping modular 
>>> mxd=mapping.MapDocument("CURRENT")  # Reference the current map document , Assign this reference to a variable 
>>> df=mapping.ListDataFrames(mxd,"Crime")[0]   # Get right Crime( Current document ) Data frame reference .
>>> refLayer=mapping.ListLayers(mxd,"Burglaries*",df)[0]  # Define reference layers 
>>> insertLayer=mapping.Layer(r"D:\ To store temporarily \ArcpyBook\data\CityOfSanAntonio.gdb\Crimes2009")   # Defines the insertion layer relative to the reference layer 
>>> mapping.InsertLayer(df,refLayer,insertLayer,"BEFORE")    # Adding layers to a data frame 
>>> 

【 Result display 】:
 Insert picture description here

原网站

版权声明
本文为[YuanYWRS]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261225561629.html