Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] `OGRGeomType` now recognizes 2.5D types, and removes need for…

… unnecessary workaround in `Layer.geom_type`; corrected geometry type in test VRT file. Refs #11433.

Backport of r11739 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12877 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e53de431f26787a11a3b5e590fe2172e71f53811 1 parent 127d46e
Justin Bronn authored March 29, 2010
15  django/contrib/gis/gdal/geometries.py
@@ -214,13 +214,7 @@ def num_coords(self):
214 214
     @property
215 215
     def geom_type(self):
216 216
         "Returns the Type for this Geometry."
217  
-        try:
218  
-            return OGRGeomType(capi.get_geom_type(self.ptr))
219  
-        except OGRException:
220  
-            # VRT datasources return an invalid geometry type
221  
-            # number, but a valid name -- we'll try that instead.
222  
-            # See: http://trac.osgeo.org/gdal/ticket/2491
223  
-            return OGRGeomType(capi.get_geom_name(self.ptr))
  217
+        return OGRGeomType(capi.get_geom_type(self.ptr))
224 218
 
225 219
     @property
226 220
     def geom_name(self):
@@ -684,4 +678,11 @@ class MultiPolygon(GeometryCollection): pass
684 678
                6 : MultiPolygon,
685 679
                7 : GeometryCollection,
686 680
                101: LinearRing,
  681
+               1 + OGRGeomType.wkb25bit : Point,
  682
+               2 + OGRGeomType.wkb25bit : LineString,
  683
+               3 + OGRGeomType.wkb25bit : Polygon,
  684
+               4 + OGRGeomType.wkb25bit : MultiPoint,
  685
+               5 + OGRGeomType.wkb25bit : MultiLineString,
  686
+               6 + OGRGeomType.wkb25bit : MultiPolygon,
  687
+               7 + OGRGeomType.wkb25bit : GeometryCollection,
687 688
                }
11  django/contrib/gis/gdal/geomtype.py
@@ -4,6 +4,8 @@
4 4
 class OGRGeomType(object):
5 5
     "Encapulates OGR Geometry Types."
6 6
 
  7
+    wkb25bit = -2147483648
  8
+
7 9
     # Dictionary of acceptable OGRwkbGeometryType s and their string names.
8 10
     _types = {0 : 'Unknown',
9 11
               1 : 'Point',
@@ -15,6 +17,13 @@ class OGRGeomType(object):
15 17
               7 : 'GeometryCollection',
16 18
               100 : 'None',
17 19
               101 : 'LinearRing',
  20
+              1 + wkb25bit: 'Point25D',
  21
+              2 + wkb25bit: 'LineString25D',
  22
+              3 + wkb25bit: 'Polygon25D',
  23
+              4 + wkb25bit: 'MultiPoint25D',
  24
+              5 + wkb25bit : 'MultiLineString25D',
  25
+              6 + wkb25bit : 'MultiPolygon25D',
  26
+              7 + wkb25bit : 'GeometryCollection25D',
18 27
               }
19 28
     # Reverse type dictionary, keyed by lower-case of the name.
20 29
     _str_types = dict([(v.lower(), k) for k, v in _types.items()])
@@ -68,7 +77,7 @@ def name(self):
68 77
     @property
69 78
     def django(self):
70 79
         "Returns the Django GeometryField for this OGR Type."
71  
-        s = self.name
  80
+        s = self.name.replace('25D', '')
72 81
         if s in ('LinearRing', 'None'):
73 82
             return None
74 83
         elif s == 'Unknown':
2  django/contrib/gis/gdal/tests/test_ds.py
@@ -25,7 +25,7 @@ def __init__(self, name, **kwargs):
25 25
                   srs_wkt='GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]',
26 26
                   field_values={'dbl' : [float(i) for i in range(1, 6)], 'int' : range(1, 6), 'str' : [str(i) for i in range(1, 6)]},
27 27
                   fids=range(5)),
28  
-           TestDS('test_vrt', ext='vrt', nfeat=3, nfld=3, geom='POINT', gtype=1, driver='VRT',
  28
+           TestDS('test_vrt', ext='vrt', nfeat=3, nfld=3, geom='POINT', gtype='Point25D', driver='VRT',
29 29
                   fields={'POINT_X' : OFTString, 'POINT_Y' : OFTString, 'NUM' : OFTString}, # VRT uses CSV, which all types are OFTString.
30 30
                   extent=(1.0, 2.0, 100.0, 523.5), # Min/Max from CSV
31 31
                   field_values={'POINT_X' : ['1.0', '5.0', '100.0'], 'POINT_Y' : ['2.0', '23.0', '523.5'], 'NUM' : ['5', '17', '23']},
18  django/contrib/gis/gdal/tests/test_geom.py
@@ -46,6 +46,13 @@ def test00a_geomtype(self):
46 46
         self.assertEqual(0, gt.num)
47 47
         self.assertEqual('Unknown', gt.name)
48 48
 
  49
+    def test00b_geomtype_25d(self):
  50
+        "Testing OGRGeomType object with 25D types."
  51
+        wkb25bit = OGRGeomType.wkb25bit
  52
+        self.failUnless(OGRGeomType(wkb25bit + 1) == 'Point25D')
  53
+        self.failUnless(OGRGeomType('MultiLineString25D') == (5 + wkb25bit))
  54
+        self.assertEqual('GeometryCollectionField', OGRGeomType('GeometryCollection25D').django)
  55
+
49 56
     def test01a_wkt(self):
50 57
         "Testing WKT output."
51 58
         for g in wkt_out:
@@ -418,6 +425,17 @@ def test15_extent(self):
418 425
         xmax, ymax = max(x), max(y)
419 426
         self.assertEqual((xmin, ymin, xmax, ymax), poly.extent)
420 427
 
  428
+    def test16_25D(self):
  429
+        "Testing 2.5D geometries."
  430
+        pnt_25d = OGRGeometry('POINT(1 2 3)')
  431
+        self.assertEqual('Point25D', pnt_25d.geom_type.name)
  432
+        self.assertEqual(3.0, pnt_25d.z)
  433
+        self.assertEqual(3, pnt_25d.coord_dim)
  434
+        ls_25d = OGRGeometry('LINESTRING(1 1 1,2 2 2,3 3 3)')
  435
+        self.assertEqual('LineString25D', ls_25d.geom_type.name)
  436
+        self.assertEqual([1.0, 2.0, 3.0], ls_25d.z)
  437
+        self.assertEqual(3, ls_25d.coord_dim)
  438
+
421 439
 def suite():
422 440
     s = unittest.TestSuite()
423 441
     s.addTest(unittest.makeSuite(OGRGeomTest))
2  django/contrib/gis/tests/data/test_vrt/test_vrt.vrt
... ...
@@ -1,7 +1,7 @@
1 1
 <OGRVRTDataSource>
2 2
 <OGRVRTLayer name="test_vrt">
3 3
 <SrcDataSource relativeToVRT="1">test_vrt.csv</SrcDataSource>
4  
-<GeometryType>wkbPoint</GeometryType>
  4
+<GeometryType>wkbPoint25D</GeometryType>
5 5
 <GeometryField encoding="PointFromColumns" x="POINT_X" y="POINT_Y" z="NUM"/>
6 6
 </OGRVRTLayer>
7 7
 </OGRVRTDataSource>

0 notes on commit e53de43

Please sign in to comment.
Something went wrong with that request. Please try again.