Ticket #11433: 3d_fix_v1.diff
File 3d_fix_v1.diff, 9.9 KB (added by , 15 years ago) |
---|
-
django/contrib/gis/geos/geometry.py
375 375 """ 376 376 # A possible faster, all-python, implementation: 377 377 # str(self.wkb).encode('hex') 378 return wkb_w.write_hex(self) 378 if self.hasz: 379 return wkb_w3d.write_hex(self) 380 else: 381 return wkb_w.write_hex(self) 379 382 380 383 @property 381 384 def json(self): … … 392 395 @property 393 396 def wkb(self): 394 397 "Returns the WKB of the Geometry as a buffer." 395 return wkb_w.write(self) 398 if self.hasz: 399 return wkb_w3d.write(self) 400 else: 401 return wkb_w.write(self) 396 402 397 403 @property 398 404 def kml(self): … … 617 623 } 618 624 619 625 # Similarly, import the GEOS I/O instances here to avoid conflicts. 620 from django.contrib.gis.geos.io import wkt_r, wkt_w, wkb_r, wkb_w 626 from django.contrib.gis.geos.io import wkt_r, wkt_w, wkb_r, wkb_w, wkb_w3d 621 627 622 628 # If supported, import the PreparedGeometry class. 623 629 if GEOS_PREPARE: -
django/contrib/gis/geos/prototypes/geom.py
62 62 63 63 ### ctypes prototypes ### 64 64 65 # Deprecated creation routines from WKB, HEX, WKT65 # Deprecated creation and output routines from WKB, HEX, WKT 66 66 from_hex = bin_constructor(lgeos.GEOSGeomFromHEX_buf) 67 67 from_wkb = bin_constructor(lgeos.GEOSGeomFromWKB_buf) 68 68 from_wkt = geom_output(lgeos.GEOSGeomFromWKT, [c_char_p]) 69 69 70 # Output routines71 70 to_hex = bin_output(lgeos.GEOSGeomToHEX_buf) 72 71 to_wkb = bin_output(lgeos.GEOSGeomToWKB_buf) 73 72 to_wkt = string_from_geom(lgeos.GEOSGeomToWKT) 74 73 75 # The GEOS geometry type, typeid, num_coordi tes and number of geometries74 # The GEOS geometry type, typeid, num_coordinates and number of geometries 76 75 geos_normalize = int_from_geom(lgeos.GEOSNormalize) 77 76 geos_type = string_from_geom(lgeos.GEOSGeomType) 78 77 geos_typeid = int_from_geom(lgeos.GEOSGeomTypeId) -
django/contrib/gis/geos/io.py
14 14 "Base class for GEOS I/O objects." 15 15 def __init__(self): 16 16 # Getting the pointer with the constructor. 17 self.ptr = self. constructor()17 self.ptr = self._constructor() 18 18 19 19 def __del__(self): 20 20 # Cleaning up with the appropriate destructor. 21 if self._ptr: self. destructor(self._ptr)21 if self._ptr: self._destructor(self._ptr) 22 22 23 23 ### WKT Reading and Writing objects ### 24 24 25 25 # Non-public class for internal use because its `read` method returns 26 26 # _pointers_ instead of a GEOSGeometry object. 27 27 class _WKTReader(IOBase): 28 constructor = capi.wkt_reader_create29 destructor = capi.wkt_reader_destroy28 _constructor = capi.wkt_reader_create 29 _destructor = capi.wkt_reader_destroy 30 30 ptr_type = capi.WKT_READ_PTR 31 31 32 32 def read(self, wkt): … … 39 39 return GEOSGeometry(super(WKTReader, self).read(wkt)) 40 40 41 41 class WKTWriter(IOBase): 42 constructor = capi.wkt_writer_create43 destructor = capi.wkt_writer_destroy42 _constructor = capi.wkt_writer_create 43 _destructor = capi.wkt_writer_destroy 44 44 ptr_type = capi.WKT_WRITE_PTR 45 45 46 46 def write(self, geom): … … 51 51 52 52 # Non-public class for the same reason as _WKTReader above. 53 53 class _WKBReader(IOBase): 54 constructor = capi.wkb_reader_create55 destructor = capi.wkb_reader_destroy54 _constructor = capi.wkb_reader_create 55 _destructor = capi.wkb_reader_destroy 56 56 ptr_type = capi.WKB_READ_PTR 57 57 58 58 def read(self, wkb): … … 71 71 return GEOSGeometry(super(WKBReader, self).read(wkb)) 72 72 73 73 class WKBWriter(IOBase): 74 constructor = capi.wkb_writer_create75 destructor = capi.wkb_writer_destroy74 _constructor = capi.wkb_writer_create 75 _destructor = capi.wkb_writer_destroy 76 76 ptr_type = capi.WKB_WRITE_PTR 77 77 78 78 def write(self, geom): … … 121 121 wkt_w = WKTWriter() 122 122 wkb_r = _WKBReader() 123 123 wkb_w = WKBWriter() 124 wkb_w3d = WKBWriter() 125 wkb_w3d.outdim = 3 -
django/contrib/gis/utils/layermapping.py
493 493 # Transforming the geometry with our Coordinate Transformation object, 494 494 # but only if the class variable `transform` is set w/a CoordTransform 495 495 # object. 496 if self.transform: g.transform(self.transform) 496 if self.transform: 497 # Have to get the coordinate dimension of the original geometry 498 # and set the transformed geometry's dimension with it afterwards. 499 # This is because of a GDAL bug (in versions prior to 1.7) which 500 # automatically converts non-point 2D geometries to 3D if they're: 501 # transformed. See: http://trac.osgeo.org/gdal/changeset/17792 502 orig_dim = g.coord_dim 503 g.transform(self.transform) 504 if g.coord_dim != orig_dim: 505 g.coord_dim = orig_dim 497 506 498 507 # Returning the WKT of the geometry. 499 508 return g.wkt … … 506 515 # Getting the target spatial reference system 507 516 target_srs = SpatialRefSys.objects.get(srid=self.geo_col.srid).srs 508 517 509 # Creating the CoordTransform object 518 # Creating the CoordTransform object -- which is much faster than 519 # transforming w/a SpatialReferencce object. 510 520 return CoordTransform(self.source_srs, target_srs) 511 521 except Exception, msg: 512 522 raise LayerMapError('Could not translate between the data source and model geometry: %s' % msg) -
django/contrib/gis/tests/geo3d/views.py
1 # Create your views here. -
django/contrib/gis/tests/geo3d/tests.py
1 import unittest 2 from django.test import TestCase 3 4 from models import City3D 5 6 class Geo3DTest(TestCase): 7 def test01_3D(self): 8 "Test the creation of 3D models." 9 City3D.objects.create(name='Pueblo', point='POINT(5 23 17)') 10 cty = City3D.objects.get(name='Pueblo') 11 self.assertEqual(17.0, cty.point.z) 12 13 def suite(): 14 s = unittest.TestSuite() 15 s.addTest(unittest.makeSuite(Geo3DTest)) 16 return s -
django/contrib/gis/tests/geo3d/models.py
1 from django.contrib.gis.db import models 2 3 class City3D(models.Model): 4 name = models.CharField(max_length=30) 5 point = models.PointField(dim=3) 6 objects = models.GeoManager() 7 8 def __unicode__(self): 9 return self.name -
django/contrib/gis/tests/__init__.py
21 21 s.addTest(geos_tests.suite()) 22 22 23 23 # Tests that require use of a spatial database (e.g., creation of models) 24 test_apps = ['geoapp', 'relatedapp' ]24 test_apps = ['geoapp', 'relatedapp', 'geo3d'] 25 25 26 26 # Tests that do not require setting up and tearing down a spatial database. 27 27 test_suite_names = [ -
django/contrib/gis/gdal/prototypes/geom.py
83 83 get_area = double_output(lgdal.OGR_G_GetArea, [c_void_p]) 84 84 get_centroid = void_output(lgdal.OGR_G_Centroid, [c_void_p, c_void_p]) 85 85 get_dims = int_output(lgdal.OGR_G_GetDimension, [c_void_p]) 86 get_coord_dims = int_output(lgdal.OGR_G_GetCoordinateDimension, [c_void_p]) 86 get_coord_dim = int_output(lgdal.OGR_G_GetCoordinateDimension, [c_void_p]) 87 set_coord_dim = void_output(lgdal.OGR_G_SetCoordinateDimension, [c_void_p, c_int], errcheck=False) 87 88 88 89 get_geom_count = int_output(lgdal.OGR_G_GetGeometryCount, [c_void_p]) 89 90 get_geom_name = const_string_output(lgdal.OGR_G_GetGeometryName, [c_void_p]) -
django/contrib/gis/gdal/geometries.py
179 179 "Returns 0 for points, 1 for lines, and 2 for surfaces." 180 180 return capi.get_dims(self.ptr) 181 181 182 @property 183 def coord_dim(self): 182 def _get_coord_dim(self): 184 183 "Returns the coordinate dimension of the Geometry." 185 return capi.get_coord_dim s(self.ptr)184 return capi.get_coord_dim(self.ptr) 186 185 186 def _set_coord_dim(self, dim): 187 "Sets the coordinate dimension of this Geometry." 188 if not dim in (2, 3): 189 raise ValueError('Geometry dimension must be either 2 or 3') 190 capi.set_coord_dim(self.ptr, dim) 191 192 coord_dim = property(_get_coord_dim, _set_coord_dim) 193 187 194 @property 188 195 def geom_count(self): 189 196 "The number of elements in this Geometry."