banniere

Le portail francophone de la géomatique


Toujours pas inscrit ? Mot de passe oublié ?
Nom d'utilisateur    Mot de passe              Toujours pas inscrit ?   Mot de passe oublié ?

Annonce

Rencontres QGIS 2025

L'appel à participation est ouvert jusqu'au 19 janvier 2025!

#1 Mon 21 April 2008 11:41

Loo
Juste Inscrit !
Date d'inscription: 17 Apr 2008
Messages: 8

[ArcGIS 9.1] Script réarrangement de champs

Salut Tutti!

Voici un code en python qui fonctionne PRESQUE !

J'arrive pas à trouver le bug, alors toutes suggestions bienvenues....

Mercimerci

Code:

import os,string,sys


import win32com.client
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")


FC_In = sys.argv[1]
NewOrder = "ID_GA25_CH;CODE_ZV;DESCRIPT;SYMBOL;AZIMUT;DIP;ORIENT;SPEC_VAL;SPEC_DESCR;REM"
FC_Out_WS = sys.argv[2]
FC_Out_Name = sys.argv[3]

strFields = gp.listfields(FC_In) 
strNewOrder = NewOrder 
Layers = [""]

# Get Field Collection into List
Fields = gp.listfields(FC_In) 

NewOrder = string.split(strNewOrder,";")
gp.AddMessage("C'est bien patri")

x=0 #NewOrder enumerator 
y=0 #Layers enumerator (first)

# Cycles through the input feature class creating field collections
while x<len(NewOrder):
    Fields.Reset()
    Field = Fields.Next()
    while Field:
        FieldName = str(Field.name)
        if x<len(NewOrder) and NewOrder[x].lower() == FieldName.lower(): 
            Layers[y] = Layers[y] + FieldName + " " + NewOrder[x] + " VISIBLE"
            x=x+1
        else:
            Layers[y] = Layers[y] + FieldName + " " + FieldName + " HIDDEN" 

        Field = Fields.Next()
                
        if Field:
            Layers[y] = Layers[y] + "; "
            FieldName = str(Field.name)
        else:
            Layers.append("")
            y=y+1
            Layers[y]=""

        
# Use Field collections to create Layers with proper order until all fields have been used
z=0 #Layers enumerator (second)
LayerList = ""
for Layer in Layers:
    if Layer <> "":
        if LayerList <> "":
            LayerList=LayerList + ";"
        LayerList=LayerList + "Layer" + str(z)
       
        gp.MakeFeatureLayer(FC_In, "Layer" + str(z),"#","#",Layer)
        gp.addmessage("Mouais")
        z=z+1
        

#Collect Info about Input Feature Class
dsc = gp.describe(FC_In)
fc_in_stype = dsc.shapetype
fc_in_sr = dsc.spatialreference

# Create new empty Feature class with desired fields 
try:
    gp.CreateFeatureClass(FC_Out_WS,FC_Out_Name,fc_in_stype,LayerList,"#","#",fc_in_sr)
    gp.addmessage("Presque")
except:
    gp.addmessage("Oups")

# Append Records to new feature class

gp.append_management(FC_In, FC_Out_WS + "\\" + FC_Out_Name)
gp.addmessage("TipTop")

del gp

Et le message d'erreur...

Code:

Executing: TestOrder (...)
Start Time: (...)
Running script TestOrder...
C'est bien patri
Mouais
Mouais
Mouais
Mouais
Oups
Error in script TestOrder.
Error in executing: cmd.exe /C (...)
Failed to execute (TestOrder).
End Time: (...) (Elapsed Time: 9.00 seconds)

Hors ligne

 

#2 Mon 21 April 2008 16:18

Tnarbiv
Participant assidu
Lieu: Véretz
Date d'inscription: 5 Sep 2005
Messages: 392

Re: [ArcGIS 9.1] Script réarrangement de champs

tu es en quelle version d'arcgis ?


Ayez le réflexe "Développement Durable": N'imprimez ce message que si nécessaire.

Hors ligne

 

#3 Mon 21 April 2008 17:01

Loo
Juste Inscrit !
Date d'inscription: 17 Apr 2008
Messages: 8

Re: [ArcGIS 9.1] Script réarrangement de champs

9.1

J'ai avancé un peu...
Maintenant, j'obtiens le nouveau shp, mais avec la table attributaire vide, et je ne sais vraiment pas quelle commande utiliser pour finaliser le tout.

Code:

import os,string,sys


import win32com.client
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")


FC_In = sys.argv[1]
NewOrder = "ID_GA25_CH;CODE_ZV;DESCRIPT;SYMBOL;AZIMUT;DIP;ORIENT;SPEC_VAL;SPEC_DESCR;REM"
FC_Out_WS = sys.argv[2]
FC_Out_Name = sys.argv[3]

strFields = gp.listfields(FC_In) 
strNewOrder = NewOrder 
Layers = [""]

# Get Field Collection into List
Fields = gp.listfields(FC_In) 

NewOrder = string.split(strNewOrder,";")
gp.AddMessage("C'est bien patri")

x=0 #NewOrder enumerator 
y=0 #Layers enumerator (first)

# Cycles through the input feature class creating field collections
while x<len(NewOrder):
    Fields.Reset()
    Field = Fields.Next()
    while Field:
        FieldName = str(Field.name)
        if x<len(NewOrder) and NewOrder[x].lower() == FieldName.lower(): 
            Layers[y] = Layers[y] + FieldName + " " + NewOrder[x] + " VISIBLE"
            x=x+1
        else:
            Layers[y] = Layers[y] + FieldName + " " + FieldName + " HIDDEN" 

        Field = Fields.Next()
                
        if Field:
            Layers[y] = Layers[y] + "; "
            FieldName = str(Field.name)
        else:
            Layers.append("")
            y=y+1
            Layers[y]=""

        
# Use Field collections to create Layers with proper order until all fields have been used
z=0 #Layers enumerator (second)
LayerList = ""
for Layer in Layers:
    if Layer <> "":
        if LayerList <> "":
            LayerList=LayerList + ";"
        LayerList=LayerList + "Layer" + str(z)
        gp.MakeFeatureLayer(FC_In, "Layer" + str(z),"#","#",Layer)
        gp.addmessage(gp.getmessages()+ "\n")
        gp.addmessage("Mouais")
        z=z+1
        

#Collect Info about Input Feature Class
dsc = gp.describe(FC_In)
fc_in_stype = dsc.shapetype
fc_in_sr = dsc.spatialreference

# Create new empty Feature class with desired fields 
try:
    gp.CreateFeatureClass(FC_Out_WS,FC_Out_Name,fc_in_stype,LayerList,"#","#",fc_in_sr)
    gp.addmessage(gp.getmessages()+ "\n")    
    gp.addmessage("Presque")
except:
    gp.addmessage(gp.getmessages()+ "\n")    
    gp.addmessage("Oups")

# ??????????

del gp

Hors ligne

 

#4 Tue 22 April 2008 15:20

Tnarbiv
Participant assidu
Lieu: Véretz
Date d'inscription: 5 Sep 2005
Messages: 392

Re: [ArcGIS 9.1] Script réarrangement de champs

peux tu m'envoyer ta donnée d'origine pour que je fasse des tests


Ayez le réflexe "Développement Durable": N'imprimez ce message que si nécessaire.

Hors ligne

 

Pied de page des forums

Powered by FluxBB