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  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to