def _getDataStep2(self, surveys):    
     """ STEP 2: get strata information for every point """
     myconnection = utils.dbconnection()
     if myconnection.connect2db() == True:
         # create a cursor
         curs = myconnection.conn.cursor()
         for (obsid, survey) in surveys.iteritems(): 
             sql =r"""SELECT stratid, depthtop, depthbot, geology, geoshort, capacity, comment, development FROM """
             sql += self.stratitable #MacOSX fix1
             sql += r""" WHERE obsid = '"""    
             sql += str(obsid)   # THIS IS WHERE THE KEY IS GIVEN TO LOAD STRATIGRAPHY FOR CHOOSEN obsid
             sql += """' ORDER BY stratid"""
             rs = curs.execute(sql) #Send SQL-syntax to cursor
             recs = rs.fetchall()  # All data are stored in recs            
             # parse attributes
             for record in recs:
                 if utils.isinteger(record[0]) and utils.isfloat(record[1]) and utils.isfloat(record[2]):
                     stratigaphy_id = record[0]  # Stratigraphy layer no
                     depthtotop = record[1]  # depth to top of stratrigraphy layer
                     depthtobot = record[2]  # depth to bottom of stratrigraphy layer
                 else:
                     raise DataSanityError(str(obsid), "Something bad with stratid, depthtop or depthbot!")
                     stratigaphy_id = 1  # when something went wrong, put it into first layer
                     depthtotop = 0
                     depthtobot = 999#default value when something went wrong
                 if record[3]: # Must check since it is not possible to print null values as text in qt widget
                     geology = record[3]  # Geology full text 
                 else:
                     geology = " " 
                 geo_short_txt = record[4]  # geo_short might contain national special characters
                 if geo_short_txt:   # Must not try to encode an empty field
                     geo_short = unicodedata.normalize('NFKD', geo_short_txt).encode('ascii','ignore')  # geo_short normalized for symbols and color
                 else:  # If the field is empty, then store an empty string
                     geo_short = ''
                 hydro = record[5] # waterloss (hydrogeo parameter) for color
                 if record[6]:  # Must check since it is not possible to print null values as text in qt widget
                     comment = record[6] # 
                 else: 
                     comment = " " 
                 if record[7]:  # Must check since it is not possible to print null values as text in qt widget
                     development = record[7] # 
                 else: 
                     development = " " 
                 st = StrataInfo(stratigaphy_id, depthtotop, depthtobot, geology, geo_short, hydro, comment, development)
                 # add strata information (in right order) 
                 insertAt = 0
                 for a in survey.strata:
                     if a.stratid > stratigaphy_id:
                         break
                     insertAt += 1
                 survey.strata.insert(insertAt, st)
         """ Close SQLite-connections """
         rs.close() # First close the table 
         myconnection.closedb()# then close the database
         DataLoadingStatus = True
         return DataLoadingStatus, surveys
     else:
         return False, surveys
    def _getDataStep2(self, surveys):
        """ STEP 2: get strata information for every point """
        dbconnection = db_utils.DbConnectionManager()
        for (obsid, survey) in surveys.items():
            sql =r"""SELECT stratid, depthtop, depthbot, geology, lower(geoshort), capacity, comment, development FROM """
            sql += self.stratitable #MacOSX fix1
            sql += r""" WHERE obsid = '"""
            sql += str(obsid)   # THIS IS WHERE THE KEY IS GIVEN TO LOAD STRATIGRAPHY FOR CHOOSEN obsid
            sql += """' ORDER BY stratid"""
            recs = dbconnection.execute_and_fetchall(sql)
            if not recs:
                if survey.length is not None:
                    recs.append([1, 0.0, survey.length, '', '', '', '', ''])
            # parse attributes
            prev_depthbot = 0
            for record in recs:
                if utils.isinteger(record[0]) and utils.isfloat(record[1]) and utils.isfloat(record[2]):
                    stratigaphy_id = record[0]  # Stratigraphy layer no
                    depthtotop = record[1]  # depth to top of stratrigraphy layer
                    depthtobot = record[2]  # depth to bottom of stratrigraphy layer
                else:
                    raise DataSanityError(str(obsid), ru(QCoreApplication.translate('SurveyStore', "Something bad with stratid, depthtop or depthbot!")))
                    stratigaphy_id = 1  # when something went wrong, put it into first layer
                    depthtotop = 0
                    depthtobot = 999#default value when something went wrong
                if record[3]: # Must check since it is not possible to print null values as text in qt widget
                    geology = record[3]  # Geology full text
                else:
                    geology = " "
                geo_short_txt = record[4]  # geo_short might contain national special characters
                if geo_short_txt:   # Must not try to encode an empty field
                    geo_short = unicodedata.normalize('NFKD', geo_short_txt).encode('ascii','ignore').decode('ascii')  # geo_short normalized for symbols and color
                else:  # If the field is empty, then store an empty string
                    geo_short = ''
                hydro = record[5] # waterloss (hydrogeo parameter) for color
                if record[6]:  # Must check since it is not possible to print null values as text in qt widget
                    comment = record[6] #
                else:
                    comment = " "
                if record[7]:  # Must check since it is not possible to print null values as text in qt widget
                    development = record[7] #
                else:
                    development = " "

                #Add layer if there is a gap
                if depthtotop != prev_depthbot:
                    stratid = len(survey.strata) + 1
                    st = StrataInfo(stratid, prev_depthbot, depthtotop)
                    survey.strata.append(st)

                stratid = len(survey.strata) + 1
                st = StrataInfo(stratid, depthtotop, depthtobot, geology, geo_short, hydro, comment, development)
                survey.strata.append(st)
                prev_depthbot = depthtobot

            DataLoadingStatus = True
        dbconnection.closedb()
        return DataLoadingStatus, surveys
 def _getDataStep1(self, featureIds, vlayer):
     """ STEP 1: get data from selected layer"""  # _CHANGE_ Completely revised to TSPLot method
     provider = vlayer.dataProvider()  #_CHANGE_  THIS IS TSPLOT-method, we do not use the db loadeds by ARPAT _init_ surveystore
     obsid_ColNo = provider.fieldNameIndex('obsid') # _CHANGE_  THIS IS TSPLOT-method To find the column named 'obsid'
     if obsid_ColNo == -1:
         obsid_ColNo = provider.fieldNameIndex('OBSID') # backwards compatibility
     h_gs_ColNo = provider.fieldNameIndex('h_gs') # _CHANGE_  THIS IS TSPLOT-method To find the column named 'h_gs'
     h_toc_ColNo = provider.fieldNameIndex('h_toc') # _CHANGE_  THIS IS TSPLOT-method To find the column named 'h_toc'
     if h_gs_ColNo == -1 and h_toc_ColNo == -1:
         h_gs_ColNo = provider.fieldNameIndex('SURF_LVL') # backwards compatibility
     surveys = {}
     strata = {}
     if(vlayer):
         nF = vlayer.selectedFeatureCount()
         if (nF > 0):
             # Load all selected observation points
             ob = vlayer.selectedFeatures()
             obsid_list=[None]*nF # List for obsid
             toplvl_list=[None]*nF # List for top_lvl
             coord_list=[None]*nF # List for coordinates
             i=0
             for k in ob:    # Loop through all selected objects, a plot is added for each one of the observation points (i.e. selected objects)
                 attributes = ob[i]
                 obsid_list[i] = unicode(str(attributes[obsid_ColNo])) # Copy value in column obsid in the attribute list 
                 if attributes[h_gs_ColNo] and utils.isfloat(attributes[h_gs_ColNo]) and  attributes[h_gs_ColNo]>-999:  # Only get h_gs if it exists 
                     toplvl_list[i] = attributes[h_gs_ColNo] # Copy value in column h_gs in the attribute list
                 elif attributes[h_toc_ColNo] and utils.isfloat(attributes[h_toc_ColNo]) and attributes[h_toc_ColNo] >-999:    # else get h_toc if that exists
                     toplvl_list[i] = attributes[h_toc_ColNo] # Copy value in column h_gs in the attribute list
                 else:       # otherwise, if neither h_gs nor h_toc exists - plot as if h_gs is zero
                     toplvl_list[i] = 0
                 coord_list[i]= k.geometry().asPoint()
                 # add to array
                 surveys[obsid_list[i]] = SurveyInfo(obsid_list[i], toplvl_list[i], coord_list[i])
                 i = i+1
     else:
         utils.pop_up_info("getDataStep1 failed ")  # _CHANGE_ for debugging
     return surveys
