import arcpy, os, sys
def MakeRec_LL(llx, lly, w, h):
xyRecList = [[llx, lly], [llx, lly+h], [llx+w,lly+h], [llx+w,lly], [llx,lly]]
array = arcpy.Array([arcpy.Point(*coords) for coords in xyRecList])
rec = arcpy.Polygon(array)
return rec
clip_feature_class = r"E:\潜源图件\区域范围\区域范围.shp"
input_feature_classes = [
r"E:\潜源图件\地震构造区\全国地震构造区100720_region.shp",
r"E:\潜源图件\风险普查潜源\全国潜源调整20220422_region.shp",
r"E:\潜源图件\潜源图绘制\潜源图.gdb\agnp_ExportFeatures6",
# 添加更多输入要素类的路径...
]
new_folder = input("请输入新文件夹名称:")
new_folder_path = os.path.join(r"E:\潜源图件\调试", new_folder)
os.makedirs(new_folder_path, exist_ok=True)
for input_feature_class in input_feature_classes:
output_feature_class = os.path.join(new_folder_path, os.path.basename(input_feature_class))
arcpy.analysis.Clip(input_feature_class, clip_feature_class, output_feature_class)
aprx = arcpy.mp.ArcGISProject(r"E:\潜源图件\无模板潜源\潜源绘制.aprx")
aprxmap = aprx.createMap(new_folder + '_Map', 'MAP')
if os.path.exists(new_folder_path):
shp_files = [os.path.join(root, file) for root, dirs, files in os.walk(new_folder_path) for file in files if
file.endswith(".shp")]
for shp_file in shp_files:
if shp_file.lower().endswith(".shp"):
aprxmap.addDataFromPath(shp_file)
print("数据加载完成并保存到项目文件中。")
else:
print("指定的文件夹不存在,请检查路径是否正确。")
aprxlayout = aprx.createLayout(210, 297, 'MILLIMETER', new_folder + '_Layout')
mf = aprxlayout.createMapFrame(MakeRec_LL(5,120,200,170), aprxmap, new_folder + 'MapFrame')
mf.camera.setExtent(arcpy.Describe(clip_feature_class).extent)
aprx.save()