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

2024-10-06 06:48:14 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我使用的是本地python目录,因此在flask上导入arcpy没有任何问题。所以,我可以使用pymssql函数创建一个新的表,但是当涉及到arcpy函数时,它抛出不存在错误,但是,表存在。我觉得用烧瓶跑arcpy有点不对劲,但任何帮助都将不胜感激。在

(2)我在Django也尝试过同样的方法,但我遇到了同样的问题。在

谢谢

在表单.py在

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

仪表板主()

^{pr2}$

在应用程序副本在

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')

在索引.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


Tags: 函数divlayerautostyle错误createpublish
1条回答
网友
1楼 · 发布于 2024-10-06 06:48:14

我没有调用函数,而是用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())

相关问题 更多 >