Skip to content
Permalink
Browse files
Pass extent of loaded views to the provider via URI
Completes the speed up loading of view layers in TopoViewer.
Finally and definitely fixes #9510.

NOTE: the commit also adds a layer for face's MBR, which serves
the purpose (among others) to allow for easy computing extent.
  • Loading branch information
Sandro Santilli committed Feb 8, 2014
1 parent 4c87b0c commit 02409e9901356e07ef1f4e56c74d1685bc62e0ae
@@ -201,25 +201,16 @@ def sqlResultModel(self, sql, parent):
from .data_model import SqlResultModel
return SqlResultModel(self, sql, parent)

def toSqlLayer(self, sql, geomCol, uniqueCol, layerName="QueryLayer", layerType=None, avoidSelectById=False, srid=None, wkbType=None):
def toSqlLayer(self, sql, geomCol, uniqueCol, layerName="QueryLayer", layerType=None, avoidSelectById=False):
from qgis.core import QgsMapLayer, QgsVectorLayer, QgsRasterLayer
uri = self.uri()
uri.setDataSource("", u"(%s\n)" % sql, geomCol, "", uniqueCol)
if avoidSelectById:
uri.disableSelectAtId( True )
if srid != None:
print "SRID is not none but %s" % srid
uri.setSrid( srid )
if wkbType != None:
print "WkbType is not none but %s" % wkbType
uri.setWkbType( wkbType )
provider = self.dbplugin().providerName()
if layerType == QgsMapLayer.RasterLayer:
return QgsRasterLayer(uri.uri(), layerName, provider)
print "Creating vector layer -- start, with uri: %s" % uri.uri()
layer = QgsVectorLayer(uri.uri(), layerName, provider)
print "Creating vector layer -- done"
return layer
return QgsVectorLayer(uri.uri(), layerName, provider)

def registerAllActions(self, mainWindow):
self.registerDatabaseActions(mainWindow)
@@ -82,7 +82,7 @@ def run(item, action, mainwindow):
QMessageBox.critical(mainwindow, "Invalid topology", u'Schema "%s" is not registered in topology.topology.' % item.schema().name)
return False

toposrid = res[0]
toposrid = str(res[0])

# load layers into the current project
toponame = item.schema().name
@@ -106,20 +106,40 @@ def run(item, action, mainwindow):
# should not be needed: http://hub.qgis.org/issues/6938
legend.setGroupVisible(group, False)

