Oh, thanks! That didn't exactly do the trick, because I had data like [(1, 22),(2,11)], but from your code I came up with:
def getBB(self):
Es=[] Ns=[] for i in range(len(self)): Es.append((self[i].E)) Ns.append((self[i].N)) self.boundingBox=geoBox((min(Es),min(Ns)),(max(Es),max(Ns))) return(self.boundingBox) which works fine, and I think will be pretty fast.
Ron
>>> Pujo Aji <[EMAIL PROTECTED]> 5/25/2005 9:47 AM >>> try this code:
L = [(1,11),(2,22)] print max(L) print min(L) I don't know if that what you want. good luck pujo On 5/25/05, Ron Phillips <[EMAIL PROTECTED]> wrote: > > short version: I need a way to get max and min E and N out of > [(E0,N0),(E1,N1)...(En,Nn)] without reordering the list > > long version: > > I would like a list of geographic coordinates (Easting, Northing) to > maintain a "bounding box" > [(minEasting,minNorthing),(maxEasting,maxNorthing)] > attribute. > > I did it like this: > > class geoCoordinateList(UserList): > def __init__(self): > UserList.__init__(self) > self.boundingBox = geoBox(minEN=geoCoordinate(), > maxEN=geoCoordinate()) > > def append(self, geoCoord): > self.extend([geoCoord]) > self.boundingBox.challenge(geoCoord)#bumps the max and min if > necessary > > but I'd have to override almost all the UserList methods, unless there's a > way to call boundingBox.challenge() on any change to the list. > > The other way I thought would be to make a getBB method, like: > > def getBB(self): > new=geoBox() > for gC in self: > new.challenge(gC)#bumps the corners if needed > self.boundingBox=new > return(new) > > but that seems like a lot of churning if nothing has changed. > > I suspect there's some slick, readable way to do this, and when I see it > I'll say "Doh!" > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ |
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor