#1 Mon 05 July 2010 17:02
- BenoitL
- Participant occasionnel
- Date d'inscription: 17 Jun 2010
- Messages: 32
[ARGCIS 9.3] Probleme avec la fonction select
Bonjour à tous,
J'ai créé un modèle sous modelbuilder qui fonctionne.
J'essaie de le passer sous python et je rencontre une erreur que je n'arrive pas à solutionner. Au moment de réaliser la sélection, j'ai l'erreur suivante :
Error executing function
An expected Field was not found or could not be retrieved properly.
[pt.MIN_POINT_]
A locator with this name does not exist
Failed to execute.
Pourtant l'expression de la condition dans ma fonction select est juste et fonctionne sous modelbuilder.
Je pense qu'au moment de l'export ou dans python, certains caractères ne sont plus lisibles. Du coup, lors du déroulement du script, certains champs ne sont plus trouvables.
Voici mon code en Python.
Code:
# --------------------------------------------------------------------------- # script5.py # Created on: ven. juil. 02 2010 09:45:32 # (generated by ArcGIS/ModelBuilder) # --------------------------------------------------------------------------- # Import system modules import sys, string, os, arcgisscripting import pdb # Create the Geoprocessor object gp = arcgisscripting.create() # Check out any necessary licenses gp.CheckOutExtension("spatial") # Load required toolboxes... gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx") gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx") gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") gp.AddToolbox("C:/Program Files/DataEast/XToolsPro 6.2.1/Toolbox/XTools Pro.tbx") gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx") # Local variables... image = "D:\Benoit_Lescot\Test_programmation\Script_Python\Test_script\k2_20100121_ms_haiti_jacmel_ortho.img" ## A CHANGER ## outFolder = r"D:\Benoit_Lescot\Test_programmation\Script_Python\Test_script\out" ## A CHANGER ## ResultFolder = r"D:\Benoit_Lescot\Test_programmation\Script_Python\Test_script\resultat" ## A CHANGER ## image_name="k2_20100121_ms_haiti_jacmel" classification = outFolder + os.sep + "conv.img" Input_true_raster_or_constant_value = "1" Input_false_raster_or_constant_value = "0" emprise = ResultFolder + os.sep + "emprise.shp" emprise_reelle = outFolder + os.sep +"select.shp" ligne_shp = ResultFolder + os.sep + "ligne.shp" point_shp = outFolder + os.sep + "point.shp" point_shp2 = outFolder + os.sep + "point.shp" point_emprise_dbf = ResultFolder + os.sep + "rast_pt.dbf" point_layer = outFolder + os.sep +"point_layer" coins_layer_lyr = outFolder + os.sep +"coins_layer.lyr" final_shp = ResultFolder + os.sep + "final.shp" try : print "Recherche de l'emprise reelle de %s" %(image) print "Process: Creation du shapefile de l'emprise reelle " # Process: Con... gp.Con_sa(image, Input_true_raster_or_constant_value, classification, Input_false_raster_or_constant_value, "Value>0") # Process: Raster to Polygon... gp.RasterToPolygon_conversion(classification, emprise, "SIMPLIFY", "VALUE") print "Process: Shapefile de l'emprise de l'image reelle cree " print "Process: Isolement de l'image contenant des donnees " # Process: Select... gp.Select_analysis(emprise, emprise_reelle, "GRIDCODE=1") print "Process: Isolement realise " print "Process: Polygon to lines " # Process: Convert Polygons to Polylines... gp.toolbox = "C:/Program Files/DataEast/XToolsPro 6.2.1/Toolbox/XTools Pro.tbx"; gp.XToolsPro_Polygons2Polylines(emprise_reelle, ligne_shp, "", "false", "Create one adjacent polyline, transferring left and right FIDs") print "Process: Polygons to lines termine " print "Process: Polylines to Points" # Process: Convert Features to Points... gp.toolbox = "C:/Program Files/DataEast/XToolsPro 6.2.1/Toolbox/XTools Pro.tbx"; gp.XToolsPro_Features2Points(ligne_shp, point_shp, "ALL", "") print "Process: Polylines to points termine " print "Process: Calcule des coordonnees de chaque point" # Process: Add XY Coordinates... gp.AddXY_management(point_shp) print "Process: addXY termine " print "Process: Conversation feature to layer" # Process: Make Feature Layer... gp.MakeFeatureLayer_management(point_shp2, point_layer, "", "", "ID ID VISIBLE NONE;GRIDCODE GRIDCODE VISIBLE NONE;POINT_X POINT_X VISIBLE NONE;POINT_Y POINT_Y VISIBLE NONE;POINT_Z POINT_Z VISIBLE NONE;POINT_M POINT_M VISIBLE NONE") print "Process: Conversion terminee " print "Process: Recuperation des min et max " # Process: Summary Statistics... gp.Statistics_analysis(point_shp2, point_emprise_dbf, "POINT_X MIN;POINT_X MAX;POINT_Y MIN;POINT_Y MAX;GRIDCODE FIRST", "") print "Process: Fin de la recuperation des coordonnees " print "Process: Jointure tableau et layer " # Process: Add Join... gp.AddJoin_management(point_layer, "GRIDCODE", point_emprise_dbf, "FIRST_GRID", "KEEP_ALL") print "Process: Jointure realisee " pdb.set_trace() print "Process: Enregistrement du layer " # Process: Save To Layer File... gp.SaveToLayerFile_management(point_layer, coins_layer_lyr) print "Process: Layer enregistre" print "Process: Selection des 4 coins" # Process: Select (2)... gp.Select_analysis(coins_layer_lyr, final_shp, "\"point.POINT_X\"= \"pt.MIN_POINT_\" OR \"point.POINT_X\"= \"pt.MAX_POINT_\" OR \"point.POINT_Y\"= \"pt.MIN_POINT1\" OR \"point.POINT_Y\"= \"pt.MAX_POINT1\"") print "...Fin du traitement" except: # If an error occurred while running a tool print the messages print gp.GetMessages()
Merci d'avance,
Benoit
Hors ligne