|
POST
|
Right click in the white space of your model and select "Create Variable". Right click on whats just been created and click "Model Parameter". Thats it. I would need to know what you are doing to help you tie this to a tool though.
... View more
11-19-2010
10:21 AM
|
0
|
0
|
2736
|
|
POST
|
I just wrote this that solves the problem at least on a two table join. You could do more tables than just two if you are careful. What I did was to make the join field be the definition query for a search cursor on the other table. This means that for every row read by the update cursor a table with only one row will be created from the joined table. This method only works on a one to one style join. I am using parcel data so I have polys with unique IDs. Its possible to adapt this to work on a one to many join but you would just have to be careful with your naming and really think about what youre doing calculation wise so you dont get mixed up. Its actually rather quick to run too. Takes half the time of the JoinFields method on a table of ~117k records. try:
U_cursor=arcpy.UpdateCursor(downloaded_parcels, '"A1RENUM" LIKE \'%-%-%\'')
for U_row in U_cursor:
S_cursor=arcpy.SearchCursor(r"C:\GIS Projects\TaxChange\Parcels\2010 Parcels.shp", '"A1RENUM" = \'%s\'' % U_row.A1RENUM)
for S_row in S_cursor:
if S_row.VASJUST != 0:
U_row.ChgJust = ((float(U_row.VASJUST)-float(S_row.VASJUST))/S_row.VASJUST)*100
if S_row.VASJUST == 0 and U_row.VASJUST != 0:
U_row.ChgJust = 100
if S_row.VASTAXABLE != 0:
U_row.ChgTaxable = ((float(U_row.VASTAXABLE)-float(S_row.VASTAXABLE))/S_row.VASTAXABLE)*100
if S_row.VASTAXABLE == 0 and U_row.VASTAXABLE != 0:
U_row.ChgTAXABLE = 100
U_cursor.updateRow(U_row)
del S_cursor
VASTAXABLEtotal+=U_row.VASTAXABLE
VASJUSTtotal+=U_row.VASJUST
pbar.update(pbar.currval+1)
finally:
del U_cursor This is a simple application that just calculates the percent change in taxable value and justified value of parcels. EDIT: I timed it, takes a third of the time to run as JoinFields + CalculateField. The whole script: http://paste2.org/p/1099256
... View more
11-19-2010
09:31 AM
|
0
|
0
|
913
|
|
POST
|
I think the answer to both depends on the questions being less general. 1. Posts like this http://forums.arcgis.com/threads/17229-Simple-question-about-using-variable-in-arcpy-tools deal directly with a specific tool, but are actually python synatx questions. The difference is that true GP questions have to do with how a tool runs and how the returned output can be used. 2.Map automation is trickier. It is defined in the help as GP so under the current generalization regime we should move it in here. I think it should go into the python forum. There are only 307 posts, less than one new post per day, and most if not all of the posts deal directly with a python module.
... View more
11-18-2010
04:08 AM
|
0
|
0
|
989
|
|
POST
|
Ha! If I had a dollar for every typo and wrong path Ive had I could hire a programmer to do this stuff for me.
... View more
11-18-2010
03:39 AM
|
0
|
0
|
1596
|
|
POST
|
It does take a file object not a path. Thank you for pointing out that typo. Where I have the path should be the variable you assigned the open(object) to. I have had python not close a file which meant I had to restart to make windows give up its hold on the file. I suggest explicitly opening and closing your files instead of hoping python trash cleanup closes it for you.
... View more
11-16-2010
10:41 AM
|
0
|
0
|
9308
|
|
POST
|
Did you vote in the poll as well? Good to have yet another Chris around. We're taking over.
... View more
11-16-2010
03:56 AM
|
0
|
0
|
864
|
|
POST
|
Try raw strings. You use an r flag at the begining of the string. r'string'
... View more
11-16-2010
03:53 AM
|
0
|
0
|
1596
|
|
POST
|
Good to remember is that the string formatting method actually works well inside the tool parameters line. arcpy.CompositeBands_management('%s,%s,%s' % (red,green,nir) ,output) Oh and I agree Niklas, concatenation of strings especially if you have a lot of things you are joining, makes your code hard to read.
... View more
11-15-2010
04:05 AM
|
0
|
0
|
635
|
|
POST
|
Sounds crazy but you have to trust me here. If you are going to use storbinary, the file cant be opened in binary mode. I know what you are going to say but I just figured this out in the last couple weeks myself and it just doesnt work. fileList=[] for i in os.listdir(dir): if i.split('.')[1] == 'pdf' #if it ends in pdf fileList.append(i) #put it in the list ftp = FTP("XXX.XXX.XXX.XXX",username, password) #save a line and just put your U:P here. for i in fileList: file = open(i, "r") #open in normal read mode ftp.cwd("//data2//ftp//pub//download//maps//") ftp.storbinary('STOR %s' % i, os.path.join('V://GIS//Maps//County//11x17shd//',i)) file.close() ftp.quit()
... View more
11-12-2010
04:18 AM
|
0
|
0
|
9308
|
|
POST
|
Oh a pickle is a good idea. I wasnt thinking of serialization=pickles. Mental jam I guess. That would work easily actually 😛 Chris, I use subprocess.Popen() not os.popen. Subprocess is meant for opening a process and os really isnt. This is a task manager I wrote for our server (once we go to 10 I will be able to do it all from python2.6, but notice some needs to be launced by 2.5). The first script to run has a clause in it of sys.exit(0) if something dowesnt quality and returns a 0 value to .wait() when that script closes. You can use this to make your code continue after the subprocess runs. You can use .communicate instead of .wait to read out the stdout from the child if you need to know where in the other script you are. Oh and yes spawn is going away according to http://docs.python.org/release/2.6.6/library/subprocess.html
from time import localtime
from subprocess import Popen
result=Popen([r'C:\Python26\python.exe', r'C:\GIS Projects\CRW\FTPhalf.py']).wait()
if result == 0:
pass
else:
Popen([r'C:\Python25\python.exe', r'C:\GIS Projects\CRW\GPhalf1.1.py']).wait()
Popen([r'C:\Python25\python.exe', r'C:\GIS Projects\TaxChange\taxchange.py']).wait()
if localtime()[2] == 1:
subprocess.Popen([r'C:\Python25\python.exe', r'C:\GIS Projects\GIS Projects\Parcels.gdb\parcelupdate.py']).wait()
Your script could include:
result=subprocess.Popen('([r'C:\Python25\python.exe', your script]').wait() #in the other script, at the end make it do sys.exit(1) if you compelete successfully
if result==1:
pass
else:
print error info here
sys.exit()
... View more
11-10-2010
08:59 AM
|
0
|
0
|
7316
|