`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.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11739 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
04f869a80c
commit
c169f8cb17
|
@ -214,13 +214,7 @@ class OGRGeometry(GDALBase):
|
||||||
@property
|
@property
|
||||||
def geom_type(self):
|
def geom_type(self):
|
||||||
"Returns the Type for this Geometry."
|
"Returns the Type for this Geometry."
|
||||||
try:
|
|
||||||
return OGRGeomType(capi.get_geom_type(self.ptr))
|
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))
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def geom_name(self):
|
def geom_name(self):
|
||||||
|
@ -684,4 +678,11 @@ GEO_CLASSES = {1 : Point,
|
||||||
6 : MultiPolygon,
|
6 : MultiPolygon,
|
||||||
7 : GeometryCollection,
|
7 : GeometryCollection,
|
||||||
101: LinearRing,
|
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,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ from django.contrib.gis.gdal.error import OGRException
|
||||||
class OGRGeomType(object):
|
class OGRGeomType(object):
|
||||||
"Encapulates OGR Geometry Types."
|
"Encapulates OGR Geometry Types."
|
||||||
|
|
||||||
|
wkb25bit = -2147483648
|
||||||
|
|
||||||
# Dictionary of acceptable OGRwkbGeometryType s and their string names.
|
# Dictionary of acceptable OGRwkbGeometryType s and their string names.
|
||||||
_types = {0 : 'Unknown',
|
_types = {0 : 'Unknown',
|
||||||
1 : 'Point',
|
1 : 'Point',
|
||||||
|
@ -15,6 +17,13 @@ class OGRGeomType(object):
|
||||||
7 : 'GeometryCollection',
|
7 : 'GeometryCollection',
|
||||||
100 : 'None',
|
100 : 'None',
|
||||||
101 : 'LinearRing',
|
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.
|
# Reverse type dictionary, keyed by lower-case of the name.
|
||||||
_str_types = dict([(v.lower(), k) for k, v in _types.items()])
|
_str_types = dict([(v.lower(), k) for k, v in _types.items()])
|
||||||
|
@ -68,7 +77,7 @@ class OGRGeomType(object):
|
||||||
@property
|
@property
|
||||||
def django(self):
|
def django(self):
|
||||||
"Returns the Django GeometryField for this OGR Type."
|
"Returns the Django GeometryField for this OGR Type."
|
||||||
s = self.name
|
s = self.name.replace('25D', '')
|
||||||
if s in ('LinearRing', 'None'):
|
if s in ('LinearRing', 'None'):
|
||||||
return None
|
return None
|
||||||
elif s == 'Unknown':
|
elif s == 'Unknown':
|
||||||
|
|
|
@ -23,7 +23,7 @@ ds_list = (TestDS('test_point', nfeat=5, nfld=3, geom='POINT', gtype=1, driver='
|
||||||
srs_wkt='GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]',
|
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)]},
|
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)),
|
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.
|
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
|
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']},
|
field_values={'POINT_X' : ['1.0', '5.0', '100.0'], 'POINT_Y' : ['2.0', '23.0', '523.5'], 'NUM' : ['5', '17', '23']},
|
||||||
|
|
|
@ -46,6 +46,13 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
self.assertEqual(0, gt.num)
|
self.assertEqual(0, gt.num)
|
||||||
self.assertEqual('Unknown', gt.name)
|
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):
|
def test01a_wkt(self):
|
||||||
"Testing WKT output."
|
"Testing WKT output."
|
||||||
for g in wkt_out:
|
for g in wkt_out:
|
||||||
|
@ -418,6 +425,17 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
xmax, ymax = max(x), max(y)
|
xmax, ymax = max(x), max(y)
|
||||||
self.assertEqual((xmin, ymin, xmax, ymax), poly.extent)
|
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():
|
def suite():
|
||||||
s = unittest.TestSuite()
|
s = unittest.TestSuite()
|
||||||
s.addTest(unittest.makeSuite(OGRGeomTest))
|
s.addTest(unittest.makeSuite(OGRGeomTest))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<OGRVRTDataSource>
|
<OGRVRTDataSource>
|
||||||
<OGRVRTLayer name="test_vrt">
|
<OGRVRTLayer name="test_vrt">
|
||||||
<SrcDataSource relativeToVRT="1">test_vrt.csv</SrcDataSource>
|
<SrcDataSource relativeToVRT="1">test_vrt.csv</SrcDataSource>
|
||||||
<GeometryType>wkbPoint</GeometryType>
|
<GeometryType>wkbPoint25D</GeometryType>
|
||||||
<GeometryField encoding="PointFromColumns" x="POINT_X" y="POINT_Y" z="NUM"/>
|
<GeometryField encoding="PointFromColumns" x="POINT_X" y="POINT_Y" z="NUM"/>
|
||||||
</OGRVRTLayer>
|
</OGRVRTLayer>
|
||||||
</OGRVRTDataSource>
|
</OGRVRTDataSource>
|
Loading…
Reference in New Issue