justearth
asked on
Python Enumerate Question
Hello,
I wanted know if it looks like my python is right below? I know that the non-python stuff is probably not known to most of you. I have a question mostly about my use of the enumerate function. I am hoping that this line:
gp.interpolatepolytopatch_ 3d (tin, InPolygon + ("_%03d" % numbers[tin_index]) +".shp", OutPolygon + ("_%03d" % numbers[tin_index]) +".shp")
Reads as: gp.interpolatepolytopatch_ 3D(C:/gisw ork/DEMS/d em2tin/tin _001, C:/temp/raster2polygon01/L C2001_001, C:/temp/3Dpoly2patch2001/3 D_area_200 1_001)"
then:
gp.interpolatepolytopatch_ 3D(C:/gisw ork/DEMS/d em2tin/tin _002, C:/temp/raster2polygon01/L C2001_002, C:/temp/3Dpoly2patch2001/3 D_area_200 1_002)"
then ...
gp.interpolatepolytopatch_ 3D(C:/gisw ork/DEMS/d em2tin/tin _100, C:/temp/raster2polygon01/L C2001_100, C:/temp/3Dpoly2patch2001/3 D_area_200 1_100)"
Will it? Can I use the enumerate function twice in the same line like I did and expect it to give me the same value for those two instances? I am not very familiar with the function.
Thanks,
JE
I wanted know if it looks like my python is right below? I know that the non-python stuff is probably not known to most of you. I have a question mostly about my use of the enumerate function. I am hoping that this line:
gp.interpolatepolytopatch_
Reads as: gp.interpolatepolytopatch_
then:
gp.interpolatepolytopatch_
then ...
gp.interpolatepolytopatch_
Will it? Can I use the enumerate function twice in the same line like I did and expect it to give me the same value for those two instances? I am not very familiar with the function.
Thanks,
JE
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(Grrr. It ate the indentation. All the lines must be indented the same way. And do not ask me why the InPolygon and OutPolygon are displayed in purple colous and the n and tpl not ;)
ASKER
Hello,
Thank you all for the help. To confirm: my tin variable is being called from a directory in order (i.e. tin_001, tin_002, etc). Then the other variable are using the tin_index. Assuming the tin_index and the tin directory are numbered the same (i.e. tin_001 wil match with tin_index 001) then they should advance together right?
e.g.
gp.interpolatepolytopatch_ 3D(C:/gisw ork/DEMS/d em2tin/tin _001, C:/temp/raster2polygon01/L C2001_001, C:/temp/3Dpoly2patch2001/3 D_area_200 1_001)"
then:
gp.interpolatepolytopatch_ 3D(C:/gisw ork/DEMS/d em2tin/tin _002, C:/temp/raster2polygon01/L C2001_002, C:/temp/3Dpoly2patch2001/3 D_area_200 1_002)"
then ...
gp.interpolatepolytopatch_ 3D(C:/gisw ork/DEMS/d em2tin/tin _100, C:/temp/raster2polygon01/L C2001_100, C:/temp/3Dpoly2patch2001/3 D_area_200 1_100)"
Thanks again,
Cheers,
JE
Thank you all for the help. To confirm: my tin variable is being called from a directory in order (i.e. tin_001, tin_002, etc). Then the other variable are using the tin_index. Assuming the tin_index and the tin directory are numbered the same (i.e. tin_001 wil match with tin_index 001) then they should advance together right?
e.g.
gp.interpolatepolytopatch_
then:
gp.interpolatepolytopatch_
then ...
gp.interpolatepolytopatch_
Thanks again,
Cheers,
JE
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
pepr:
>you could think about passing only the tin variable
This sounds great pepr. I hope this can be achieved.
You helped me with a similar idea in a script a while ago. Using 'assert' and 'suffix'
see: https://www.experts-exchange.com/questions/23580838/Python-script-no-longer-works-only-minor-change-made.html I do not have a complete understanding of the assert module.
So I tried the code below. When I execute it, I get nothing. No errors, no output. Does it look like a python error, or the other software?
Thanks again for the continued support,
JE
>you could think about passing only the tin variable
This sounds great pepr. I hope this can be achieved.
You helped me with a similar idea in a script a while ago. Using 'assert' and 'suffix'
see: https://www.experts-exchange.com/questions/23580838/Python-script-no-longer-works-only-minor-change-made.html I do not have a complete understanding of the assert module.
So I tried the code below. When I execute it, I get nothing. No errors, no output. Does it look like a python error, or the other software?
Thanks again for the continued support,
JE
# Purpose: Create a multipatch simulating a portion of a TIN surface.
# Create the Geoprocessor object
import arcgisscripting
gp = arcgisscripting.create(9.3)
#Check out the 3D Analyst extension
gp.CheckOutExtension ("3D")
# Set the workspace (to avoid having to type in the full path to the data every time)
gp.workspace = "C:/giswork/DEMS/dem2tin"
#InTin = gp.workspace
InTin = gp.ListRasters()
InPolygon = "C:/temp/raster2polygon01/LC2001_"
OutPolygon = "C:/temp/3Dpoly2patch2001/3D_area_2001_"
tincount = 0
# Select the 3D Analyst Toolbox
gp.toolbox = "3D"
# Say, the tin variable contains 'C:/giswork/DEMS/dem2tin/tin_001'. Just check whether
# the tin contains the suffix that we expect.
for tin in InTin:
assert tin[-4] == '_'
assert tin[-3:].isdigit()
# Get the numbered suffix from the tin variable.
nsuffix = tin[-4:]
print nsuffix
# Prepare the template of the generated paths.
tpl = '%s%s.shp'
print tpl
# name without extension, numbered suffix, explicit extension
# Now, put the information together.
gp.interpolatepolytopatch_3d(tin, tpl % (InPolygon, nsuffix), tpl % (OutPolygon, nsuffix))
# Print error message if an error occurs
print gp.GetMessages()
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.