(self, ds_input, ds_driver=False, write=False, encoding="utf-8")
| 53 | destructor = capi.destroy_ds |
| 54 | |
| 55 | def __init__(self, ds_input, ds_driver=False, write=False, encoding="utf-8"): |
| 56 | # The write flag. |
| 57 | self._write = capi.GDAL_OF_UPDATE if write else capi.GDAL_OF_READONLY |
| 58 | # See also https://gdal.org/development/rfc/rfc23_ogr_unicode.html |
| 59 | self.encoding = encoding |
| 60 | |
| 61 | Driver.ensure_registered() |
| 62 | |
| 63 | if isinstance(ds_input, (str, Path)): |
| 64 | try: |
| 65 | # GDALOpenEx will auto-detect the data source type. |
| 66 | ds = capi.open_ds( |
| 67 | force_bytes(ds_input), |
| 68 | self._write | capi.GDAL_OF_VECTOR, |
| 69 | None, |
| 70 | None, |
| 71 | None, |
| 72 | ) |
| 73 | except GDALException: |
| 74 | # Making the error message more clear rather than something |
| 75 | # like "Invalid pointer returned from OGROpen". |
| 76 | raise GDALException('Could not open the datasource at "%s"' % ds_input) |
| 77 | elif isinstance(ds_input, self.ptr_type) and isinstance( |
| 78 | ds_driver, Driver.ptr_type |
| 79 | ): |
| 80 | ds = ds_input |
| 81 | else: |
| 82 | raise GDALException("Invalid data source input type: %s" % type(ds_input)) |
| 83 | |
| 84 | if ds: |
| 85 | self.ptr = ds |
| 86 | driver = capi.get_dataset_driver(ds) |
| 87 | self.driver = Driver(driver) |
| 88 | else: |
| 89 | # Raise an exception if the returned pointer is NULL |
| 90 | raise GDALException('Invalid data source file "%s"' % ds_input) |
| 91 | |
| 92 | def __getitem__(self, index): |
| 93 | "Allows use of the index [] operator to get a layer at the index." |
nothing calls this directly
no test coverage detected