【问题标题】:arcpy in django doesnot rundjango 中的 arcpy 无法运行
【发布时间】:2019-11-02 19:14:51
【问题描述】:

我有一个使用 arcpy 模型的 ArcGIS 脚本。我想将它与 Django 结合起来。该脚本在控制台上成功运行,但是,当使用 Django 运行时,我发现 arcpy 函数没有运行。所以我对它做了一个简单的测试,得到了同样的结果。

test.py

import arcpy
import os

def test_arcpy():
    tempFolder = arcpy.env.scratchFolder
    tempGDBPath = os.path.join(tempFolder, 'test.gdb')
    arcpy.env.overwriteOutput = True
    if not arcpy.Exists(tempGDBPath):
        arcpy.AddMessage('create..')
        arcpy.CreateFileGDB_management(tempFolder, 'test.gdb')
    return arcpy.Exists(tempGDBPath)

views.py

from django.http import HttpResponse
from . import test
def t(request):
    msg = str(test.test_arcpy())
    return HttpResponse(msg)

如果我在控制台中运行 test.py,它返回 True。但如果我在 django 中运行它,它总是返回 false。如果我不能解决它,我就不能在 django 中制作更难的脚本。你能帮助我吗? 我在Flask app with ArcGIS, Arcpy does not run找到了类似的问题,但是这个问题没有解决方案。

【问题讨论】:

    标签: django arcpy


    【解决方案1】:

    我想我可以使用子进程模型在控制台中运行 arcpy 脚本,然后将控制台消息返回给 django 函数。 但我真的很想知道 arcpy 是否可以与 django 一起运行。

    【讨论】:

      【解决方案2】:

      我在 Flask 中遇到了和你一样的问题。

      我检查了arcpy 中的源代码,发现arcgisscripting.pyd 文件中有一个错误,而我从Flask 触发arcpy.Exists()。我失去了任何线索。在 ESRI 在线博客上搜索了一些案例后,我确实发现这是 arcpy 中的一个错误。所以我建议你:

      1. 尝试更高版本的 arcpy。(我当前的版本是 10.1)
      2. 尝试在控制台中运行您的代码
      3. 尝试像from multiprocessing import Queue, Process一样运行消息队列
      4. 尽量不要使用该功能。就我而言,我避免使用arcpy.Exists()
      5. 尝试在 arcServer 中使用 64 位 arcpy。

      【讨论】:

        猜你喜欢
        • 2018-12-19
        • 2021-03-04
        • 2019-01-14
        • 2012-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-30
        • 1970-01-01
        相关资源
        最近更新 更多