librelist archives

« back to archive

External functions in @hybrid_property (or other?)

External functions in @hybrid_property (or other?)

Jón Ragnarsson
2015-06-26 @ 14:28

I'm working with GIS data and need to convert coordinates between systems.
I wanted to make my life a bit easier by adding a converter to a Location 

class Location(db.Model):
    x = Column(Float)
    y = Column(Float)
    def lat(self):
        return isn93towgs84(self.x, self.y)[0]

    def lon(self):
        return isn93towgs84(self.x, self.y)[1]

Of course, I was hoping then to be able to do something like this:
    def inside(self, west, north, east, south):
        if float(west) > self.lon > float(east) and float(north) > > float(south):
            return True
            return False
And finally:

Is this even possible?
SQLAlchemy apparently doesn't like using python functions with queries, it
keeps passing <sqlalchemy.orm.attributes.InstrumentedAttribute> to 
isn93towgs84() instead of the property value.
Or maybe the only solution is to convert the coordinates before the query 
and use the stored x,y values?