Changeset 6574
- Timestamp:
- 10/20/07 23:27:22 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/srs.py
r6460 r6574 71 71 """ 72 72 A wrapper for the OGRSpatialReference object. According to the GDAL website, 73 the SpatialReference object 'provide[s] services to represent coordinate74 systems (projections and datums) and to transform between them.'73 the SpatialReference object 'provide[s] services to represent coordinate 74 systems (projections and datums) and to transform between them.' 75 75 """ 76 76 … … 136 136 """ 137 137 Returns the value of the given string attribute node, None if the node 138 doesn't exist. Can also take a tuple as a parameter, (target, child), 139 where child is the child index to get. 138 doesn't exist. Can also take a tuple as a parameter, (target, child), 139 where child is the index of the attribute in the WKT. For example: 140 141 >>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]') 142 >>> srs = SpatialReference(wkt) # could also use 'WGS84', or 4326 143 >>> print srs['GEOGCS'] 144 WGS 84 145 >>> print srs['DATUM'] 146 WGS_1984 147 >>> print srs['AUTHORITY'] 148 EPSG 149 >>> print srs['AUTHORITY', 1] # The authority value 150 4326 151 >>> print srs['TOWGS84', 4] # the fourth value in this wkt 152 0 153 >>> print srs['UNIT|AUTHORITY'] # For the units authority, have to use the pipe symbole. 154 EPSG 155 >>> print srs['UNIT|AUTHORITY', 1] # The authority value for the untis 156 9122 140 157 """ 141 158 if isinstance(target, TupleType): … … 159 176 """ 160 177 Returns the string at the pointer if it is valid, None if the pointer 161 is NULL.178 is NULL. 162 179 """ 163 180 if not ptr: return None … … 178 195 """ 179 196 The attribute value for the given target node (e.g. 'PROJCS'). The index 180 keyword specifies an index of the child node to return. 181 """ 197 keyword specifies an index of the child node to return. 198 """ 199 if not isinstance(target, str): 200 raise TypeError('Attribute target must be a string') 182 201 ptr = lgdal.OSRGetAttrValue(self._srs, c_char_p(target), c_int(index)) 183 202 return self._string_ptr(ptr) … … 201 220 @property 202 221 def srid(self): 203 """ 204 Returns the EPSG SRID of this Spatial Reference, will be None if 205 if undefined. 206 """ 222 "Returns the SRID of top-level authority, or None if undefined." 207 223 try: 208 224 return int(self.attr_value('AUTHORITY', 1)) 209 except ValueError:225 except (TypeError, ValueError): 210 226 return None 211 227 django/branches/gis/django/contrib/gis/tests/test_gdal_srs.py
r5748 r6574 146 146 if s.proj: 147 147 ct = CoordTransform(SpatialReference(s.wkt), target) 148 149 def test13_attr_value(self): 150 "Testing the attr_value() method." 151 s1 = SpatialReference('WGS84') 152 self.assertRaises(TypeError, s1.__getitem__, 0) 153 self.assertRaises(TypeError, s1.__getitem__, ('GEOGCS', 'foo')) 154 self.assertEqual('WGS 84', s1['GEOGCS']) 155 self.assertEqual('WGS_1984', s1['DATUM']) 156 self.assertEqual('EPSG', s1['AUTHORITY']) 157 self.assertEqual(4326, int(s1['AUTHORITY', 1])) 158 for i in range(7): self.assertEqual(0, int(s1['TOWGS84', i])) 159 self.assertEqual(None, s1['FOOBAR']) 148 160 149 161 def suite():
