473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to check value fields in different shapes files

Good morning all,

I am new in Python and i need your help.

I have already wrote a program that works for one of the shapes that i need to check, but now i need to do the same for the rest of the shapes that i have in different folders.

How could i do it?

I really appreciate your help!

Flor
Expand|Select|Wrap|Line Numbers
  1. #Import standard library modules
  2. import arcgisscripting, sys, os, string
  3.  
  4. #Create the Geoprocessor object
  5. gp= arcgisscripting.create(9.3)
  6.  
  7. #Set the input workspace
  8. #gp.workspace=sys.argv[1]
  9.  
  10. gp.workspace = 'F:\\fiorenza\MPRGC25M\\77_21_Figueres'
  11.  
  12.  
  13. #Set the output workspace
  14. outWorkspace = 'F:\\fiorenza\MPRGC25M\\77_21_Figueres'
  15. numfull = '77_21'
  16.  
  17. #try:
  18.  
  19. #Get a list of the featureclasses in the input folder
  20. #fcs = gp.listfeatureclasses()
  21. fcExisteix = []
  22. poligon= ['suproc_7721.shp', 'bloc_diposits_7721.shp', 'areabloclliscament_7721.shp', 'esllavissades_7721.shp', 'altres_dip_7721.shp', 'cons_7721.shp', 'dibuixcons_7721.shp', 'limit_esf_7721.shp', 'indicis_7721.shp']
  23.  
  24. punts=['escpunt_772125M.shp', 'blc_ind_mes10_7721.shp', 'blc_ind_menys10_7721.shp', 'b_caiguts_ant_menys10_7721.shp', 'b_caiguts_ant_mes10_7721.shp', 'b_caiguts_rec_menys10_7721.shp', 'b_caiguts_rec_mes10_7721.shp', 'inven_dpr_7721.shp', 'bloclliscament_7721.shp', 'inventari_petits_7721.shp', 'ind_esf_7721.shp', 'antrExt_7721.shp','limit_esf_7721.shp', 'indicis_7721.shp']
  25.  
  26. arc= ['escarpaments_7721.shp', 'direccio_esllavissades_7721.shp','ind_esf_7721.shp', 'altresindicis_7721.shp', 'antrESc_7721.shp', 'eros_soscic_7721.shp']
  27.  
  28. ## Get a list of the fields in the feature classes
  29.  
  30. escarpaments=['EscRoc11', 'EscRoc12', 'EscRoc13', 'EscRoc21', 'EscRoc22', 'EscRoc23', 'EscRoc31', 'EscRoc32', 'EscRoc33', 'EscSol11', 'EscSol12','EscSol13', 'EscSol21', 'EscSol22', 'EscSol23', 'EscSol31', 'EscSol32', 'EscSol33', 'LRtAnEsc', 'LRtRcEsc', 'LTrAnEsc', 'LTrRcEsc', 'MxtAnEsc', 'MxtRcEsc', 'FluxAnEsc', 'FluxRcEsc', 'ExpAnEsc', 'ExpRcEsc', 'CorrAnEsc', 'CorrRcEsc']
  31.  
  32. direccio_esllavissades=['LRtAnDirec', 'LRtRcDirec', 'LTrAnDirec', 'LTrRcDirec', 'MxtAnDirec','MxtRcDirec ', 'FluxAnDirec', 'FluxRcDirec', 'ExpAnDirec', 'ExpRcDirec', 'CorrAnDirec', 'CorrRcDirec']
  33.  
  34. ind_esf = ['EsfSubAnPt']
  35.  
  36. altresindicis = ['ErosSoscavAn', 'ErosSoscavRc', 'ErosEsc', 'ErosSOlc']
  37.  
  38. antrESc = ['AntrExtAbanEsc', 'AntrESc']
  39.  
  40. eros_soscic =['ErosSosCic']
  41.  
  42. suproc =['SupRoc1 ', 'SR1','SupRoc2 ', 'SR2', 'SupRoc3', 'SR3']
  43.  
  44. bloc_diposits=['BlcDispGran','BlcDispMitj','BlcDisppetit','BlcDipRc1','DB1r','BlcDipRc2','DB2r','BlcDipRc3', 'DB3r','BlcDipAn1','DB1a','BlcDipAn2','DB2a','BlcDipAn3','DB3a']
  45.  
  46. areabloclliscament=['AreaBlocllis']
  47.  
  48. esllavissades=['LRtAnLimit','LRtRcLimit','LTrAnLimit','LTrRcLimit','MxtAnLimit','Mxa','MxtRcLimit','Mxr','FluxAnLimit','FluxRcLimit','ExpAnLimit','ExpRcLimit','CorrAnLimit','CorrRcLimit']
  49.  
  50. altres_dip= ['ConDipIn','ConAltresAn','ConAltresRc']
  51.  
  52. cons=['ConDejAn']
  53.  
  54. limit_esf=['Doi','Doip','Kp','Ks']
  55.  
  56. indicis=['ConDipln','ErosInt','Ein','ErosMOd','Emd']
  57.  
  58. escpunt_codifull25M=['EscRocPetit','ERP']
  59.  
  60. blc_ind_mes10= ['BlcInd1Roc1MG','BlcIndRoc2G','BlcInd1Sol1MG','BlcIndSol2G']
  61.  
  62. blc_ind_menys10=['BlcIndRoc3M', 'BlcIndSol3M']
  63.  
  64. b_caiguts_ant_menys10=['BlcAn3Mitja','BlcAn4Petit']
  65.  
  66. b_caiguts_ant_mes10=['BlcAn1MGran','BlcAn2Gran']
  67.  
  68. b_caiguts_rec_menys10=['BlcRC3Miitja','BlcRC4Petit']
  69.  
  70. b_caiguts_rec_mes10=['BlcRC1MGran','BlcRC2Gran']
  71.  
  72. inven_dpr=['DprAnPetit','DprRcPetit','DpsAnPetit','DpsRcPetit']
  73.  
  74. bloclliscament=['Blocllis']
  75.  
  76. inventari_petits=['LRtAnMitj','LRtRcMitj','LRtAnPet','LRtRcPet','LTrAnMitj','LTrRcMitj','LTrAnPet','LTrRcPet','MxtAnMitj','MxtRctMitj','MxtAnPet','MxtRctPet','FluxAnMitj','FluxRcMitj','FluxAnPet','FluxRcPet','ExpAnMitj','ExpRcMitj','CorrAnMitj','CorrRcMitj','CorrAnPet','CorrRcPet']
  77.  
  78. ind_esf=['EsfCavAn','EsfCavRc']
  79.  
  80. antrExt=['AntrExtAban']
  81.  
  82. limit_esf=['Dsa','Dsp']
  83.  
  84. indicis=['BlcIndDisc','BlcIndBalm','BlcIndSost','BlcIndDesp','IndDef','IndEsqTerr','IndArbres','IndSurgen','IndSurgenTerm','IndAiguam','IndEsqEdif']
  85.  
  86. fclistpoly = gp.listfeatureclasses("*", "polygon")
  87. fclistpunts = gp.listfeatureclasses("*", "point")
  88. fclistarc = gp.listfeatureclasses("*", "arc")
  89. fcNoExisteix =[]
  90. fcExisteix =[]
  91. outFeatureClass = []
  92.  
  93. nomarxiu = 'F:\\fiorenza\MPRGC25M\\workfile_' + numfull + '.txt'
  94. print nomarxiu
  95. f = open(nomarxiu,'w')
  96.  
  97. f.write('arcs_comprobats:\n\n')
  98. for fc in arc:
  99.     fc1 = 0
  100.     arE=0
  101.     for fc1 in fclistarc :
  102.         outFeatureClass = outWorkspace + "\\" + fc
  103.         #fc1.lower
  104.         if str(fc) == str(fc1):
  105.             arE = 1
  106.             fcExisteix.append (fc1)
  107.     if arE == 1:
  108.         f.write(outFeatureClass + '......... existeix\n')
  109.     else:
  110.         fcNoExisteix.append(fc1)
  111.         f.write(outFeatureClass + '......... no existeix\n')
  112.  
  113. f.write('\npunts_comprobats:\n\n')
  114. for fc in punts:
  115.     puE=0
  116.     for fc1 in fclistpunts :
  117.         outFeatureClass = outWorkspace + "\\" + fc
  118.         #fc1.lower
  119.         if str(fc) == str(fc1):
  120.             puE = 1
  121.             fcExisteix.append (fc1)
  122.     if puE == 1:
  123.         f.write(outFeatureClass + '......... existeix\n')
  124.     else:
  125.         fcNoExisteix.append(fc1)
  126.         f.write(outFeatureClass + '......... no existeix\n')
  127.  
  128. f.write('\npoligons_comprobats:\n\n')
  129. for fc in poligon:
  130.     poE=0
  131.     for fc1 in fclistpoly :
  132.         outFeatureClass = outWorkspace + "\\" + fc
  133.         #fc1.lower
  134.         if str(fc) == str(fc1):
  135.             poE = 1
  136.             fcExisteix.append (fc1)
  137.     if poE == 1:
  138.         f.write(outFeatureClass + '......... existeix\n')
  139.     else:
  140.         fcNoExisteix.append(fc1)
  141.         f.write(outFeatureClass + '......... no existeix\n')
  142.  
  143. #Ara comencem a comprobar el camp codi_BD
  144. fcCampNE=[]
  145. f.write('\nComprobant el shape escarpaments.shp :\n\n')                
  146. for fc in fcExisteix:
  147.     registres = []
  148.     llista =[]
  149.     fields = gp.ListFields(fc)
  150.     #fields = gp.ListFields('escarpaments_7721.shp')
  151.  
  152.     for field in fields:
  153.  
  154.                 if str(field.Name) == 'Codi_BD':        
  155.                     cur = gp.SearchCursor (fc)
  156.                     row = cur.Next()
  157.                     nn = 0
  158.                     while row <> None:
  159.                         llista.append(row.Codi_BD)
  160.                         row = cur.Next()
  161.  
  162.                     for item in llista:
  163.                         #Aqui crearem una nova llista eliminant duplicats
  164.  
  165.                         if item <>' ':                    
  166.                             if item not in registres:
  167.                                 registres.append(item)
  168.                     for valor_camp in registres:
  169.                         treure = '_' + numfull + '.shp'
  170.                         llistaValor = fc.lstrip(treure)
  171.                         print llistaValor
  172.                         for valorFila in llistaValor:
  173.                             correcte = 0
  174.                             if str(valor_camp) == str(valorFila):
  175.                                 correcte = 1
  176.                         if correcte == 0:                        
  177.                            # f.write(outFeatureClass+'-'+valor_camp + '......... existeix\n')
  178.                         #else:
  179.                             fcCampNE.append(valor_camp)
  180.                             nn = nn + 1
  181.  
  182.  
  183. for camp in fcCampNE:
  184.     print camp
  185.     f.write('\n'+ camp)
  186.  
  187. #f.write("\nHi ha " + str(nn) + " registres erronis.\n")
  188. f.write('\nComprobats tots els fitxers')
  189. f.close()
