ArcMap+ArcPy批量生成油井点PDF报告

利用 ArcMap 和 ArcPy 批量生成油井点之记并导出 PDF

准备工作

确保安装 ArcMap 10.x 及以上版本和 Python 环境。准备包含油井点数据的 Shapefile 或地理数据库,字段需包含井名、坐标、深度等关键信息。设计好 MXD 模板,布局视图中包含图名、图例、比例尺和动态文本(如井名、坐标等)。

创建 MXD 模板

在 ArcMap 中新建地图文档,加载油井点数据。进入布局视图,插入动态文本(如 %井名%),绑定属性字段。调整图面元素(比例尺、指北针)位置,保存为 WellTemplate.mxd

编写 ArcPy 脚本

import arcpy
import os

# 设置路径
mxd_template = r"C:\Data\WellTemplate.mxd"
output_folder = r"C:\Output\PDFs"
well_points = r"C:\Data\Wells.shp"

# 创建输出文件夹
if not os.path.exists(output_folder):
    os.makedirs(output_folder)

# 获取油井点游标
with arcpy.da.SearchCursor(well_points, ["井名", "X", "Y"]) as cursor:
    for row in cursor:
        well_name, x, y = row
        mxd = arcpy.mapping.MapDocument(mxd_template)
        
        # 更新动态文本
        for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
            if elm.text == "%井名%":
                elm.text = well_name
            elif elm.text == "%坐标%":
                elm.text = f"X: {x}, Y: {y}"
        
        # 导出PDF
        output_pdf = os.path.join(output_folder, f"{well_name}.pdf")
        arcpy.mapping.ExportToPDF(mxd, output_pdf)
        
        del mxd

动态调整布局

若需根据井数调整图幅大小,可在脚本中添加缩放逻辑:

df = arcpy.mapping.ListDataFrames(mxd)[0]
df.scale = 5000  # 固定比例尺
df.panToExtent(arcpy.Extent(x-1000, y-1000, x+1000, y+1000))  # 居中显示

批量处理优化

使用多进程加速大批量处理:

from multiprocessing import Pool

def export_pdf(args):
    well_name, x, y = args
    # 同上文导出逻辑

with arcpy.da.SearchCursor(well_points, ["井名", "X", "Y"]) as cursor:
    pool = Pool(4)  # 4进程
    pool.map(export_pdf, cursor)

常见问题解决

若出现文本重叠,可在 MXD 模板中预留足够空间。坐标显示异常时,检查数据投影是否一致。导出失败时,确认输出路径无特殊字符。

结果验证

生成的 PDF 应包含井名、坐标等动态信息,图面元素布局整齐。可通过脚本日志检查是否有未处理的井点:

print(f"已生成 {len(os.listdir(output_folder))} 个PDF文件")

扩展应用

此方法适用于其他点状地物之记生成,如气象站、监测点等。通过修改 MXD 模板和字段绑定,可快速适配不同需求。

