コード例 #1
0
    def _InsertTractRegion(self, process, layer, query, bounds, llD):
        '''
        '''
        #Check that the regioncat is correctly set
        self.cursor.execute("SELECT * FROM system.regioncats WHERE regioncat = '%(regioncat)s';" %query)
        record = self.cursor.fetchone()
        if record == None:
            exitstr = 'the regioncat %(regioncat)s does not exist in the regioncats table' %query
            exit(exitstr)

        #Check that the parent regions is set
        self.cursor.execute("SELECT * FROM system.defregions WHERE regionid = '%(parentid)s' AND regioncat ='%(parentcat)s' ;" %query)
        record = self.cursor.fetchone()
        if record == None:
            if query['parentid'] in ['south-america','antarctica'] and query['parentcat'] == 'subcontinent':
                xquery = {'parentid':query['parentid'], 'parentcat':'continent'}
                self.cursor.execute("SELECT * FROM system.defregions WHERE regionid = '%(parentid)s' AND regioncat ='%(parentcat)s' ;" %xquery)
                record = self.cursor.fetchone()
                if record == None:
                    print ("SELECT * FROM system.defregions WHERE regionid = '%(parentid)s' AND regioncat ='%(parentcat)s' ;" %xquery)
                    FISKA
                    exitstr = 'the parentid region "%s" of regioncat "%s" does not exist in the defregions table' %(query['parentid'], query['parentcat'])
                    exit(exitstr)
            else:
                print ("SELECT * FROM system.defregions WHERE regionid = '%(parentid)s' AND regioncat ='%(parentcat)s' ;" %query)
                FISKA
                exitstr = 'the parentid region "%s" of regioncat "%s" does not exist in the defregions table' %(query['parentid'], query['parentcat'])
                exit(exitstr)

        #Check if the region itself already exists

        self.cursor.execute("SELECT regioncat FROM regions.defregions WHERE regionid = '%(regionid)s';" %query)
        record = self.cursor.fetchone()
        if record == None:
            self.cursor.execute('INSERT INTO regions.defregions (regioncat, regionid, regionname, parentid, title, label) VALUES (%s, %s, %s, %s, %s, %s)',
                                (query['regioncat'], query['regionid'], query['regionname'], query['parentid'], query['title'], query['label']))
            self.conn.commit()

        query['system'] = 'regions'
        query['regiontype'] = 'T'
        self._InsertRegion(query, bounds, llD)
        print (layer.comp.system)
        InsertCompDef(self,layer.comp)
        InsertCompProd(self,layer.comp)
        #InsertCompProd(self,process.system,process.system,layer.comp)
        InsertLayer(self, layer, process.proc.overwrite, process.proc.delete)
コード例 #2
0
 def _InsertLayer(self, layer, overwrite, delete):
     InsertLayer(self, layer, overwrite, delete)
コード例 #3
0
    def _InsertDefRegion(self, process, layer, query, bounds, llD, overwrite,
                         delete):
        '''
        '''
        if overwrite or delete:
            self.cursor.execute(
                "DELETE FROM system.defregions WHERE regionid = '%(regionid)s' AND regioncat ='%(parentcat)s' AND parentid ='%(parentid)s'  ;"
                % query)
            self.conn.commit()
            if delete:
                self._InsertRegion(query, bounds, llD, overwrite, delete)
                return
        #Check that the regioncat is correctly set
        self.cursor.execute(
            "SELECT * FROM system.regioncats WHERE regioncat = '%(regioncat)s';"
            % query)
        record = self.cursor.fetchone()
        if record == None:
            exitstr = 'the regioncat %(regioncat)s does not exist in the regioncats table' % query
            exit(exitstr)

        #Check that the parent regions is set
        self.cursor.execute(
            "SELECT * FROM system.defregions WHERE regionid = '%(parentid)s' AND regioncat ='%(parentcat)s' ;"
            % query)
        record = self.cursor.fetchone()
        if record == None:
            if query['parentid'] in [
                    'south-america', 'antarctica'
            ] and query['parentcat'] == 'subcontinent':
                xquery = {
                    'parentid': query['parentid'],
                    'parentcat': 'continent'
                }
                self.cursor.execute(
                    "SELECT * FROM system.defregions WHERE regionid = '%(parentid)s' AND regioncat ='%(parentcat)s' ;"
                    % xquery)
                record = self.cursor.fetchone()
                if record == None:
                    print(
                        "SELECT * FROM system.defregions WHERE regionid = '%(parentid)s' AND regioncat ='%(parentcat)s' ;"
                        % xquery)
                    FISKA
                    exitstr = 'the parentid region "%s" of regioncat "%s" does not exist in the defregions table' % (
                        query['parentid'], query['parentcat'])
                    exit(exitstr)
            else:

                exitstr = 'the parentid region "%s" of regioncat "%s" does not exist in the defregions table' % (
                    query['parentid'], query['parentcat'])
                print(
                    "SELECT * FROM system.defregions WHERE regionid = '%(parentid)s' AND regioncat ='%(parentcat)s' ;"
                    % query)

                exit(exitstr)

        #Check if the region itself already exists
        #query = {'id': layer.location.regionid}
        self.cursor.execute(
            "SELECT regioncat FROM system.defregions WHERE regionid = '%(regionid)s';"
            % query)
        record = self.cursor.fetchone()
        if record == None:
            self.cursor.execute(
                'INSERT INTO system.defregions (regioncat, regionid, regionname, parentid, title, label) VALUES (%s, %s, %s, %s, %s, %s)',
                (query['regioncat'], query['regionid'], query['regionname'],
                 query['parentid'], query['title'], query['label']))
            self.conn.commit()

        else:
            if query['regioncat'] != record[0]:
                if layer.locus.locus in ['antarctica', 'south-america']:
                    query2 = {
                        'id': layer.locus.locus,
                        'cat': query['regioncat']
                    }
                    self.cursor.execute(
                        "SELECT regioncat FROM system.defregions WHERE regionid = '%(id)s' and regioncat = '%(cat)s';"
                        % query2)
                    record = self.cursor.fetchone()
                    if record == None:
                        self.cursor.execute(
                            'INSERT INTO system.defregions (regioncat, regionid, regionname, parentid, title, label) VALUES (%s, %s, %s, %s, %s, %s)',
                            (query['regioncat'], query['regionid'],
                             query['regionname'], query['parentid'],
                             query['title'], query['label']))
                        self.conn.commit()
                else:
                    pass

        query['system'] = 'system'
        query['regiontype'] = 'D'
        self._InsertRegion(query, bounds, llD, overwrite, delete)

        InsertCompDef(self, layer.comp)
        InsertCompProd(self, layer.comp)
        #InsertCompProd(self,process.system,process.system,layer.comp)
        InsertLayer(self, layer, process.proc.overwrite, process.proc.delete)