Beispiel #1
0
    def get_site_by_code(self, site_code):
        """Get wof site from odm2 database by site code.

        :param site_code: Site Code Ex. 'USU-LBR-Mendon'
        :return: WOF Site
        """
        self.db_check()
        w_s = None
        try:
            s = self.db_session.query(odm2_models.Sites). \
                filter(odm2_models.Sites.SamplingFeatureCode == site_code).one()

            aff = self.db_session.query(odm2_models.Affiliations). \
                join(odm2_models.ActionBy). \
                join(odm2_models.Actions). \
                join(odm2_models.FeatureActions). \
                join(odm2_models.Sites). \
                filter(odm2_models.Sites.SamplingFeatureCode == s.SamplingFeatureCode).first()
        # filter(odm2_models.ActionBy.IsActionLead == True) : may be too strict,
        # removed on 8/14/17
        except:
            s = None
            aff = None
        if s is not None:
            w_s = model.Site(s, aff)
        return w_s
    def get_site_by_code(self, site_code):
        """Get wof site from odm2 database by site code.

        :param site_code: Site Code Ex. 'USU-LBR-Mendon'
        :return: WOF Site
        """
        w_s = None
        try:
            s = self.db_session.query(odm2_models.Sites). \
                filter(odm2_models.Sites.SamplingFeatureCode == site_code).one()
        except:
            s = None
        if s is not None:
            w_s = model.Site(s)
        return w_s
    def get_all_sites(self):
        """Get all wof sites from odm2 database.

        :return: List of WOF Sites
        """
        s_rArr = self.db_session.query(odm2_models.Sites). \
            join(odm2_models.FeatureActions). \
            join(odm2_models.TimeSeriesResults). \
            filter(odm2_models.FeatureActions.SamplingFeatureID == odm2_models.Sites.SamplingFeatureID,
                   odm2_models.TimeSeriesResults.FeatureActionID == odm2_models.FeatureActions.FeatureActionID).distinct()  # noqa

        s_Arr = []
        for s_r in s_rArr:
            s = model.Site(s_r)
            s_Arr.append(s)
        return s_Arr
    def get_sites_by_box(self, west, south, east, north):
        """Get wof sites from odm2 database by a bounding box.

        :param north: north - ymax - latitude
        :param south: south - ymin - latitude
        :param west: west - xmin - longitude
        :param east: east - xmax - longitude
        :return: List of WOF Sites
        """
        s_rArr = self.db_session.query(odm2_models.Sites). \
            join(odm2_models.FeatureActions). \
            join(odm2_models.TimeSeriesResults). \
            filter(odm2_models.FeatureActions.SamplingFeatureID == odm2_models.Sites.SamplingFeatureID,
                   odm2_models.TimeSeriesResults.FeatureActionID == odm2_models.FeatureActions.FeatureActionID,  # noqa
                   odm2_models.Sites.Latitude >= south,
                   odm2_models.Sites.Latitude <= north,
                   odm2_models.Sites.Longitude >= west,
                   odm2_models.Sites.Longitude <= east).distinct()
        s_Arr = []
        for s_r in s_rArr:
            s = model.Site(s_r)
            s_Arr.append(s)
        return s_Arr