Skip to content

Commit 8c7ca62

Browse files
committedOct 27, 2016
[DBManager GPKG] Set appropriate icon for line layers
1 parent bf6607f commit 8c7ca62

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed
 

‎python/plugins/db_manager/db_model.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ def icon(self):
254254
if geom_type is not None:
255255
if geom_type.find('POINT') != -1:
256256
return self.layerPointIcon
257-
elif geom_type.find('LINESTRING') != -1:
257+
elif geom_type.find('LINESTRING') != -1 or geom_type in ('CIRCULARSTRING', 'COMPOUNDCURVE', 'MULTICURVE'):
258258
return self.layerLineIcon
259-
elif geom_type.find('POLYGON') != -1:
259+
elif geom_type.find('POLYGON') != -1 or geom_type == 'MULTISURFACE':
260260
return self.layerPolygonIcon
261261
return self.layerUnknownIcon
262262

‎python/plugins/db_manager/db_plugins/gpkg/connector.py‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,31 @@ def getVectorTables(self, schema=None):
299299
geomtype_flatten = ogr.GT_Flatten(geomtype)
300300
else:
301301
geomtype_flatten = geomtype
302-
geomname = ogr.GeometryTypeToName(geomtype_flatten).upper()
302+
if geomtype_flatten == ogr.wkbPoint:
303+
geomname = 'POINT'
304+
elif geomtype_flatten == ogr.wkbLineString:
305+
geomname = 'LINESTRING'
306+
elif geomtype_flatten == ogr.wkbPolygon:
307+
geomname = 'POLYGON'
308+
elif geomtype_flatten == ogr.wkbMultiPoint:
309+
geomname = 'MULTIPOINT'
310+
elif geomtype_flatten == ogr.wkbMultiLineString:
311+
geomname = 'MULTILINESTRING'
312+
elif geomtype_flatten == ogr.wkbMultiPolygon:
313+
geomname = 'MULTIPOLYGON'
314+
elif geomtype_flatten == ogr.wkbGeometryCollection:
315+
geomname = 'GEOMETRYCOLLECTION'
316+
if self.gdal2:
317+
if geomtype_flatten == ogr.wkbCircularString:
318+
geomname = 'CIRCULARSTRING'
319+
elif geomtype_flatten == ogr.wkbCompoundCurve:
320+
geomname = 'COMPOUNDCURVE'
321+
elif geomtype_flatten == ogr.wkbCurvePolygon:
322+
geomname = 'CURVEPOLYGON'
323+
elif geomtype_flatten == ogr.wkbMultiCurve:
324+
geomname = 'MULTICURVE'
325+
elif geomtype_flatten == ogr.wkbMultiSurface:
326+
geomname = 'MULTISURFACE'
303327
geomdim = 'XY'
304328
if hasattr(ogr, 'GT_HasZ') and ogr.GT_HasZ(lyr.GetGeomType()):
305329
geomdim += 'Z'

