带有ArcGIS的Flask应用程序,Arcpy无法运行 [英] Flask app with ArcGIS, Arcpy does not run

查看:110
本文介绍了带有ArcGIS的Flask应用程序,Arcpy无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,该脚本从MSSQL数据库获取表,然后将其注册到ArcGIS.它还使用其他几种arcpy方法.我试图将其与Flask结合使用,并开发了一个HTML界面,您可以在其中指定表.但是,当在

解决方案

我使用DOS运行脚本,而不是调用该函数.

  @ app.route('/cad2json',Methods = ['POST'])def cad2sde():dwg_path = request.form.get('dwg_path')reference_scale = request.form.get('reference_scale')空间参考= request.form.get('空间参考')target_layer = request.form.get('target_layer')句子=(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(句子)返回格式(p.read()) 

I have a script that gets a table from MSSQL database and then registers it with ArcGIS. It uses several other arcpy methods as well. I tried to combine it with Flask and developed an HTML interface where you can specify tables. The script runs on console perfectly well, however, when running with Flask on http://127.0.0.1:5000/ , the arcpy functions do not run, then the app throws errors.

I am using my local python directory, so I do not have any problem with importing arcpy on flask. So, I am able to use pymssql functions and create a new table, however when it comes to arcpy function, It throws does not exist error, however, the table exists. I feel like there is something wrong with running arcpy with Flask, but any help would be appreciated.

(2) I tried the same thing in Django but I am having the same problem.

Thanks

forms.py

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

DashboardMain()

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

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

app.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>

ERROR

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

screenshot

解决方案

Instead of calling the function, I ran my script with 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())

这篇关于带有ArcGIS的Flask应用程序,Arcpy无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