Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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
@jbronn jbronn authored
View
15 django/contrib/gis/gdal/geometries.py
@@ -214,13 +214,7 @@ def num_coords(self):
@property
def geom_type(self):
"Returns the Type for this Geometry."
- try:
- return OGRGeomType(capi.get_geom_type(self.ptr))
- except OGRException:
- # VRT datasources return an invalid geometry type
- # number, but a valid name -- we'll try that instead.
- # See: http://trac.osgeo.org/gdal/ticket/2491
- return OGRGeomType(capi.get_geom_name(self.ptr))
+ return OGRGeomType(capi.get_geom_type(self.ptr))
@property
def geom_name(self):
@@ -684,4 +678,11 @@ class MultiPolygon(GeometryCollection): pass
6 : MultiPolygon,
7 : GeometryCollection,
101: LinearRing,
+ 1 + OGRGeomType.wkb25bit : Point,
+ 2 + OGRGeomType.wkb25bit : LineString,
+ 3 + OGRGeomType.wkb25bit : Polygon,
+ 4 + OGRGeomType.wkb25bit : MultiPoint,
+ 5 + OGRGeomType.wkb25bit : MultiLineString,
+ 6 + OGRGeomType.wkb25bit : MultiPolygon,
+ 7 + OGRGeomType.wkb25bit : GeometryCollection,
}
View
11 django/contrib/gis/gdal/geomtype.py
@@ -4,6 +4,8 @@
class OGRGeomType(object):
"Encapulates OGR Geometry Types."
+ wkb25bit = -2147483648
+
# Dictionary of acceptable OGRwkbGeometryType s and their string names.
_types = {0 : 'Unknown',
1 : 'Point',
@@ -15,6 +17,13 @@ class OGRGeomType(object):
7 : 'GeometryCollection',
100 : 'None',
101 : 'LinearRing',
+ 1 + wkb25bit: 'Point25D',
+ 2 + wkb25bit: 'LineString25D',
+ 3 + wkb25bit: 'Polygon25D',
+ 4 + wkb25bit: 'MultiPoint25D',
+ 5 + wkb25bit : 'MultiLineString25D',
+ 6 + wkb25bit : 'MultiPolygon25D',
+ 7 + wkb25bit : 'GeometryCollection25D',
}
# Reverse type dictionary, keyed by lower-case of the name.
_str_types = dict([(v.lower(), k) for k, v in _types.items()])
@@ -68,7 +77,7 @@ def name(self):
@property
def django(self):
"Returns the Django GeometryField for this OGR Type."
- s = self.name
+ s = self.name.replace('25D', '')
if s in ('LinearRing', 'None'):
return None
elif s == 'Unknown':
View
2  django/contrib/gis/gdal/tests/test_ds.py
@@ -25,7 +25,7 @@ def __init__(self, name, **kwargs):
srs_wkt='GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]',
field_values={'dbl' : [float(i) for i in range(1, 6)], 'int' : range(1, 6), 'str' : [str(i) for i in range(1, 6)]},
fids=range(5)),
- TestDS('test_vrt', ext='vrt', nfeat=3, nfld=3, geom='POINT', gtype=1, driver='VRT',
+ TestDS('test_vrt', ext='vrt', nfeat=3, nfld=3, geom='POINT', gtype='Point25D', driver='VRT',
fields={'POINT_X' : OFTString, 'POINT_Y' : OFTString, 'NUM' : OFTString}, # VRT uses CSV, which all types are OFTString.
extent=(1.0, 2.0, 100.0, 523.5), # Min/Max from CSV
field_values={'POINT_X' : ['1.0', '5.0', '100.0'], 'POINT_Y' : ['2.0', '23.0', '523.5'], 'NUM' : ['5', '17', '23']},
View
18 django/contrib/gis/gdal/tests/test_geom.py
@@ -46,6 +46,13 @@ def test00a_geomtype(self):
self.assertEqual(0, gt.num)
self.assertEqual('Unknown', gt.name)
+ def test00b_geomtype_25d(self):
+ "Testing OGRGeomType object with 25D types."
+ wkb25bit = OGRGeomType.wkb25bit
+ self.failUnless(OGRGeomType(wkb25bit + 1) == 'Point25D')
+ self.failUnless(OGRGeomType('MultiLineString25D') == (5 + wkb25bit))
+ self.assertEqual('GeometryCollectionField', OGRGeomType('GeometryCollection25D').django)
+
def test01a_wkt(self):
"Testing WKT output."
for g in wkt_out:
@@ -418,6 +425,17 @@ def test15_extent(self):
xmax, ymax = max(x), max(y)
self.assertEqual((xmin, ymin, xmax, ymax), poly.extent)
+ def test16_25D(self):
+ "Testing 2.5D geometries."
+ pnt_25d = OGRGeometry('POINT(1 2 3)')
+ self.assertEqual('Point25D', pnt_25d.geom_type.name)
+ self.assertEqual(3.0, pnt_25d.z)
+ self.assertEqual(3, pnt_25d.coord_dim)
+ ls_25d = OGRGeometry('LINESTRING(1 1 1,2 2 2,3 3 3)')
+ self.assertEqual('LineString25D', ls_25d.geom_type.name)
+ self.assertEqual([1.0, 2.0, 3.0], ls_25d.z)
+ self.assertEqual(3, ls_25d.coord_dim)
+
def suite():
s = unittest.TestSuite()
s.addTest(unittest.makeSuite(OGRGeomTest))
View
2  django/contrib/gis/tests/data/test_vrt/test_vrt.vrt
@@ -1,7 +1,7 @@
<OGRVRTDataSource>
<OGRVRTLayer name="test_vrt">
<SrcDataSource relativeToVRT="1">test_vrt.csv</SrcDataSource>
-<GeometryType>wkbPoint</GeometryType>
+<GeometryType>wkbPoint25D</GeometryType>
<GeometryField encoding="PointFromColumns" x="POINT_X" y="POINT_Y" z="NUM"/>
</OGRVRTLayer>
</OGRVRTDataSource>
Please sign in to comment.
Something went wrong with that request. Please try again.