MCPcopy
hub / github.com/django/django / __getitem__

Method __getitem__

django/contrib/gis/gdal/datasource.py:92–109  ·  view source on GitHub ↗

Allows use of the index [] operator to get a layer at the index.

(self, index)

Source from the content-addressed store, hash-verified

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."
94 if isinstance(index, str):
95 try:
96 layer = capi.get_layer_by_name(self.ptr, force_bytes(index))
97 except GDALException:
98 raise IndexError("Invalid OGR layer name given: %s." % index)
99 elif isinstance(index, int):
100 if 0 <= index < self.layer_count:
101 layer = capi.get_layer(self._ptr, index)
102 else:
103 raise IndexError(
104 "Index out of range when accessing layers in a datasource: %s."
105 % index
106 )
107 else:
108 raise TypeError("Invalid index type: %s" % type(index))
109 return Layer(layer, self)
110
111 def __len__(self):
112 "Return the number of layers within the data source."

Callers 1

test01_valid_shpMethod · 0.95

Calls 3

force_bytesFunction · 0.90
LayerClass · 0.90
get_layerMethod · 0.80

Tested by 1

test01_valid_shpMethod · 0.76