def __init__(self, back_ds, allocator, open_options, mode):
        uid = uuid.uuid4()

        with back_ds.acquire_driver_object(uid, allocator) as gdal_objs:
            gdal_ds, lyr = gdal_objs
            rect = None
            if lyr is not None:
                rect = lyr.GetExtent()
            path = gdal_ds.GetDescription()
            driver = gdal_ds.GetDriver().ShortName
            sr = lyr.GetSpatialRef()
            if sr is None:
                wkt_stored = None
            else:
                wkt_stored = sr.ExportToWkt()
            fields = BackGDALFileVector._fields_of_lyr(lyr)
            type = conv.str_of_wkbgeom(lyr.GetGeomType())
            layer = lyr.GetName()

        super(BackGDALFileVector, self).__init__(back_ds=back_ds,
                                                 wkt_stored=wkt_stored,
                                                 mode=mode,
                                                 driver=driver,
                                                 open_options=open_options,
                                                 path=path,
                                                 uid=uid,
                                                 layer=layer,
                                                 fields=fields,
                                                 rect=rect,
                                                 type=type)

        self._type_of_field_index = [
            conv.type_of_oftstr(field['type']) for field in self.fields
        ]
示例#2
0
 def __init__(self, type, fields, **kwargs):
     super(ABackProxyVector, self).__init__(**kwargs)
     self.type = type
     self.fields = fields
     self.index_of_field_name = {
         field['name']: i
         for i, field in enumerate(self.fields)
     }
     self.type_of_field_index = [
         conv.type_of_oftstr(field['type']) for field in self.fields
     ]
     self.all_nullable = all(field['nullable'] for field in self.fields)
示例#3
0
 def _field_of_def(fielddef):
     """Used on file opening / creation"""
     oft = fielddef.type
     oftstr = conv.str_of_oft(oft)
     type_ = conv.type_of_oftstr(oftstr)
     default = fielddef.GetDefault()
     return {
         'name': fielddef.name,
         'precision': fielddef.precision,
         'width': fielddef.width,
         'nullable': bool(fielddef.IsNullable()),
         'default': None if default is None else type_(default),
         'type': oftstr,
     }
    def __init__(self, back_ds, allocator, open_options):
        # gdal_ds, lyr = self.create_file('', geometry, fields, layer, 'Memory', open_options, sr)

        gdal_ds, lyr = allocator()
        self._gdal_ds = gdal_ds
        self._lyr = lyr

        rect = None
        if lyr is not None:
            rect = lyr.GetExtent()

        path = gdal_ds.GetDescription()
        driver = gdal_ds.GetDriver().ShortName
        sr = lyr.GetSpatialRef()
        if sr is None:
            wkt_stored = None
        else:
            wkt_stored = sr.ExportToWkt()
        fields = BackGDALMemoryVector._fields_of_lyr(lyr)
        type = conv.str_of_wkbgeom(lyr.GetGeomType())
        layer = lyr.GetName()

        super(BackGDALMemoryVector, self).__init__(
            back_ds=back_ds,
            wkt_stored=wkt_stored,
            mode='w',
            driver=driver,
            open_options=open_options,
            path=path,
            layer=layer,
            fields=fields,
            rect=rect,
            type=type
        )

        self._type_of_field_index = [
            conv.type_of_oftstr(field['type'])
            for field in self.fields
        ]
示例#5
0
 def _sanitize_dict(dic):
     dic = dict(dic)
     name = dic.pop('name')
     type_ = dic.pop('type')
     precision = dic.pop('precision', None)
     width = dic.pop('width', None)
     nullable = dic.pop('nullable', None)
     default = dic.pop('default', None)
     oft = conv.oft_of_any(type_)
     if default is not None:
         default = str(
             conv.type_of_oftstr(conv.str_of_oft(oft))(default))
     if len(dic) != 0:
         raise ValueError('unexpected keys in {} dict: {}'.format(
             name, dic))
     return dict(
         name=name,
         type=oft,
         precision=precision,
         width=width,
         nullable=nullable,
         default=default,
     )
示例#6
0
    def __init__(self, ds, consts, gdal_ds=None, lyr=None):
        """Instanciated by DataSource class, instanciation by user is undefined"""
        rect = None
        if lyr is not None:
            rect = lyr.GetExtent()
        Proxy.__init__(self, ds, consts, rect)

        self._gdal_ds = gdal_ds
        self._lyr = lyr

        self._index_of_field_name = {
            field['name']: i
            for i, field in enumerate(self._c.fields)
        }
        self._type_of_field_index = [
            conv.type_of_oftstr(field['type'])
            for field in self._c.fields
        ]
        self._all_nullable = all(field['nullable'] for field in self._c.fields)
        if ds._ogr_layer_lock == 'none':
            self._lock = None
        else:
            self._lock = threading.Lock()