Exemplo n.º 1
0
def update_meta(metatable, table):
    """
    After ingest/update, update the metatable registry to reflect table information.

    :param metatable: MetaTable instance to update.
    :param table: Table instance to update from.

    :returns: None
    """

    metatable.update_date_added()

    metatable.obs_from, metatable.obs_to = postgres_session.query(
        func.min(table.c.point_date),
        func.max(table.c.point_date)
    ).first()

    metatable.bbox = postgres_session.query(
        func.ST_SetSRID(
            func.ST_Envelope(func.ST_Union(table.c.geom)),
            4326
        )
    ).first()[0]

    metatable.column_names = {
        c.name: str(c.type) for c in metatable.column_info()
        if c.name not in {'geom', 'point_date', 'hash'}
    }

    postgres_session.add(metatable)
    postgres_session.commit()
Exemplo n.º 2
0
def update_meta(metatable, table):
    """
    After ingest/update, update the metatable registry to reflect table information.

    :param metatable: MetaTable instance to update.
    :param table: Table instance to update from.

    :returns: None
    """

    metatable.update_date_added()

    metatable.obs_from, metatable.obs_to = session.query(
        func.min(table.c.point_date),
        func.max(table.c.point_date)
    ).first()

    metatable.bbox = session.query(
        func.ST_SetSRID(
            func.ST_Envelope(func.ST_Union(table.c.geom)),
            4326
        )
    ).first()[0]

    session.add(metatable)

    try:
        session.commit()
    except:
        session.rollback()
        raise
Exemplo n.º 3
0
 def get_plots_bounding_box_as_json(self):
     positions = []
     if self.role.name == Role._ADMIN_ROLE:
         plots = Plot().queryObject().all()
     else:
         plots = self.plots
     for plot in plots:
         positions.append(plot.geom)
     return self.session.scalar(func.ST_AsGeoJson(func.ST_Envelope(
         func.ST_Union(array(positions))))) if len(positions) > 0\
         else None
Exemplo n.º 4
0
 def get_bounding_box(self):
     positions = []
     for position in self.positions:
         positions.append(position.geom)
         # We return the max number of positions plus one, so it can detect
         # there are more and not just the barrier number
         if len(positions) == (max_positions + 1):
             break
     return self.session.scalar(func.ST_Envelope(
         func.ST_MakeLine(array(positions)))) if len(positions) > 0\
         else None
Exemplo n.º 5
0
 def get_animals_bounding_box(self):
     positions = []
     if self.role.name == Role._ADMIN_ROLE:
         animals = Animal().queryObject().all()
     else:
         animals = self.animals
     for animal in animals:
         if animal.n_positions > 0:
             positions.append(animal.positions[0].geom)
     return self.session.scalar(func.ST_Envelope(
         func.ST_MakeLine(array(positions)))) if len(positions) > 0\
         else None
Exemplo n.º 6
0
    def test_query_to_geopandas_wo_geom(self):
        """
        Test converting a sqlalchemy query of points to geopandas df where the geom column is not == 'geom'
        """
        # Query the centroids of all the raster tiles and use that as the geometry column in geopandas
        qry = self.session.query(
            func.ST_Centroid(func.ST_Envelope(ImageData.raster)))
        df = query_to_geopandas(qry, self.engine, geom_col='ST_Centroid_1')

        # Confirm the type
        assert isinstance(df, gpd.GeoDataFrame)

        # Confirm value count
        assert df['ST_Centroid_1'].count() == 1
Exemplo n.º 7
0
def update_meta(metadata, table):
    """
    After ingest/update, update the metadata registry to reflect
    :param metadata:
    :param table:
    """
    metadata.update_date_added()
    metadata.obs_from, metadata.obs_to =\
        session.query(func.min(table.c.point_date),
                      func.max(table.c.point_date)).first()

    bbox = session.query(
        func.ST_SetSRID(func.ST_Envelope(func.ST_Union(table.c.geom)),
                        4326)).first()[0]
    metadata.bbox = bbox
    session.add(metadata)
    try:
        session.commit()
    except:
        session.rollback()
        raise
 def make_bound_box(box):
     return func.ST_Envelope(func.box2d(box), srid=4326)