<\/HEAD>
Bonjour à tous,<\/P>
<\/P>
J'essaie de lire des informations à partir d'un fichier shape (.shp) et je rencontre un petit problème lorsque la fonction ListFields() tente de lire le fichier. Ici, dans ce code, je passe manuellement le fichier pour vérifier.<\/P>
<\/P>
for <\/STRONG><\/SPAN>field <\/SPAN>in <\/STRONG><\/SPAN>arcpy.ListFields(<\/SPAN>"L:<\/STRONG><\/SPAN>\\<\/STRONG><\/SPAN>historical_data<\/STRONG><\/SPAN>\\<\/STRONG><\/SPAN>Elko County<\/STRONG><\/SPAN>\\<\/STRONG><\/SPAN>Elko_Sewer<\/STRONG><\/SPAN>\\<\/STRONG><\/SPAN>Elko_Sewer_Network_DBO_ssLateralLine.shp"<\/STRONG><\/SPAN>😞<\/span><\/SPAN><\/P><\/P>La ligne ci-dessus génère une exception indiquant que le fichier n'existe pas.<\/P>Le f = arcpy.ListFeatureClasses() retourne les valeurs correctes.<\/SPAN><\/PRE>Maintenant, la partie intéressante est que ce code fonctionne bien dans la version desktop du code python. Et quand j'essaie d'exécuter le même code depuis la version web, il renvoie l'erreur ci-dessus.<\/SPAN>Voici le code complet de la fonction ci-dessous :<\/SPAN><\/SPAN><\/P><\/P>def <\/STRONG><\/SPAN>connectSource(<\/SPAN>self<\/SPAN>, filepath):
<\/SPAN>"""
Se connecter à un fichier et créer une structure de données dictionnaire qui contiendra
les classes d'entités : ShapeTypes et les noms de champs : Type
"""
<\/EM><\/SPAN>self<\/SPAN>.feature.clear()
listfield = <\/SPAN>list<\/SPAN>()
<\/SPAN>try<\/STRONG><\/SPAN>:
<\/SPAN># définir l'espace de travail sur le fichier connecté
<\/EM><\/SPAN>arcpy.env.workspace = filepath
<\/SPAN># Obtenir la liste de toutes les entités
<\/EM><\/SPAN>f = arcpy.ListFeatureClasses()
<\/SPAN>print<\/STRONG><\/SPAN>(f)
<\/SPAN>for <\/STRONG><\/SPAN>f1 <\/SPAN>in <\/STRONG><\/SPAN>f:
listfield[:] = []
i = <\/SPAN>0
& nbsp ; < / SPAN > < SPANstyle = "color : gray ; font - size : 9 . 0 pt ; " > < EM > # Itérer à travers la liste des champs < BR / > & nbsp ; & nbsp ; & nbsp ; & nbsp ; & nbsp ; & nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nbsp ;& nb sp;< / EM > < / SPAN > < SPANstyle = "color : navy ; font - size : 9 . 0 pt ; " > < STR ONG > print < / STR ONG > < / SPAN > ( f1 ) < BR / > & nb sp;< / SPAN > < SPANstyle = "color : navy ; font - size : 9 . 0 pt ; " > < STR ONG > for < / STR ONG > < / SPAN > < SPANstyle = "font - size : 9 . 0 pt ; color : black ; " > field < / SPAN > < SPANstyle = "color : navy ; font - size : 9 . 0 pt ; " > < STR ONG > in < / STR ONG > < / SPAN > < SPANstyle = "font - size : 9 . 0 pt ; color : black ; " > arcpy.ListFields ( < / SPAN > < SPANstyle = "color : green ; font - size : 9 . 0 pt ; " > < STR ONG > " L :< / STR ONG > < / SPAN > < SPANstyle = "color : navy ; font - size : 9 . 0 pt ; " > < STR ONG > \ \ < / STR ONG > < / SPAN > < SPANstyle = "color : green ; font - size : 9 . 0 pt ; " > historical_data < / SPAN > ... <\/SPAN>elif <\/STRONG><\/SPAN>type.ShapeType <\/SPAN>in <\/STRONG><\/SPAN>[<\/SPAN>'Polyline'<\/STRONG><\/SPAN>, <\/SPAN>'Line'<\/STRONG><\/SPAN>]:
<\/SPAN>self<\/SPAN>.feature[f1, type.ShapeType] = hup
<\/SPAN>sauf <\/STRONG><\/SPAN>Exception comme <\/STRONG><\/SPAN>e:
<\/SPAN>print <\/STRONG><\/SPAN>(<\/SPAN>"Fichier incorrect"<\/STRONG><\/SPAN>+e.message)
tkMessageBox.showerror(<\/SPAN>"Source File Connection"<\/STRONG><\/SPAN>, <\/SPAN>"Échec de la connexion au fichier.{0} "<\/STRONG><\/SPAN>.format(e))
<\/SPAN>return <\/STRONG><\/SPAN>0<\/SPAN> <\/SPAN><\/SPAN><\/P><\/P>Le même code au format web lance une exception indiquant que le fichier n'existe pas. Alors que dans la version bureau, il s'exécute parfaitement. <\/SPAN><\/P><\/P>arcpy.ListFields(<\/SPAN>"L:<\/STRONG><\/SPAN>\\<\/STRONG><\/SPAN>historical_data<\/STRONG><\/SPAN>\\<\/STRONG><\/SPAN>Elko County<\/STRONG><\/SPAN>\\<\/STRONG><\/SPAN>Elko_Sewer<\/STRONG><\/SPAN>\\<\/STRONG><\/SPAN>Elko_Sewer_Network_DBO_ssLateralLine.shp")<\/STRONG><\/SPAN> <\/STRONG><\/SPAN><\/SPAN><\/P><\/P>Cette fonction ListFields() n'arrive pas à retourner / lire la valeur.<\/SPAN><\/P><\/P>Merci de me guider sur ce qui ne va pas.<\/SPAN><\/P><\/P>ÉDITION 1 :<\/SPAN><\/P><\/P>J'essaie de développer une application python flask où je veux que ce bloc de code soit exécuté lors d'un clic sur un bouton d'un fichier HTML.<\/P>L'application tourne donc sur http:\/\127.0.0.1\5000\<\/A> et une fois que je clique sur ce bouton, la fonction suivante est exécutée.<\/P>La fonction suivante est exécutée au clic de ce bouton :<\/P>
@app.route< \/span > ( < \/ span > ' \/ open_file ' < \/ strong > , < \/ span > methods < \/ span > = [ < \/ span > ' POST ' < \/ strong > ] ) < br \/ > < \/ span > def < \/ strong > open_file ( ) : < br \/ > & nbsp ; & nbsp ; & nbsp ; proce ( os.path.abspath ( < \/ span > ' uploads \/ Elko_Sewer ' < \/ strong > & nbsp ; & nbsp ; & nbsp ; < \/ span > print < \/ strong > ( < \/ span > ' END OPEN ' < \/ strong > ) < br \/ > & nbsp ; & nbsp ; & nbsp ; < \/ span > return < \/ strong > render_template ( < \/ span > ' view.html ' < \/ strong > ) < \/ span >< \/ p >
& nbsp;< \/ p >
Dans le code ci-dessus, la fonction proce() contient tout ce code pour lire à partir du fichier shp.< \/ p >
& nbsp;< \/ p >
La partie intéressante est que lorsque j'appelle proce() sous la fonction principale de l'application flask, cela fonctionne parfaitement vraiment bien et avant que le débogueur ne s'active, il exécute le code et affiche la sortie dans la console du débogueur. J'utilise PyCharm pour développer et déboguer.< \/ p >
if
__name__ ==
'__main__'
:
& nbsp;& nbsp;& nbsp;
proce(os.path.abspath(
'uploads/Elko_Sewer')
& nbsp;& nbsp;& nbsp;
app.run(
& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;
debug
=
True
)
Cordialement
Priyam