def __init__( self, layer_wrapper, field: QgsField, values: Set, pk_name: Optional[str] = None, ) -> None: from .layer_wrapper import LayerWrapper self.layer_wrapper: LayerWrapper = layer_wrapper self.name = field.name() self._alias = field.alias() self.type = field.type() self.unique_values = values self.pk_name = pk_name
def combineVectorFields(layerA, layerB): """Create single field map from two input field maps. """ fields = [] fieldsA = layerA.pendingFields() fields.extend(fieldsA) namesA = [unicode(f.name()).lower() for f in fieldsA] fieldsB = layerB.pendingFields() for field in fieldsB: name = unicode(field.name()).lower() if name in namesA: idx = 2 newName = name + '_' + unicode(idx) while newName in namesA: idx += 1 newName = name + '_' + unicode(idx) field = QgsField(newName, field.type(), field.typeName()) fields.append(field) return fields
def combineVectorFields(layerA, layerB): """Create single field map from two input field maps. """ fields = [] fieldsA = layerA.fields() fields.extend(fieldsA) namesA = [str(f.name()).lower() for f in fieldsA] fieldsB = layerB.fields() for field in fieldsB: name = str(field.name()).lower() if name in namesA: idx = 2 newName = name + '_' + str(idx) while newName in namesA: idx += 1 newName = name + '_' + str(idx) field = QgsField(newName, field.type(), field.typeName()) fields.append(field) return fields
def combineFields(fieldsA, fieldsB): """Create single field map from two input field maps. """ fields = [] fields.extend(fieldsA) namesA = [str(f.name()).lower() for f in fieldsA] for field in fieldsB: name = str(field.name()).lower() if name in namesA: idx = 2 newName = name + '_' + str(idx) while newName in namesA: idx += 1 newName = name + '_' + str(idx) field = QgsField(newName, field.type(), field.typeName()) fields.append(field) real_fields = QgsFields() for f in fields: real_fields.append(f) return real_fields
def _qgis_field_to_unfolded_field(self, field: QgsField) -> Field: """ Analyze information about the field :param field: QGIS field :return: Unfolded field """ field_name = field.name() field_type = field.type() format_ = '' if field_type in [QVariant.Int, QVariant.UInt, QVariant.LongLong, QVariant.ULongLong]: type_, analyzer_type = 'integer', 'INT' elif field_type == QVariant.Double: type_, analyzer_type = 'real', 'FLOAT' elif field_type == QVariant.String: if field_name == self.GEOM_FIELD: type_, analyzer_type = 'geojson', 'PAIR_GEOMETRY_FROM_STRING' else: type_, analyzer_type = 'string', 'STRING' elif field_type == QVariant.Bool: type_, analyzer_type = ('boolean', 'BOOLEAN') # TODO: check date time formats elif field_type == QVariant.Date: type_, analyzer_type = ('date', 'DATE') format_ = 'YYYY/M/D' elif field_type == QVariant.DateTime: type_, analyzer_type = ('timestamp', 'DATETIME') format_ = 'YYYY/M/D H:m:s' elif field_type == QVariant.Time: type_, analyzer_type = ('timestamp', 'INT') format_ = 'H:m:s' # elif field_type == QVariant.ByteArray: # type, analyzer_type = ('integer', 'INT') else: raise QgsPluginNotImplementedException(tr('Field type "{}" not implemented yet', field_type)) return Field(field_name, type_, format_, analyzer_type)