‎tests/src/python/test_db_manager_gpkg.py‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def testListLayer(self):
127127
table = tables[0]
128128
self.assertEqual(table.name, 'testLayer')
129129
info = table.info()
130-
expected_html = """<div class="section"><h2>General info</h2><div><table><tr><td>Relation type:&nbsp;</td><td>Table&nbsp;</td></tr><tr><td>Rows:&nbsp;</td><td>1&nbsp;</td></tr></table></div></div><div class="section"><h2>GeoPackage</h2><div><table><tr><td>Column:&nbsp;</td><td>geom&nbsp;</td></tr><tr><td>Geometry:&nbsp;</td><td>LINE STRING&nbsp;</td></tr><tr><td>Dimension:&nbsp;</td><td>XY&nbsp;</td></tr><tr><td>Spatial ref:&nbsp;</td><td>Undefined (-1)&nbsp;</td></tr><tr><td>Extent:&nbsp;</td><td>1.00000, 2.00000 - 3.00000, 4.00000&nbsp;</td></tr></table><p><warning> No spatial index defined (<a href="action:spatialindex/create">create it</a>)</p></div></div><div class="section"><h2>Fields</h2><div><table class="header"><tr><th>#&nbsp;</th><th>Name&nbsp;</th><th>Type&nbsp;</th><th>Null&nbsp;</th><th>Default&nbsp;</th></tr><tr><td>0&nbsp;</td><td class="underline">fid&nbsp;</td><td>INTEGER&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr><tr><td>1&nbsp;</td><td>geom&nbsp;</td><td>LINESTRING&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr><tr><td>2&nbsp;</td><td>text_field&nbsp;</td><td>TEXT&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr></table></div></div>"""
130+
expected_html = """<div class="section"><h2>General info</h2><div><table><tr><td>Relation type:&nbsp;</td><td>Table&nbsp;</td></tr><tr><td>Rows:&nbsp;</td><td>1&nbsp;</td></tr></table></div></div><div class="section"><h2>GeoPackage</h2><div><table><tr><td>Column:&nbsp;</td><td>geom&nbsp;</td></tr><tr><td>Geometry:&nbsp;</td><td>LINESTRING&nbsp;</td></tr><tr><td>Dimension:&nbsp;</td><td>XY&nbsp;</td></tr><tr><td>Spatial ref:&nbsp;</td><td>Undefined (-1)&nbsp;</td></tr><tr><td>Extent:&nbsp;</td><td>1.00000, 2.00000 - 3.00000, 4.00000&nbsp;</td></tr></table><p><warning> No spatial index defined (<a href="action:spatialindex/create">create it</a>)</p></div></div><div class="section"><h2>Fields</h2><div><table class="header"><tr><th>#&nbsp;</th><th>Name&nbsp;</th><th>Type&nbsp;</th><th>Null&nbsp;</th><th>Default&nbsp;</th></tr><tr><td>0&nbsp;</td><td class="underline">fid&nbsp;</td><td>INTEGER&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr><tr><td>1&nbsp;</td><td>geom&nbsp;</td><td>LINESTRING&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr><tr><td>2&nbsp;</td><td>text_field&nbsp;</td><td>TEXT&nbsp;</td><td>Y&nbsp;</td><td>&nbsp;</td></tr></table></div></div>"""
131131
self.assertEqual(info.toHtml(), expected_html, info.toHtml())
132132

133133
connection.remove()
@@ -389,5 +389,45 @@ def testNonSpatial(self):
389389

390390
connection.remove()
391391

392+
def testAllGeometryTypes(self):
393+
394+
connection_name = 'testAllGeometryTypes'
395+
plugin = createDbPlugin('gpkg')
396+
uri = QgsDataSourceURI()
397+
398+
test_gpkg = os.path.join(self.basetestpath, 'testAllGeometryTypes.gpkg')
399+
ds = ogr.GetDriverByName('GPKG').CreateDataSource(test_gpkg)
400+
ds.CreateLayer('testPoint', geom_type=ogr.wkbPoint)
401+
ds.CreateLayer('testLineString', geom_type=ogr.wkbLineString)
402+
ds.CreateLayer('testPolygon', geom_type=ogr.wkbPolygon)
403+
ds.CreateLayer('testMultiPoint', geom_type=ogr.wkbMultiPoint)
404+
ds.CreateLayer('testMultiLineString', geom_type=ogr.wkbMultiLineString)
405+
ds.CreateLayer('testMultiPolygon', geom_type=ogr.wkbMultiPolygon)
406+
ds.CreateLayer('testGeometryCollection', geom_type=ogr.wkbGeometryCollection)
407+
408+
if int(gdal.VersionInfo('VERSION_NUM')) >= GDAL_COMPUTE_VERSION(2, 0, 0):
409+
ds.CreateLayer('testCircularString', geom_type=ogr.wkbCircularString)
410+
ds.CreateLayer('testCompoundCurve', geom_type=ogr.wkbCompoundCurve)
411+
ds.CreateLayer('testCurvePolygon', geom_type=ogr.wkbCurvePolygon)
412+
ds.CreateLayer('testMultiCurve', geom_type=ogr.wkbMultiCurve)
413+
ds.CreateLayer('testMultiSurface', geom_type=ogr.wkbMultiSurface)
414+
ds = None
415+
416+
uri.setDatabase(test_gpkg)
417+
self.assertTrue(plugin.addConnection(connection_name, uri))
418+
419+
connection = createDbPlugin('gpkg', connection_name)
420+
connection.connect()
421+
422+
db = connection.database()
423+
self.assertIsNotNone(db)
424+
425+
tables = db.tables()
426+
for i in range(len(tables)):
427+
table = tables[i]
428+
info = table.info()
429+
430+
connection.remove()
431+
392432
if __name__ == '__main__':
393433
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.