May 12 '10 #1
1 1358
Glenton
391 Expert 256MB
It's hard to read your code (please use code tags), and I don't really understand your question. But are you trying to ask how you can apply your script to different folders?

The os module docs are a good place to start. Look for the os.walk and path commands.

Good luck, and let us know how it goes.
May 13 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Krista | last post by:
Hi, I wrote a php project 2 years ago. I am totally lost right now. what is differnt between $userName, $_GET and $_REQUEST? In my past project, I remember i can use $userName as a variable, but i...
4
by: Heather | last post by:
I am creating a database with a backend and frontend. The backend consists of a Products table and many other tables. The products table in an .mdb file by itself is over 2 meg. I thought about...
5
by: Dale Ring | last post by:
Access 2000 I need to check a particular folder for files of a particular type (such as *.txt) Prior to the next step. If Files of said type are present, then the code will continue, else it...
1
by: Nita Raju | last post by:
Hi, In my application i have to use different XML files for different users. I use the cache dependency for the Xml file with the dataset. When multiple users are accessing the site will there...
1
by: amraam35 | last post by:
Here is the problem. I have made a log in script that prompts you to log in with a username and password as the "splash screen" It is an unbounded forum that checks that the username and password...
1
by: Sergio | last post by:
Hello everybody. Somebody has given me nine files with some data for the years 1997, 1998, ... , 2005. They are 9 different mdb files. Each one has many tables, forms, and other things. But all...
1
by: DC | last post by:
Is ther an easy way of using the HTTP_REFERER server variable to choose between 2 different includes files? Eg: <% If HTTP_REFERER="Url 1" then <!--#include...
3
by: huda81 | last post by:
Dear all, I need help in creating this system really got tired by searching. I am new baby born programmer (^_^). The requirments are: Develop a Java applet that draws different shapes of...
3
by: jim | last post by:
Each night, a scheduled task copies certain information from an MS Access db to a MySQL db that serves as a data warehouse. I would like to begin replicating multi-value fields from Access to...
7
by: ismailc | last post by:
Good day, I urgently need help. I need to check all fields have values on click of button. The button already has a command but i need to check / run through the page for required fields. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.