Changeset 6707
- Timestamp:
- 11/20/07 09:10:20 (8 months ago)
- Files:
-
- django/branches/gis/django/contrib/gis/gdal/feature.py (modified) (3 diffs)
- django/branches/gis/django/contrib/gis/gdal/field.py (modified) (3 diffs)
- django/branches/gis/django/contrib/gis/gdal/libgdal.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/gdal/prototypes/ds.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/gdal/prototypes/geom.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/gdal/prototypes/srs.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/feature.py
r6686 r6707 34 34 35 35 def __getitem__(self, index): 36 "Gets the Field at the specified index." 36 """ 37 Gets the Field object at the specified index, which may be either 38 an integer or the Field's string label. Note that the Field object 39 is not the field's _value_ -- use the `get` method instead to 40 retrieve the value (e.g. an integer) instead of a Field instance. 41 """ 37 42 if isinstance(index, basestring): 38 43 i = self.index(index) … … 87 92 # Retrieving the geometry pointer for the feature. 88 93 geom_ptr = get_feat_geom_ref(self._ptr) 94 return OGRGeometry(clone_geom(geom_ptr)) 89 95 90 # Attempting to retrieve the Spatial Reference for the geometry.91 try:92 srs_ptr = get_geom_srs(geom_ptr)93 srs = SpatialReference(clone_srs(srs_ptr))94 except OGRException:95 srs = None96 # Geometry is cloned so the feature isn't invalidated.97 return OGRGeometry(clone_geom(geom_ptr), srs)98 99 96 @property 100 97 def geom_type(self): … … 106 103 """ 107 104 Returns the value of the field, instead of an instance of the Field 108 object. May take a string of the field name or a Field object as109 parameters.105 object. May take a string of the field name or a Field object as 106 parameters. 110 107 """ 111 108 field_name = getattr(field, 'name', field) django/branches/gis/django/contrib/gis/gdal/field.py
r6686 r6707 129 129 "Returns a Python `date` object for the OFTDate field." 130 130 yy, mm, dd, hh, mn, ss, tz = self.as_datetime() 131 return date(yy.value, mm.value, dd.value) 131 try: 132 return date(yy.value, mm.value, dd.value) 133 except ValueError: 134 return None 132 135 133 136 class OFTDateTime(Field): … … 140 143 # The `tz` variable has values of: 0=unknown, 1=localtime (ambiguous), 141 144 # 100=GMT, 104=GMT+1, 80=GMT-5, etc. 142 return datetime(yy.value, mm.value, dd.value, hh.value, mn.value, ss.value) 145 try: 146 return datetime(yy.value, mm.value, dd.value, hh.value, mn.value, ss.value) 147 except ValueError: 148 return None 143 149 144 150 class OFTTime(Field): … … 147 153 "Returns a Python `time` object for this OFTTime field." 148 154 yy, mm, dd, hh, mn, ss, tz = self.as_datetime() 149 return time(hh.value, mn.value, ss.value) 155 try: 156 return time(hh.value, mn.value, ss.value) 157 except ValueError: 158 return None 150 159 151 160 # List fields are also just subclasses django/branches/gis/django/contrib/gis/gdal/libgdal.py
r6686 r6707 7 7 # Windows NT shared library 8 8 lib_name = 'libgdal-1.dll' 9 errcheck_flag = False 9 10 elif os.name == 'posix': 10 11 platform = os.uname()[0] … … 15 16 # Attempting to use .so extension for all other platforms. 16 17 lib_name = 'libgdal.so' 18 errcheck_flag = True 17 19 else: 18 20 raise OGRException('Unsupported OS "%s"' % os.name) django/branches/gis/django/contrib/gis/gdal/prototypes/ds.py
r6686 r6707 6 6 from ctypes import c_char_p, c_int, c_long, c_void_p, POINTER 7 7 from django.contrib.gis.gdal.envelope import OGREnvelope 8 from django.contrib.gis.gdal.libgdal import lgdal 8 from django.contrib.gis.gdal.libgdal import lgdal, errcheck_flag 9 9 from django.contrib.gis.gdal.prototypes.generation import \ 10 10 const_string_output, double_output, geom_output, int_output, \ … … 48 48 ### Feature Routines ### 49 49 clone_feature = voidptr_output(lgdal.OGR_F_Clone, [c_void_p]) 50 destroy_feature = void_output(lgdal.OGR_F_Destroy, [c_void_p] )50 destroy_feature = void_output(lgdal.OGR_F_Destroy, [c_void_p], errcheck=errcheck_flag) 51 51 feature_equal = int_output(lgdal.OGR_F_Equal, [c_void_p, c_void_p]) 52 52 get_feat_geom_ref = geom_output(lgdal.OGR_F_GetGeometryRef, [c_void_p]) django/branches/gis/django/contrib/gis/gdal/prototypes/geom.py
r6686 r6707 1 1 from ctypes import c_char, c_char_p, c_double, c_int, c_ubyte, c_void_p, POINTER 2 2 from django.contrib.gis.gdal.envelope import OGREnvelope 3 from django.contrib.gis.gdal.libgdal import lgdal 3 from django.contrib.gis.gdal.libgdal import lgdal, errcheck_flag 4 4 from django.contrib.gis.gdal.prototypes.errcheck import check_bool, check_envelope 5 5 from django.contrib.gis.gdal.prototypes.generation import \ … … 73 73 get_point_count = int_output(lgdal.OGR_G_GetPointCount, [c_void_p]) 74 74 get_point = void_output(lgdal.OGR_G_GetPoint, [c_void_p, c_int, POINTER(c_double), POINTER(c_double), POINTER(c_double)], errcheck=False) 75 geom_close_rings = void_output(lgdal.OGR_G_CloseRings, [c_void_p] )75 geom_close_rings = void_output(lgdal.OGR_G_CloseRings, [c_void_p], errcheck=errcheck_flag) 76 76 77 77 # Topology routines. django/branches/gis/django/contrib/gis/gdal/prototypes/srs.py
r6686 r6707 1 1 from ctypes import c_char_p, c_int, c_void_p, POINTER 2 from django.contrib.gis.gdal.libgdal import lgdal 2 from django.contrib.gis.gdal.libgdal import lgdal, errcheck_flag 3 3 from django.contrib.gis.gdal.prototypes.generation import \ 4 4 const_string_output, double_output, int_output, \ … … 23 23 clone_srs = srs_output(lgdal.OSRClone, [c_void_p]) 24 24 new_srs = srs_output(lgdal.OSRNewSpatialReference, [c_char_p]) 25 release_srs = void_output(lgdal.OSRRelease, [c_void_p]) 26 srs_validate = void_output(lgdal.OSRValidate, [c_void_p], errcheck=True) 25 release_srs = void_output(lgdal.OSRRelease, [c_void_p], errcheck=errcheck_flag) 26 destroy_srs = void_output(lgdal.OSRDestroySpatialReference, [c_void_p], errcheck=errcheck_flag) 27 srs_validate = void_output(lgdal.OSRValidate, [c_void_p]) 27 28 28 29 # Getting the semi_major, semi_minor, and flattening functions. … … 68 69 # Coordinate transformation 69 70 new_ct= srs_output(lgdal.OCTNewCoordinateTransformation, [c_void_p, c_void_p]) 70 destroy_ct = void_output(lgdal.OCTDestroyCoordinateTransformation, [c_void_p] )71 destroy_ct = void_output(lgdal.OCTDestroyCoordinateTransformation, [c_void_p], errcheck=errcheck_flag)
