美文网首页
ArcGIS工具箱并行化改造

ArcGIS工具箱并行化改造

作者: 依旧水木天 | 来源:发表于2017-02-10 10:26 被阅读0次

    1、总述

    通过使用Map函数,对ArcPy中的GP工具进行少量的改造,从而达到并行化调用的目的。

    2、Map函数

    在使用ArcPy进行批处理的过程中,虽然简化了很多手动的操作,但是对于大量重复性的操作并没有一个效率上的考虑。因此在这一部分通过使用Python自带的map函数,在讲GP工具的函数稍加改造的基础之上采用并行的方式来提高处理效率。
    简而言之,就是将原本的循环操作,改成map函数可以使用的形式,从而采用并行的方式进行处理。前提是相应的GP工具是支持同时操作,并避免同时写入的操作等。
    Map函数的详细介绍,参考http://blog.jobbole.com/58700/

    3、GP工具改造示例

    如下所示为GP工具函数改造的过程,改造起来也比较简单,将原本GP工具中的函数的参数作为一个列表传入,对于一些默认的参数可以不传入,在改造过程中写死,从而减少不必要的参数。如下图所示,是对求交函数进行的改造,对于求交函数,一般情况下,必备的参数有两个需要相交的图层以及结果图层。如下图所示:

    # -*- coding: utf-8 -*-
    import arcpy
    from arcpy import env
    from multiprocessing import Pool
    # obtains the intersect
    def mapIntersect_analysis(d):
        print(d)
        a = d[0]
        b = d[1]
        c = d[2]
        if arcpy.Exists(c):
            arcpy.Delete_management(c)
        arcpy.Intersect_analysis ([a,b], c, "ALL", "", "")
        return "successful!"
    if __name__=="__main__":
        # 改成自己的路径
        src = r"H:\tt"
        env.workspace = src
        workspaceList = arcpy.ListWorkspaces("","FileGDB")
        parameters = []
        for w in workspaceList:
            first = "{0}\\{1}".format(w, 'data01')
            second = "{0}\\{1}".format(w, 'data02')
            third = "{0}\\{1}".format(w, 'data03')
            d = [first,second,third]
            parameters.append(d)
        pool = Pool(4)
        results = pool.map(mapIntersect_analysis,parameters)
        # print the results
        print(results)
        pool.close()
        pool.join()
    

    相关文章

      网友评论

          本文标题:ArcGIS工具箱并行化改造

          本文链接:https://www.haomeiwen.com/subject/iwlgittx.html