5G.okacbd051.asia/PoSt/1123_979524.HtM
5G.okacbd052.asia/PoSt/1123_931300.HtM
5G.okacbd053.asia/PoSt/1123_808374.HtM
5G.okacbd054.asia/PoSt/1123_847160.HtM
5G.okacbd055.asia/PoSt/1123_360284.HtM
5G.okacbd056.asia/PoSt/1123_349558.HtM
5G.okacbd057.asia/PoSt/1123_238943.HtM
5G.okacbd058.asia/PoSt/1123_380777.HtM
5G.okacbd059.asia/PoSt/1123_648135.HtM
5G.okacbd060.asia/PoSt/1123_347202.HtM
5G.okacbd051.asia/PoSt/1123_906092.HtM
5G.okacbd052.asia/PoSt/1123_729279.HtM
5G.okacbd053.asia/PoSt/1123_777600.HtM
5G.okacbd054.asia/PoSt/1123_148213.HtM
5G.okacbd055.asia/PoSt/1123_696504.HtM
5G.okacbd056.asia/PoSt/1123_763578.HtM
5G.okacbd057.asia/PoSt/1123_246714.HtM
5G.okacbd058.asia/PoSt/1123_848319.HtM
5G.okacbd059.asia/PoSt/1123_729767.HtM
5G.okacbd060.asia/PoSt/1123_833498.HtM
5G.okacbd051.asia/PoSt/1123_031566.HtM
5G.okacbd052.asia/PoSt/1123_497061.HtM
5G.okacbd053.asia/PoSt/1123_743430.HtM
5G.okacbd054.asia/PoSt/1123_439568.HtM
5G.okacbd055.asia/PoSt/1123_106404.HtM
5G.okacbd056.asia/PoSt/1123_558063.HtM
5G.okacbd057.asia/PoSt/1123_716966.HtM
5G.okacbd058.asia/PoSt/1123_801939.HtM
5G.okacbd059.asia/PoSt/1123_998388.HtM
5G.okacbd060.asia/PoSt/1123_446110.HtM
5G.okacbd051.asia/PoSt/1123_367955.HtM
5G.okacbd052.asia/PoSt/1123_954252.HtM
5G.okacbd053.asia/PoSt/1123_773286.HtM
5G.okacbd054.asia/PoSt/1123_947559.HtM
5G.okacbd055.asia/PoSt/1123_905680.HtM
5G.okacbd056.asia/PoSt/1123_414771.HtM
5G.okacbd057.asia/PoSt/1123_195796.HtM
5G.okacbd058.asia/PoSt/1123_404879.HtM
5G.okacbd059.asia/PoSt/1123_402955.HtM
5G.okacbd060.asia/PoSt/1123_415274.HtM
5G.okacbd061.asia/PoSt/1123_748020.HtM
5G.okacbd062.asia/PoSt/1123_638191.HtM
5G.okacbd063.asia/PoSt/1123_874952.HtM
5G.okacbd064.asia/PoSt/1123_377793.HtM
5G.okacbd065.asia/PoSt/1123_196929.HtM
5G.okacbd066.asia/PoSt/1123_889999.HtM
5G.okacbd067.asia/PoSt/1123_003906.HtM
5G.okacbd068.asia/PoSt/1123_234433.HtM
5G.okacbd069.asia/PoSt/1123_623508.HtM
5G.okacbd070.asia/PoSt/1123_434661.HtM
5G.okacbd061.asia/PoSt/1123_630068.HtM
5G.okacbd062.asia/PoSt/1123_598048.HtM
5G.okacbd063.asia/PoSt/1123_354782.HtM
5G.okacbd064.asia/PoSt/1123_603923.HtM
5G.okacbd065.asia/PoSt/1123_169382.HtM
5G.okacbd066.asia/PoSt/1123_552374.HtM
5G.okacbd067.asia/PoSt/1123_569423.HtM
5G.okacbd068.asia/PoSt/1123_434115.HtM
5G.okacbd069.asia/PoSt/1123_997042.HtM
5G.okacbd070.asia/PoSt/1123_118256.HtM
5G.okacbd061.asia/PoSt/1123_505360.HtM
5G.okacbd062.asia/PoSt/1123_979445.HtM
5G.okacbd063.asia/PoSt/1123_894849.HtM
5G.okacbd064.asia/PoSt/1123_016595.HtM
5G.okacbd065.asia/PoSt/1123_950179.HtM
5G.okacbd066.asia/PoSt/1123_363469.HtM
5G.okacbd067.asia/PoSt/1123_452165.HtM
5G.okacbd068.asia/PoSt/1123_925740.HtM
5G.okacbd069.asia/PoSt/1123_744449.HtM
5G.okacbd070.asia/PoSt/1123_761347.HtM
5G.okacbd061.asia/PoSt/1123_726251.HtM
5G.okacbd062.asia/PoSt/1123_372137.HtM
5G.okacbd063.asia/PoSt/1123_083997.HtM
5G.okacbd064.asia/PoSt/1123_133828.HtM
5G.okacbd065.asia/PoSt/1123_492537.HtM
5G.okacbd066.asia/PoSt/1123_275680.HtM
5G.okacbd067.asia/PoSt/1123_843471.HtM
5G.okacbd068.asia/PoSt/1123_937868.HtM
5G.okacbd069.asia/PoSt/1123_091904.HtM
5G.okacbd070.asia/PoSt/1123_465062.HtM

#牛客AI配图神器#

全部评论

相关推荐

不愿透露姓名的神秘牛友
10-09 16:39
已编辑
英俊的靓仔offer...:我感觉吧第二个寻迹小车的项目有点配不上你的学历了,写上去扣分了都可能对你来说,好歹是211硕士嘛,写在我这种二本混子的简历上还说得过去,个人观点哦,能再有个好点的项目应该会好很多,或者干脆不写第二个换个啥实习经历?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务