Esempio n. 1
0
    def get_tables(self):
        """Get geodatabase tables as `Table` class instances."""
        tables = []
        if self.arcpy_found:
            arcpy.env.workspace = self.path
            for tbl in arcpy.ListTables():
                try:
                    logging.debug("Table: {} ".format(tbl))
                    tbl_instance = Table(arcpy.Describe(tbl).catalogPath)
                    if tbl_instance.OIDFieldName == 'ATTACHMENTID':
                        continue
                    od = OrderedDict()
                    for k, v in GDB_TABLE_PROPS.items():
                        od[v] = getattr(tbl_instance, k, '')

                    # custom props
                    od['Row count'] = tbl_instance.get_row_count()
                    num_attachments = tbl_instance.get_attachments_count()

                    if num_attachments is not None:
                        od['Attachments enabled'] = True
                        od['Attachments count'] = num_attachments
                    else:
                        od['Attachments enabled'] = False
                        od['Attachments count'] = ''

                    tables.append(od)
                except Exception as e:
                    logging.error(
                        'Error. Could not read table  {} '.format(tbl))
                    logging.error(str(e.args[0]))
                    tb = sys.exc_info()[2]
                    tbinfo = traceback.format_tb(tb)[0]
                    logging.error(tbinfo)

        else:
            table_names = [
                self.ds.GetLayerByIndex(i).GetName()
                for i in range(0, self.ds.GetLayerCount())
                if not self.ds.GetLayerByIndex(i).GetGeometryColumn()
            ]
            for table_name in table_names:
                try:
                    tbl_instance = TableOgr(self, table_name)
                    od = OrderedDict()
                    for k, v in GDB_TABLE_PROPS.items():
                        od[v] = getattr(tbl_instance, k, '')

                    # custom props
                    od['Row count'] = tbl_instance.get_row_count()
                    tables.append(od)
                except Exception as e:
                    logger.error(e)
        return tables
Esempio n. 2
0
    def get_tables(self):
        """Get geodatabase tables as `Table` class instances."""
        tables = []
        if self.arcpy_found:
            arcpy.env.workspace = self.path
            for tbl in arcpy.ListTables():
                try:
                    tbl_instance = Table(arcpy.Describe(tbl).catalogPath)
                    if tbl_instance.OIDFieldName == 'ATTACHMENTID':
                        continue
                    od = OrderedDict()
                    for k, v in GDB_TABLE_PROPS.items():
                        od[v] = getattr(tbl_instance, k, '')

                    # custom props
                    od['Row count'] = tbl_instance.get_row_count()
                    num_attachments = tbl_instance.get_attachments_count()

                    if num_attachments is not None:
                        od['Attachments enabled'] = True
                        od['Attachments count'] = num_attachments
                    else:
                        od['Attachments enabled'] = False
                        od['Attachments count'] = ''

                    tables.append(od)
                except Exception as e:
                    print('Error. Could not read table', tbl, '. Reason: ', e)

        else:
            table_names = [
                self.ds.GetLayerByIndex(i).GetName()
                for i in range(0, self.ds.GetLayerCount())
                if not self.ds.GetLayerByIndex(i).GetGeometryColumn()
            ]
            for table_name in table_names:
                try:
                    tbl_instance = TableOgr(self, table_name)
                    od = OrderedDict()
                    for k, v in GDB_TABLE_PROPS.items():
                        od[v] = getattr(tbl_instance, k, '')

                    # custom props
                    od['Row count'] = tbl_instance.get_row_count()
                    tables.append(od)
                except Exception as e:
                    print(e)
        return tables