python - 带有 ArcGIS 的 Flask 应用程序,Arcpy 不运行

标签 python flask arcpy pymssql

我有一个脚本可以从 MSSQL 数据库中获取一个表,然后将其注册到 ArcGIS。它还使用其他几种 arcpy 方法。我尝试将它与 Flask 结合起来,并开发了一个 HTML 界面,您可以在其中指定表格。该脚本在控制台上运行得非常好,但是,当在 http://127.0.0.1:5000/ 上使用 Flask 运行时,arcpy 函数不运行,然后应用程序抛出错误。

我使用的是本地 python 目录,因此在 flask 上导入 arcpy 没有任何问题。因此,我能够使用 pymssql 函数并创建一个新表,但是当涉及到 arcpy 函数时,它抛出不存在错误,但是该表存在。我觉得用 Flask 运行 arcpy 有问题,但我们将不胜感激。

(2) 我在 Django 中尝试了同样的事情,但我遇到了同样的问题。

谢谢

表格.py

class createGISLayer(FlaskForm):
    tCreateLayer = SubmitField('Create GIS Layer')

仪表板主函数()

   try:
        cursor.execute(QueryCreate)
        print ("Table Created.")
        print(self.dbTablePath)
        descTable = arcpy.Describe(self.dbTablePath)

    except arcpy.ExecuteError:
        print(arcpy.GetMessages())

应用.py

if formCreate.tCreateLayer.data and formCreate.validate_on_submit():
    if myLayer is not None:
        try:
            print("Create GIS Layer")
            myLayer.dashboardMain()
            flash('GIS Layer created!', 'success')

        except Exception as e:
            print(e.message)
            flash(e.message, 'danger')

index.html

<!-- Create GIS Layer  -->
<div class="content-section">
<form name='idCreateGISLayer' action="" method="POST">
<table style="height: auto; margin-left: auto; margin-right: auto; width: 600px;">
<tbody>
<tr>
    {{ formCreate.hidden_tag() }}
    <td style="height: 39px; width: 259px">
        <h2 style="text-align: left;"><font size="3"><strong>(2) Create </strong></font></h2>
    </td>
    <td style="text-align: left; height: 39px;">
        <div class="auto-style2">                                                                
            {{ formCreate.tCreateLayer(class="btn btn-outline-info")}}
        </div>
    </td>
 </tr>
 </tbody>
 </table>
 </form>
 </div>

错误

Table Created.
F:\Projects\Dashboard\Publish.sde\Publish.dbo.A_WebT1
"F:\Projects\Dashboard\Publish.sde\Publish.dbo.A_WebT1" does not exist

截图

Table exists

最佳答案

我没有调用函数,而是使用 DOS 运行我的脚本。

@app.route('/cad2json', methods=['POST'])
def cad2sde():
    dwg_path = request.form.get('dwg_path')
    reference_scale = request.form.get('reference_scale')
    spatial_reference = request.form.get('spatial_reference')
    target_layer = request.form.get('target_layer')
    sentence =   (u'C:\\Python27\\ArcGIS10.1\\python.exe C:\\Users\\Administrator           \\Desktop\\flask\\cad.py %s %s %s %s'
             %(dwg_path,reference_scale,spatial_reference,target_layer))
    p = os.popen(sentence)
    return format(p.read())

关于python - 带有 ArcGIS 的 Flask 应用程序,Arcpy 不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51292905/

相关文章:

python - AWS lambda AccessDeniedException 调用另一个 lambda 函数

python - 从数据帧 python 创建自定义字典时出现字符串索引错误

python - Flask-Appbuilder 根据用户更改默认登陆页面

python - 在 Flask 中执行耗时函数时显示 ‘loading’ 消息

python - 在 tkinter 中是否可以有两列标签,其中一个标签位于下方和中间?

python - 用于添加RTSP客户端并使用Tobii Pro Glasses 2的实时视频和凝视数据流的Python库吗?

jquery - 使用ajax和flask来更新表

python从xml中提取数据并保存到excel

python - 不使用局部变量值 - python

python - 使用 reticulate 导入 arcpy