# face
layer = db.toSqlLayer(u'SELECT face_id, topology.ST_GetFaceGeometry(%s, face_id) as geom ' \
'FROM %s.face WHERE face_id > 0' % (quoteStr(toponame), quoteId(toponame)),
'geom', 'face_id', u'%s.face' % toponame, None, False, str(toposrid), QGis.WKBPolygon)
# face mbr
uri.setDataSource(toponame, 'face', 'mbr', '', 'face_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBPolygon )
layer = QgsVectorLayer(uri.uri(), u'%s.face_mbr' % toponame, provider)
layer.loadNamedStyle(os.path.join(template_dir, 'face_mbr.qml'))
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
legend.setLayerExpanded(layer, False)
legend.moveLayer(layer, group)
face_extent = layer.extent()

# face geometry
sql = u'SELECT face_id, topology.ST_GetFaceGeometry(%s, face_id) as geom ' \
'FROM %s.face WHERE face_id > 0' % (quoteStr(toponame), quoteId(toponame))
uri.setDataSource('', u'(%s\n)' % sql, 'geom', '', 'face_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBPolygon )
layer = QgsVectorLayer(uri.uri(), u'%s.face' % toponame, provider)
layer.setExtent(face_extent)
layer.loadNamedStyle(os.path.join(template_dir, 'face.qml'))
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
legend.setLayerExpanded(layer, False)
legend.moveLayer(layer, group)

# face_seed
layer = db.toSqlLayer(u'SELECT face_id, ST_PointOnSurface(topology.ST_GetFaceGeometry(%s, face_id)) as geom ' \
'FROM %s.face WHERE face_id > 0' % (quoteStr(toponame), quoteId(toponame)),
'geom', 'face_id', u'%s.face_seed' % toponame, None, False, str(toposrid), QGis.WKBPoint)
sql = u'SELECT face_id, ST_PointOnSurface(topology.ST_GetFaceGeometry(%s, face_id)) as geom ' \
'FROM %s.face WHERE face_id > 0' % (quoteStr(toponame), quoteId(toponame))
uri.setDataSource('', u'(%s)' % sql, 'geom', '', 'face_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBPolygon )
layer = QgsVectorLayer(uri.uri(), u'%s.face_seed' % toponame, provider)
layer.setExtent(face_extent)
layer.loadNamedStyle(os.path.join(template_dir, 'face_seed.qml'))
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
@@ -136,16 +156,22 @@ def run(item, action, mainwindow):

# node
uri.setDataSource(toponame, 'node', 'geom', '', 'node_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBPoint )
layer = QgsVectorLayer(uri.uri(), u'%s.node' % toponame, provider)
layer.loadNamedStyle(os.path.join(template_dir, 'node.qml'))
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
legend.setLayerExpanded(layer, False)
legend.moveLayer(layer, group)
node_extent = layer.extent()

# node labels
uri.setDataSource(toponame, 'node', 'geom', '', 'node_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBPoint )
layer = QgsVectorLayer(uri.uri(), u'%s.node_id' % toponame, provider)
layer.setExtent(node_extent)
layer.loadNamedStyle(os.path.join(template_dir, 'node_label.qml'))
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
@@ -159,15 +185,21 @@ def run(item, action, mainwindow):

# edge
uri.setDataSource(toponame, 'edge_data', 'geom', '', 'edge_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBLineString )
layer = QgsVectorLayer(uri.uri(), u'%s.edge' % toponame, provider)
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
legend.setLayerExpanded(layer, False)
legend.moveLayer(layer, group)
edge_extent = layer.extent()

# directed edge
uri.setDataSource(toponame, 'edge_data', 'geom', '', 'edge_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBLineString )
layer = QgsVectorLayer(uri.uri(), u'%s.directed_edge' % toponame, provider)
layer.setExtent(edge_extent)
layer.loadNamedStyle(os.path.join(template_dir, 'edge.qml'))
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
@@ -177,7 +209,10 @@ def run(item, action, mainwindow):

# edge labels
uri.setDataSource(toponame, 'edge_data', 'geom', '', 'edge_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBLineString )
layer = QgsVectorLayer(uri.uri(), u'%s.edge_id' % toponame, provider)
layer.setExtent(edge_extent)
layer.loadNamedStyle(os.path.join(template_dir, 'edge_label.qml'))
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
@@ -186,7 +221,10 @@ def run(item, action, mainwindow):

# face_left
uri.setDataSource(toponame, 'edge_data', 'geom', '', 'edge_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBLineString )
layer = QgsVectorLayer(uri.uri(), u'%s.face_left' % toponame, provider)
layer.setExtent(edge_extent)
layer.loadNamedStyle(os.path.join(template_dir, 'face_left.qml'))
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
@@ -195,7 +233,10 @@ def run(item, action, mainwindow):

# face_right
uri.setDataSource(toponame, 'edge_data', 'geom', '', 'edge_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBLineString )
layer = QgsVectorLayer(uri.uri(), u'%s.face_right' % toponame, provider)
layer.setExtent(edge_extent)
layer.loadNamedStyle(os.path.join(template_dir, 'face_right.qml'))
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
@@ -204,7 +245,10 @@ def run(item, action, mainwindow):

# next_left
uri.setDataSource(toponame, 'edge_data', 'geom', '', 'edge_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBLineString )
layer = QgsVectorLayer(uri.uri(), u'%s.next_left' % toponame, provider)
layer.setExtent(edge_extent)
layer.loadNamedStyle(os.path.join(template_dir, 'next_left.qml'))
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
@@ -213,7 +257,10 @@ def run(item, action, mainwindow):

# next_right
uri.setDataSource(toponame, 'edge_data', 'geom', '', 'edge_id')
uri.setSrid( toposrid )
uri.setWkbType( QGis.WKBLineString )
layer = QgsVectorLayer(uri.uri(), u'%s.next_right' % toponame, provider)
layer.setExtent(edge_extent)
layer.loadNamedStyle(os.path.join(template_dir, 'next_right.qml'))
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
@@ -0,0 +1,177 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis version="2.1.0-Master" minimumScale="-4.65661e-10" maximumScale="1e+08" simplifyDrawingHints="1" minLabelScale="1" maxLabelScale="1e+08" simplifyDrawingTol="1" simplifyMaxScale="1" hasScaleBasedVisibilityFlag="0" simplifyLocal="1" scaleBasedLabelVisibilityFlag="0">
<renderer-v2 symbollevels="0" type="singleSymbol">
<symbols>
<symbol alpha="0.396078" type="fill" name="0">
<layer pass="0" class="SimpleFill" locked="0">
<prop k="border_width_unit" v="MM"/>
<prop k="color" v="170,170,170,255"/>
<prop k="color_border" v="0,0,0,255"/>
<prop k="offset" v="0,0"/>
<prop k="offset_unit" v="MM"/>
<prop k="style" v="solid"/>
<prop k="style_border" v="solid"/>
<prop k="width_border" v="0.26"/>
</layer>
</symbol>
</symbols>
<rotation/>
<sizescale scalemethod="area"/>
</renderer-v2>
<customproperties>
<property key="labeling" value="pal"/>
<property key="labeling/addDirectionSymbol" value="false"/>
<property key="labeling/angleOffset" value="0"/>
<property key="labeling/blendMode" value="0"/>
<property key="labeling/bufferBlendMode" value="0"/>
<property key="labeling/bufferColorA" value="255"/>
<property key="labeling/bufferColorB" value="255"/>
<property key="labeling/bufferColorG" value="255"/>
<property key="labeling/bufferColorR" value="255"/>
<property key="labeling/bufferDraw" value="true"/>
<property key="labeling/bufferJoinStyle" value="64"/>
<property key="labeling/bufferNoFill" value="false"/>
<property key="labeling/bufferSize" value="1"/>
<property key="labeling/bufferSizeInMapUnits" value="false"/>
<property key="labeling/bufferTransp" value="0"/>
<property key="labeling/centroidWhole" value="false"/>
<property key="labeling/decimals" value="0"/>
<property key="labeling/displayAll" value="false"/>
<property key="labeling/dist" value="0"/>
<property key="labeling/distInMapUnits" value="false"/>
<property key="labeling/enabled" value="false"/>
<property key="labeling/fieldName" value="face_id"/>
<property key="labeling/fontBold" value="false"/>
<property key="labeling/fontCapitals" value="0"/>
<property key="labeling/fontFamily" value="DejaVu Sans"/>
<property key="labeling/fontItalic" value="false"/>
<property key="labeling/fontLetterSpacing" value="0"/>
<property key="labeling/fontLimitPixelSize" value="false"/>
<property key="labeling/fontMaxPixelSize" value="10000"/>
<property key="labeling/fontMinPixelSize" value="3"/>
<property key="labeling/fontSize" value="8"/>
<property key="labeling/fontSizeInMapUnits" value="false"/>
<property key="labeling/fontStrikeout" value="false"/>
<property key="labeling/fontUnderline" value="false"/>
<property key="labeling/fontWeight" value="50"/>
<property key="labeling/fontWordSpacing" value="0"/>
<property key="labeling/formatNumbers" value="false"/>
<property key="labeling/isExpression" value="false"/>
<property key="labeling/labelOffsetInMapUnits" value="true"/>
<property key="labeling/labelPerPart" value="false"/>
<property key="labeling/leftDirectionSymbol" value="&lt;"/>
<property key="labeling/limitNumLabels" value="false"/>
<property key="labeling/maxCurvedCharAngleIn" value="20"/>
<property key="labeling/maxCurvedCharAngleOut" value="-20"/>
<property key="labeling/maxNumLabels" value="2000"/>
<property key="labeling/mergeLines" value="false"/>
<property key="labeling/minFeatureSize" value="0"/>
<property key="labeling/multilineAlign" value="0"/>
<property key="labeling/multilineHeight" value="1"/>
<property key="labeling/namedStyle" value="Condensed"/>
<property key="labeling/obstacle" value="true"/>
<property key="labeling/placeDirectionSymbol" value="0"/>
<property key="labeling/placement" value="0"/>
<property key="labeling/placementFlags" value="0"/>
<property key="labeling/plussign" value="false"/>
<property key="labeling/preserveRotation" value="true"/>
<property key="labeling/previewBkgrdColor" value="#ffffff"/>
<property key="labeling/priority" value="5"/>
<property key="labeling/quadOffset" value="4"/>
<property key="labeling/reverseDirectionSymbol" value="false"/>
<property key="labeling/rightDirectionSymbol" value=">"/>
<property key="labeling/scaleMax" value="10000000"/>
<property key="labeling/scaleMin" value="1"/>
<property key="labeling/scaleVisibility" value="false"/>
<property key="labeling/shadowBlendMode" value="6"/>
<property key="labeling/shadowColorB" value="0"/>
<property key="labeling/shadowColorG" value="0"/>
<property key="labeling/shadowColorR" value="0"/>
<property key="labeling/shadowDraw" value="false"/>
<property key="labeling/shadowOffsetAngle" value="135"/>
<property key="labeling/shadowOffsetDist" value="1"/>
<property key="labeling/shadowOffsetGlobal" value="true"/>
<property key="labeling/shadowOffsetUnits" value="1"/>
<property key="labeling/shadowRadius" value="1.5"/>
<property key="labeling/shadowRadiusAlphaOnly" value="false"/>
<property key="labeling/shadowRadiusUnits" value="1"/>
<property key="labeling/shadowScale" value="100"/>
<property key="labeling/shadowTransparency" value="30"/>
<property key="labeling/shadowUnder" value="0"/>
<property key="labeling/shapeBlendMode" value="0"/>
<property key="labeling/shapeBorderColorA" value="255"/>
<property key="labeling/shapeBorderColorB" value="128"/>
<property key="labeling/shapeBorderColorG" value="128"/>
<property key="labeling/shapeBorderColorR" value="128"/>
<property key="labeling/shapeBorderWidth" value="0"/>
<property key="labeling/shapeBorderWidthUnits" value="1"/>
<property key="labeling/shapeDraw" value="false"/>
<property key="labeling/shapeFillColorA" value="255"/>
<property key="labeling/shapeFillColorB" value="255"/>
<property key="labeling/shapeFillColorG" value="255"/>
<property key="labeling/shapeFillColorR" value="255"/>
<property key="labeling/shapeJoinStyle" value="64"/>
<property key="labeling/shapeOffsetUnits" value="1"/>
<property key="labeling/shapeOffsetX" value="0"/>
<property key="labeling/shapeOffsetY" value="0"/>
<property key="labeling/shapeRadiiUnits" value="1"/>
<property key="labeling/shapeRadiiX" value="0"/>
<property key="labeling/shapeRadiiY" value="0"/>
<property key="labeling/shapeRotation" value="0"/>
<property key="labeling/shapeRotationType" value="0"/>
<property key="labeling/shapeSVGFile" value=""/>
<property key="labeling/shapeSizeType" value="0"/>
<property key="labeling/shapeSizeUnits" value="1"/>
<property key="labeling/shapeSizeX" value="0"/>
<property key="labeling/shapeSizeY" value="0"/>
<property key="labeling/shapeTransparency" value="0"/>
<property key="labeling/shapeType" value="0"/>
<property key="labeling/textColorA" value="255"/>
<property key="labeling/textColorB" value="0"/>
<property key="labeling/textColorG" value="0"/>
<property key="labeling/textColorR" value="170"/>
<property key="labeling/textTransp" value="0"/>
<property key="labeling/upsidedownLabels" value="0"/>
<property key="labeling/wrapChar" value=""/>
<property key="labeling/xOffset" value="0"/>
<property key="labeling/xQuadOffset" value="0"/>
<property key="labeling/yOffset" value="0"/>
<property key="labeling/yQuadOffset" value="0"/>
</customproperties>
<blendMode>0</blendMode>
<featureBlendMode>0</featureBlendMode>
<layerTransparency>0</layerTransparency>
<displayfield>face_id</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Label"/>
<family fieldname="" name="DejaVu Sans"/>
<size fieldname="" units="pt" value="12"/>
<bold fieldname="" on="0"/>
<italic fieldname="" on="0"/>
<underline fieldname="" on="0"/>
<strikeout fieldname="" on="0"/>
<color fieldname="" red="0" blue="0" green="0"/>
<x fieldname=""/>
<y fieldname=""/>
<offset x="0" y="0" units="pt" yfieldname="" xfieldname=""/>
<angle fieldname="" value="0" auto="0"/>
<alignment fieldname="" value="center"/>
<buffercolor fieldname="" red="255" blue="255" green="255"/>
<buffersize fieldname="" units="pt" value="1"/>
<bufferenabled fieldname="" on=""/>
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<edittypes>
<edittype labelontop="0" editable="1" type="0" name="face_id"/>
</edittypes>
<editform></editform>
<editforminit></editforminit>
<featformsuppress>0</featformsuppress>
<annotationform></annotationform>
<editorlayout>generatedlayout</editorlayout>
<excludeAttributesWMS/>
<excludeAttributesWFS/>
<attributeactions/>
</qgis>

0 comments on commit 02409e9

Please sign in to comment.