MCPcopy
hub / github.com/django/django / __init__

Method __init__

django/contrib/gis/gdal/driver.py:42–74  ·  view source on GitHub ↗

Initialize an GDAL/OGR driver on either a string or integer input.

(self, dr_input)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

ensure_registeredMethod · 0.95
force_bytesFunction · 0.90
GDALExceptionClass · 0.90

Tested by

no test coverage detected