Changeset 6639
- Timestamp:
- 11/03/07 19:48:10 (8 months ago)
- Files:
-
- django/branches/gis/django/contrib/gis/gdal/datasource.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/driver.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/feature.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/gdal/field.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/__init__.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/layer.py (modified) (5 diffs)
- django/branches/gis/django/contrib/gis/gdal/libgdal.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/gdal/srs.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/datasource.py
r6436 r6639 56 56 def __init__(self, ds_input, ds_driver=False): 57 57 58 self._ds = 0# Initially NULL58 self._ds = None # Initially NULL 59 59 60 60 # Registering all the drivers, this needs to be done django/branches/gis/django/contrib/gis/gdal/driver.py
r6436 r6639 28 28 if isinstance(input, StringType): 29 29 # If a string name of the driver was passed in 30 self._dr = 0# Initially NULL30 self._dr = None # Initially NULL 31 31 self._register() 32 32 django/branches/gis/django/contrib/gis/gdal/feature.py
r6464 r6639 18 18 19 19 #### Python 'magic' routines #### 20 def __init__(self, f ):20 def __init__(self, feat, fdefn): 21 21 "Needs a C pointer (Python integer in ctypes) in order to initialize." 22 self._feat = 0# Initially NULL23 self._fdefn = 024 if not f :22 self._feat = None # Initially NULL 23 self._fdefn = None 24 if not feat or not fdefn: 25 25 raise OGRException('Cannot create OGR Feature, invalid pointer given.') 26 self._feat = f 27 self._fdefn = lgdal.OGR_F_GetDefnRef(f)26 self._feat = feat 27 self._fdefn = fdefn 28 28 29 29 def __del__(self): 30 30 "Releases a reference to this object." 31 if self._f defn: lgdal.OGR_FD_Release(self._fdefn)31 if self._feat: lgdal.OGR_F_Destroy(self._feat) 32 32 33 33 def __getitem__(self, index): … … 92 92 93 93 # Attempting to retrieve the Spatial Reference for the geometry. 94 srs_ptr = lgdal.O GR_G_GetSpatialReference(geom_ptr)94 srs_ptr = lgdal.OSRClone(lgdal.OGR_G_GetSpatialReference(geom_ptr)) 95 95 if srs_ptr: 96 96 srs = SpatialReference(srs_ptr, 'ogr') django/branches/gis/django/contrib/gis/gdal/field.py
r6436 r6639 13 13 def __init__(self, fld, val=''): 14 14 "Needs a C pointer (Python integer in ctypes) in order to initialize." 15 self._fld = 0# Initially NULL15 self._fld = None # Initially NULL 16 16 17 17 if not fld: django/branches/gis/django/contrib/gis/gdal/__init__.py
r6436 r6639 27 27 from django.contrib.gis.gdal.driver import Driver 28 28 from django.contrib.gis.gdal.datasource import DataSource 29 from django.contrib.gis.gdal.libgdal import gdal_version, gdal_full_version, gdal_release_date 29 30 from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform 30 31 from django.contrib.gis.gdal.geometries import OGRGeometry django/branches/gis/django/contrib/gis/gdal/layer.py
r6421 r6639 28 28 def __init__(self, l): 29 29 "Needs a C pointer (Python/ctypes integer) in order to initialize." 30 self._layer = 0# Initially NULL31 self._ldefn = 030 self._layer = None # Initially NULL 31 self._ldefn = None 32 32 if not l: 33 33 raise OGRException, 'Cannot create Layer, invalid pointer given' … … 37 37 def __getitem__(self, index): 38 38 "Gets the Feature at the specified index." 39 def make_feature(offset):40 return Feature(lgdal.OGR_L_GetFeature(self._layer,41 c_long(offset)))42 end = self.num_feat43 39 if not isinstance(index, (slice, int)): 44 40 raise TypeError 45 41 end = self.num_feat 46 42 if isinstance(index,int): 47 43 # An integer index was given … … 50 46 if index < 0 or index >= self.num_feat: 51 47 raise OGRIndexError, 'index out of range' 52 return make_feature(index)48 return self._make_feature(index) 53 49 else: 54 50 # A slice was given 55 51 start, stop, stride = index.indices(end) 56 return [ make_feature(offset) for offset in range(start,stop,stride)]52 return [self._make_feature(offset) for offset in range(start,stop,stride)] 57 53 58 54 def __iter__(self): 59 55 "Iterates over each Feature in the Layer." 60 #TODO: is OGR's GetNextFeature faster here? 56 # ResetReading() must be called before iteration is to begin. 57 lgdal.OGR_L_ResetReading(self._layer) 61 58 for i in range(self.num_feat): 62 yield self.__getitem__(i)59 yield Feature(lgdal.OGR_L_GetNextFeature(self._layer), self._ldefn) 63 60 64 61 def __len__(self): … … 69 66 "The string name of the layer." 70 67 return self.name 68 69 def _make_feature(self, offset): 70 "Helper routine for __getitem__ that makes a feature from an offset." 71 return Feature(lgdal.OGR_L_GetFeature(self._layer, c_long(offset)), self._ldefn) 71 72 72 73 #### Layer properties #### … … 113 114 for i in xrange(self.num_fields) ] 114 115 116 @property 117 def field_widths(self): 118 "Returns a list of the maximum field widths for the features." 119 return [ int(lgdal.OGR_Fld_GetWidth(lgdal.OGR_FD_GetFieldDefn(self._ldefn, i))) 120 for i in xrange(self.num_fields) ] 121 122 @property 123 def field_precisions(self): 124 "Returns the field precisions for the features." 125 return [ int(lgdal.OGR_Fld_GetPrecision(lgdal.OGR_FD_GetFieldDefn(self._ldefn, i))) 126 for i in xrange(self.num_fields) ] 127 115 128 #### Layer Methods #### 116 129 def get_fields(self, field_name): django/branches/gis/django/contrib/gis/gdal/libgdal.py
r5749 r6639 1 1 import os, sys 2 from ctypes import CDLL 2 from ctypes import CDLL, string_at 3 3 from django.contrib.gis.gdal.error import OGRException 4 4 … … 22 22 lgdal = CDLL(lib_name) 23 23 24 #### Version-information functions. #### 25 def _version_info(key): 26 "Returns GDAL library version information with the given key." 27 buf = lgdal.GDALVersionInfo(key) 28 if buf: return string_at(buf) 29 30 def gdal_version(): 31 "Returns only the GDAL version number information." 32 return _version_info('RELEASE_NAME') 33 34 def gdal_full_version(): 35 "Returns the full GDAL version information." 36 return _version_info('') 37 38 def gdal_release_date(date=False): 39 """ 40 Returns the release date in a string format, e.g, "2007/06/27". 41 If the date keyword argument is set to True, a Python datetime object 42 will be returned instead. 43 """ 44 from datetime import datetime 45 rel = _version_info('RELEASE_DATE') 46 yy, mm, dd = map(int, (rel[0:4], rel[4:6], rel[6:8])) 47 d = datetime(yy, mm, dd) 48 if date: return d 49 else: return d.strftime('%Y/%m/%d') django/branches/gis/django/contrib/gis/gdal/srs.py
r6574 r6639 83 83 "Creates a spatial reference object from the given OGC Well Known Text (WKT)." 84 84 85 self._srs = 0# Initially NULL85 self._srs = None # Initially NULL 86 86 87 87 # Creating an initial empty string buffer.
