Efk*_*kan 9 python pymssql flask arcpy
我有一个脚本,该脚本从MSSQL数据库获取表,然后在ArcGIS中注册该表。它还使用其他几种arcpy方法。我试图将其与Flask结合使用,并开发了一个HTML界面,您可以在其中指定表。该脚本可以很好地在控制台上运行,但是,当在http://127.0.0.1:5000/上与Flask一起运行时,arcpy函数无法运行,则该应用程序将引发错误。
我正在使用本地python目录,因此在flask上导入arcpy时没有任何问题。因此,我能够使用pymssql函数并创建一个新表,但是当涉及到arcpy函数时,它不会引发错误,但是该表存在。我感觉用Flask运行arcpy有点问题,但是任何帮助将不胜感激。
(2)我在Django中尝试了相同的操作,但是遇到了相同的问题。
谢谢
class createGISLayer(FlaskForm):
tCreateLayer = SubmitField('Create GIS Layer')
Run Code Online (Sandbox Code Playgroud)
try:
cursor.execute(QueryCreate)
print ("Table Created.")
print(self.dbTablePath)
descTable = arcpy.Describe(self.dbTablePath)
except arcpy.ExecuteError:
print(arcpy.GetMessages())
Run Code Online (Sandbox Code Playgroud)
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')
Run Code Online (Sandbox Code Playgroud)
<!-- 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>
Run Code Online (Sandbox Code Playgroud)
Table Created.
F:\Projects\Dashboard\Publish.sde\Publish.dbo.A_WebT1
"F:\Projects\Dashboard\Publish.sde\Publish.dbo.A_WebT1" does not exist
Run Code Online (Sandbox Code Playgroud)
小智 -1
我没有调用该函数,而是使用 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())
Run Code Online (Sandbox Code Playgroud)