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

Method __getitem__

django/contrib/gis/gdal/srs.py:113–144  ·  view source on GitHub ↗

Return the value of the given string attribute node, None if the node doesn't exist. Can also take a tuple as a parameter, (target, child), where child is the index of the attribute in the WKT. For example: >>> wkt = ( ... 'GEOGCS["WGS 84",' ...

(self, target)

Source from the content-addressed store, hash-verified

111 self.import_epsg(srs_input)
112
113 def __getitem__(self, target):
114 """
115 Return the value of the given string attribute node, None if the node
116 doesn't exist. Can also take a tuple as a parameter, (target, child),
117 where child is the index of the attribute in the WKT. For example:
118
119 >>> wkt = (
120 ... 'GEOGCS["WGS 84",'
121 ... ' DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]'
122 ... ']'
123 ... )
124 >>> srs = SpatialReference(wkt) # could also use 'WGS84', or 4326
125 >>> print(srs['GEOGCS'])
126 WGS 84
127 >>> print(srs['DATUM'])
128 WGS_1984
129 >>> print(srs['AUTHORITY'])
130 EPSG
131 >>> print(srs['AUTHORITY', 1]) # The authority value
132 4326
133 >>> print(srs['TOWGS84', 4]) # the fourth value in this wkt
134 0
135 >>> # For the units authority, have to use the pipe symbole.
136 >>> print(srs['UNIT|AUTHORITY'])
137 EPSG
138 >>> print(srs['UNIT|AUTHORITY', 1]) # The authority value for the units
139 9122
140 """
141 if isinstance(target, tuple):
142 return self.attr_value(*target)
143 else:
144 return self.attr_value(target)
145
146 def __str__(self):
147 "Use 'pretty' WKT."

Callers 1

test13_attr_valueMethod · 0.95

Calls 1

attr_valueMethod · 0.95

Tested by 1

test13_attr_valueMethod · 0.76