Changeset 5527
- Timestamp:
- 06/24/07 20:29:01 (1 year ago)
- Files:
-
- django/branches/gis/django/contrib/gis/gdal/Envelope.py (added)
- django/branches/gis/django/contrib/gis/gdal/__init__.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/Layer.py (modified) (3 diffs)
- django/branches/gis/django/contrib/gis/gdal/OGRGeometry.py (modified) (3 diffs)
- django/branches/gis/django/contrib/gis/tests/test_gdal_ds.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/__init__.py
r5478 r5527 1 1 from Driver import Driver 2 from Envelope import Envelope 2 3 from DataSource import DataSource 3 4 from SpatialReference import SpatialReference, CoordTransform django/branches/gis/django/contrib/gis/gdal/Layer.py
r5397 r5527 1 1 # Needed ctypes routines 2 from ctypes import c_int, c_long, c_void_p, string_at2 from ctypes import c_int, c_long, c_void_p, byref, string_at 3 3 4 4 # The GDAL C Library … … 6 6 7 7 # Other GDAL imports. 8 from django.contrib.gis.gdal.Envelope import Envelope, OGREnvelope 8 9 from django.contrib.gis.gdal.Feature import Feature 9 from django.contrib.gis.gdal.OGRError import OGRException 10 from django.contrib.gis.gdal.OGRError import OGRException, check_err 10 11 from django.contrib.gis.gdal.SpatialReference import SpatialReference 11 12 … … 59 60 #### Layer properties #### 60 61 @property 62 def extent(self): 63 "Returns the extent (an Envelope) of this layer." 64 env = OGREnvelope() 65 check_err(lgdal.OGR_L_GetExtent(self._layer, byref(env), c_int(1))) 66 return Envelope(env) 67 68 @property 61 69 def name(self): 62 70 "Returns the name of this layer in the Data Source." django/branches/gis/django/contrib/gis/gdal/OGRGeometry.py
r5478 r5527 5 5 # Getting the GDAL C library and error checking facilities 6 6 from django.contrib.gis.gdal.libgdal import lgdal 7 from django.contrib.gis.gdal.Envelope import Envelope, OGREnvelope 7 8 from django.contrib.gis.gdal.OGRError import check_err, OGRException 8 9 from django.contrib.gis.gdal.SpatialReference import SpatialReference, CoordTransform … … 249 250 a = lgdal.OGR_G_GetArea(self._g) 250 251 return a.value 252 253 @property 254 def envelope(self): 255 "Returns the envelope for this Geometry." 256 env = OGREnvelope() 257 lgdal.OGR_G_GetEnvelope(self._g, byref(env)) 258 return Envelope(env) 251 259 252 260 #### Geometry Methods #### … … 323 331 324 332 #### Geometry-generation Methods #### 325 def _geomgen(self, gen_func, other): 326 if not isinstance(other, OGRGeometry): 327 raise OGRException, 'Must use another OGRGeometry object for geometry-generating operations!' 328 return OGRGeometry(gen_func(self._g, other._g)) 333 def _geomgen(self, gen_func, other=None): 334 "A helper routine for the OGR routines that generate geometries." 335 if isinstance(other, OGRGeometry): 336 return OGRGeometry(gen_func(self._g, other._g)) 337 else: 338 return OGRGeometry(gen_func(self._g)) 339 340 @property 341 def boundary(self): 342 "Returns the boundary of this geometry." 343 return self._geomgen(lgdal.OGR_G_GetBoundary) 344 345 @property 346 def convex_hull(self): 347 "Returns the smallest convex Polygon that contains all the points in the Geometry." 348 return self._geomgen(lgdal.OGR_G_ConvexHull) 329 349 330 350 def union(self, other): django/branches/gis/django/contrib/gis/tests/test_gdal_ds.py
r5478 r5527 1 1 import os, os.path, unittest 2 2 from django.contrib.gis.gdal import DataSource, OGRException 3 from django.contrib.gis.gdal.Envelope import Envelope 3 4 from django.contrib.gis.gdal.Field import OFTReal, OFTInteger, OFTString 4 5 … … 17 18 # List of acceptable data sources. 18 19 ds_list = (TestSHP('test_point', nfeat=5, nfld=3, geom='POINT', gtype=1, fields={'dbl' : OFTReal, 'int' : OFTReal, 'str' : OFTString,}, 20 extent=(-1.35011,0.166623,-0.524093,0.824508), # Got extent from QGIS 19 21 srs_wkt='GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]'), 20 22 TestSHP('test_poly', nfeat=3, nfld=3, geom='POLYGON', gtype=3, fields={'float' : OFTReal, 'int' : OFTReal, 'str' : OFTString,}, 23 extent=(-1.01513,-0.558245,0.161876,0.839637), # Got extent from QGIS 21 24 srs_wkt='GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]'), 22 25 ) … … 68 71 69 72 # Making sure we get the number of fields we expect 70 self.assertEqual(layer.num_fields, source.nfld) 71 self.assertEqual(len(layer.fields), source.nfld) 73 self.assertEqual(source.nfld, layer.num_fields) 74 self.assertEqual(source.nfld, len(layer.fields)) 75 76 # Testing the layer's extent (an Envelope), and it's properties 77 self.assertEqual(True, isinstance(layer.extent, Envelope)) 78 self.assertAlmostEqual(source.extent[0], layer.extent.min_x, 5) 79 self.assertAlmostEqual(source.extent[1], layer.extent.min_y, 5) 80 self.assertAlmostEqual(source.extent[2], layer.extent.max_x, 5) 81 self.assertAlmostEqual(source.extent[3], layer.extent.max_y, 5) 72 82 73 83 # Now checking the field names. … … 114 124 # Making sure the SpatialReference is as expected. 115 125 self.assertEqual(source.srs_wkt, g.srs.wkt) 116 126 117 127 def suite(): 118 128 s = unittest.TestSuite()
