我有一个使用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.But。如果我在django中运行它,它总是返回false。如果我不能解决它,我就不能用django编写更难的脚本。你能帮帮我吗?我在Flask app with ArcGIS, Arcpy does not run中发现了类似的问题,但在这个问题中没有解决方案。
发布于 2019-06-20 14:09:09
我想我可以使用子进程模型在控制台中运行arcpy脚本,然后将控制台消息返回给django函数。但我真的很想知道arcpy是否可以使用django运行。
发布于 2020-05-28 19:47:35
我在Flask中遇到了和你一样的问题。
我检查了arcpy中的源代码,当我从Flask中触发arcpy.Exists()时,发现arcgisscripting.pyd文件中有一个bug。我失去了任何线索。在ESRI在线博客上搜索了一些案例后,我肯定发现这是arcpy中的一个bug。所以我建议你:
from multiprocessing import Queue, Processarcpy.Exists()https://stackoverflow.com/questions/56677977
复制相似问题