Initialize an GDAL/OGR driver on either a string or integer input.
(self, dr_input)
| 40 | ) |
| 41 | |
| 42 | def __init__(self, dr_input): |
| 43 | """ |
| 44 | Initialize an GDAL/OGR driver on either a string or integer input. |
| 45 | """ |
| 46 | if isinstance(dr_input, str): |
| 47 | # If a string name of the driver was passed in |
| 48 | self.ensure_registered() |
| 49 | |
| 50 | # Checking the alias dictionary (case-insensitive) to see if an |
| 51 | # alias exists for the given driver. |
| 52 | if dr_input.lower() in self._alias: |
| 53 | name = self._alias[dr_input.lower()] |
| 54 | else: |
| 55 | name = dr_input |
| 56 | |
| 57 | # Attempting to get the GDAL/OGR driver by the string name. |
| 58 | driver = c_void_p(capi.get_driver_by_name(force_bytes(name))) |
| 59 | elif isinstance(dr_input, int): |
| 60 | self.ensure_registered() |
| 61 | driver = capi.get_driver(dr_input) |
| 62 | elif isinstance(dr_input, c_void_p): |
| 63 | driver = dr_input |
| 64 | else: |
| 65 | raise GDALException( |
| 66 | "Unrecognized input type for GDAL/OGR Driver: %s" % type(dr_input) |
| 67 | ) |
| 68 | |
| 69 | # Making sure we get a valid pointer to the OGR Driver |
| 70 | if not driver: |
| 71 | raise GDALException( |
| 72 | "Could not initialize GDAL/OGR Driver on input: %s" % dr_input |
| 73 | ) |
| 74 | self.ptr = driver |
| 75 | |
| 76 | def __str__(self): |
| 77 | return self.name |
nothing calls this directly
no test coverage detected