# Import native arcgisscripting module # import arcgisscripting # Create the geoprocessor object # gp = arcgisscripting.create(9.3) infc = gp.GetParameterAsText(0) # Identify the geometry field # desc = gp.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = gp.SearchCursor(infc) row = rows.Next() # Enter while loop for each feature/row # while row: # Create the geometry object # feat = row.GetValue(shapefieldname) # Print the current multipoint's ID # print "Feature " + str(row.getvalue(desc.OIDFieldName)) + ":" partnum = 0 # Count the number of points in the current multipart feature # partcount = feat.PartCount # Enter while loop for each part in the feature (if a singlepart feature # this will occur only once) # while partnum < partcount: # Print the part number # print "Part " + str(partnum) + ":" part = feat.GetPart(partnum) pnt = part.Next() pntcount = 0 # Enter while loop for each vertex # while pnt: # Print x,y coordinates of current point # print pnt.x, pnt.y, pnt.z pnt = part.Next() pntcount += 1 # If pnt is null, either the part is finished or there is an # interior ring # if not pnt: pnt = part.Next() if pnt: print "Interior Ring:" partnum += 1 row = rows.Next()
Solved! Go to Solution.
while row: list = []
# Import native arcgisscripting module # import arcgisscripting # Create the geoprocessor object # gp = arcgisscripting.create(9.3) infc = gp.GetParameterAsText(0) # Identify the geometry field # desc = gp.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = gp.SearchCursor(infc) row = rows.Next() # Enter while loop for each feature/row # while row: list = [] # Create the geometry object # feat = row.GetValue(shapefieldname) # Print the current multipoint's ID # print "Feature " + str(row.getvalue(desc.OIDFieldName)) + ":" partnum = 0 # Count the number of points in the current multipart feature # partcount = feat.PartCount # Enter while loop for each part in the feature (if a singlepart feature # this will occur only once) # while partnum < partcount: # Print the part number # print "Part " + str(partnum) + ":" part = feat.GetPart(partnum) pnt = part.Next() pntcount = 0 # Enter while loop for each vertex # while pnt: # Print x,y coordinates of current point ##print pnt.x, pnt.y, pnt.z pnt = part.Next() pntcount += 1 # If pnt is null, either the part is finished or there is an # interior ring # if not pnt: pnt = part.Next() if pnt: print "Interior Ring:" partnum += 1 list.sort() min = list[0] max = list[-1] print min, max row = rows.Next()
while row: list = []
minval, maxval = None, None cur = gp.SearchCursor(infc) for row in iter(cur.next, None): colval = row.getValue(field_name) if minval is None or colval < minval: minval = colval if maxval is None or colval > maxval: maxval = colval del row del cur
Did you create the empty list? It's hard to see the bold in the pasted code before. Here is the subset of it:while row: list = []
minval, maxval = None, None cur = gp.SearchCursor(infc) for row in iter(cur.next, None): colval = row.getValue(field_name) if minval is None or colval < minval: minval = colval if maxval is None or colval > maxval: maxval = colval del row del cur
Yes, i used it. May be can be more specific where i should put the append, because there are 3 while loops and which one to append ( pnt or pnt.z ).
thanks again
while pnt: # Print x,y coordinates of current point ##print pnt.x, pnt.y, pnt.z list.append(pnt.z) pnt = part.Next() pntcount += 1
# Import native arcgisscripting module # import arcgisscripting # Create the geoprocessor object # gp = arcgisscripting.create(9.3) infc = gp.GetParameterAsText(0) # Identify the geometry field # desc = gp.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = gp.SearchCursor(infc) row = rows.Next() # Enter while loop for each feature/row # while row: list = [] # Create the geometry object # feat = row.GetValue(shapefieldname) # Print the current multipoint's ID # print "Feature " + str(row.getvalue(desc.OIDFieldName)) + ":" partnum = 0 # Count the number of points in the current multipart feature # partcount = feat.PartCount # Enter while loop for each part in the feature (if a singlepart feature # this will occur only once) # while partnum < partcount: # Print the part number # print "Part " + str(partnum) + ":" part = feat.GetPart(partnum) pnt = part.Next() pntcount = 0 # Enter while loop for each vertex # while pnt: # Print x,y coordinates of current point ##print pnt.x, pnt.y, pnt.z list.append(pnt.z) pnt = part.Next() pntcount += 1 # If pnt is null, either the part is finished or there is an # interior ring # if not pnt: pnt = part.Next() if pnt: print "Interior Ring:" partnum += 1 list.sort() min = list[0] max = list[-1] print min, max row = rows.Next() del row, rows
Looks like I forgot to include the append portion:while pnt: # Print x,y coordinates of current point ##print pnt.x, pnt.y, pnt.z list.append(pnt.z) pnt = part.Next() pntcount += 1
So, the entire code I was able to get working is:# Import native arcgisscripting module # import arcgisscripting # Create the geoprocessor object # gp = arcgisscripting.create(9.3) infc = gp.GetParameterAsText(0) # Identify the geometry field # desc = gp.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = gp.SearchCursor(infc) row = rows.Next() # Enter while loop for each feature/row # while row: list = [] # Create the geometry object # feat = row.GetValue(shapefieldname) # Print the current multipoint's ID # print "Feature " + str(row.getvalue(desc.OIDFieldName)) + ":" partnum = 0 # Count the number of points in the current multipart feature # partcount = feat.PartCount # Enter while loop for each part in the feature (if a singlepart feature # this will occur only once) # while partnum < partcount: # Print the part number # print "Part " + str(partnum) + ":" part = feat.GetPart(partnum) pnt = part.Next() pntcount = 0 # Enter while loop for each vertex # while pnt: # Print x,y coordinates of current point ##print pnt.x, pnt.y, pnt.z list.append(pnt.z) pnt = part.Next() pntcount += 1 # If pnt is null, either the part is finished or there is an # interior ring # if not pnt: pnt = part.Next() if pnt: print "Interior Ring:" partnum += 1 list.sort() min = list[0] max = list[-1] print min, max row = rows.Next() del row, rows
Thanks alot it works !!!
I just made a little change to get just the min and max, so i put the code in the main loop as follows.
# Identify the geometry field # desc = gp.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = gp.SearchCursor(infc) row = rows.Next() # Enter while loop for each feature/row list = [] while row: # Create the geometry object # feat = row.GetValue(shapefieldname) # Print the current multipoint's ID # partnum = 0 # Count the number of points in the current multipart feature # partcount = feat.PartCount # Enter while loop for each part in the feature (if a singlepart feature # this will occur only once) # while partnum < partcount: # Print the part number # part = feat.GetPart(partnum) pnt = part.Next() pntcount = 0 # Enter while loop for each vertex while pnt: # Print x,y coordinates of current point ##print pnt.x, pnt.y, pnt.z list.append(pnt.z) pnt = part.Next() pntcount += 1 # If pnt is null, either the part is finished or there is an # interior ring # if not pnt: pnt = part.Next() if pnt: print "Interior Ring:" partnum += 1 row = rows.Next() list.sort() min = list[0] max = list[-1] print min, max del row, rows