Exemple #4
0
    def _getDataStep2(self, surveys):
        """ STEP 2: get strata information for every point """
        dbconnection = db_utils.DbConnectionManager()
        for (obsid, survey) in surveys.iteritems():
            sql = r"""SELECT stratid, depthtop, depthbot, geology, lower(geoshort), capacity, comment, development FROM """
            sql += self.stratitable  #MacOSX fix1
            sql += r""" WHERE obsid = '"""
            sql += str(
                obsid
            )  # THIS IS WHERE THE KEY IS GIVEN TO LOAD STRATIGRAPHY FOR CHOOSEN obsid
            sql += """' ORDER BY stratid"""
            recs = dbconnection.execute_and_fetchall(sql)
            # parse attributes
            prev_depthbot = 0
            for record in recs:
                if utils.isinteger(record[0]) and utils.isfloat(
                        record[1]) and utils.isfloat(record[2]):
                    stratigaphy_id = record[0]  # Stratigraphy layer no
                    depthtotop = record[
                        1]  # depth to top of stratrigraphy layer
                    depthtobot = record[
                        2]  # depth to bottom of stratrigraphy layer
                else:
                    raise DataSanityError(
                        str(obsid),
                        ru(
                            QCoreApplication.translate(
                                u'SurveyStore',
                                u"Something bad with stratid, depthtop or depthbot!"
                            )))
                    stratigaphy_id = 1  # when something went wrong, put it into first layer
                    depthtotop = 0
                    depthtobot = 999  #default value when something went wrong
                if record[
                        3]:  # Must check since it is not possible to print null values as text in qt widget
                    geology = record[3]  # Geology full text
                else:
                    geology = " "
                geo_short_txt = record[
                    4]  # geo_short might contain national special characters
                if geo_short_txt:  # Must not try to encode an empty field
                    geo_short = unicodedata.normalize(
                        'NFKD', geo_short_txt).encode(
                            'ascii', 'ignore'
                        )  # geo_short normalized for symbols and color
                else:  # If the field is empty, then store an empty string
                    geo_short = ''
                hydro = record[5]  # waterloss (hydrogeo parameter) for color
                if record[
                        6]:  # Must check since it is not possible to print null values as text in qt widget
                    comment = record[6]  #
                else:
                    comment = " "
                if record[
                        7]:  # Must check since it is not possible to print null values as text in qt widget
                    development = record[7]  #
                else:
                    development = " "

                #Add layer if there is a gap
                if depthtotop != prev_depthbot:
                    stratid = len(survey.strata) + 1
                    st = StrataInfo(stratid, prev_depthbot, depthtotop)
                    survey.strata.append(st)

                stratid = len(survey.strata) + 1
                st = StrataInfo(stratid, depthtotop, depthtobot, geology,
                                geo_short, hydro, comment, development)
                survey.strata.append(st)
                prev_depthbot = depthtobot

            DataLoadingStatus = True
        dbconnection.closedb()
        return DataLoadingStatus, surveys