Пример #1
0
 def load_geometry(self, session):
     from gtfsdb.model.shape import Pattern
     from gtfsdb.model.trip import Trip
     if hasattr(self, 'geom'):
         s = func.st_collect(Pattern.geom)
         s = func.st_multi(s)
         s = func.st_astext(s).label('geom')
         q = session.query(s)
         q = q.filter(Pattern.trips.any((Trip.route == self)))
         self.geom = q.first().geom
Пример #2
0
    def load_geoms(cls, db):
        """ load derived geometries, currently only written for PostgreSQL """
        from gtfsdb.model.pattern import Pattern
        from gtfsdb.model.trip import Trip

        if db.is_geospatial and db.is_postgresql:
            start_time = time.time()
            session = db.session
            routes = session.query(Route).all()
            for route in routes:
                s = func.st_collect(Pattern.geom)
                s = func.st_multi(s)
                s = func.st_astext(s).label('geom')
                q = session.query(s)
                q = q.filter(Pattern.trips.any((Trip.route == route)))
                route.geom = q.first().geom
                session.merge(route)
            session.commit()
            processing_time = time.time() - start_time
            log.debug('{0}.load_geoms ({1:.0f} seconds)'.format(cls.__name__, processing_time))
Пример #3
0
    def load_geoms(cls, db):
        '''load derived geometries, currently only written for PostgreSQL'''
        from gtfsdb.model.shape import Pattern
        from gtfsdb.model.trip import Trip

        if db.is_geospatial and db.is_postgresql:
            start_time = time.time()
            session = db.session
            routes = session.query(Route).all()
            for route in routes:
                s = func.st_collect(Pattern.geom)
                s = func.st_multi(s)
                s = func.st_astext(s).label('geom')
                q = session.query(s)
                q = q.filter(Pattern.trips.any((Trip.route == route)))
                route.geom = q.first().geom
                session.merge(route)
            session.commit()
            processing_time = time.time() - start_time
            log.debug('{0}.load_geoms ({1:.0f} seconds)'.format(
                cls.__name__, processing_time))
Пример #4
0
def combine_geom(list_of_strokes):
    """Expects a list of strokes, returns a combined geometry of the strokes in the list."""
    geoms = [stroke.geom for stroke in list_of_strokes]
    return session.query(
        func.st_astext(func.st_linemerge(func.st_collect(array(geoms)))))[0][0]