Ejemplo n.º 1
0
 def _loadLogLayer(self, sourceLayer, layerPath, layerName):
     layer = None
     layerId = ''
     layerList = QgsMapLayerRegistry.instance().mapLayersByName(layerName)
     if (len(layerList) > 0):
         layer = layerList[0]
         self._iface.legendInterface().moveLayer(layer, self._bufferGroupIndex)
     else:
         fullLayerPath = self.projectPath + '/' + layerPath
         if (layerName and layerPath and sourceLayer and sourceLayer.isValid()):
             if not QFile.exists(fullLayerPath):
                 # If the layer doesn't exist, clone from the source layer
                 layer = layers.cloneAsShapefile(sourceLayer, fullLayerPath, layerName)
                 if layer and layer.isValid():
                     layer.dataProvider().addAttributes([QgsField('timestamp', QVariant.String, '', 10, 0, 'timestamp')])
                     layer.dataProvider().addAttributes([QgsField('event', QVariant.String, '', 6, 0, 'event')])
             else:
                 # If the layer does exist, then load it and copy the style
                 layer = QgsVectorLayer(fullLayerPath, layerName, 'ogr')
                 if layer and layer.isValid():
                     layers.loadStyle(layer, fromLayer=sourceLayer)
     if layer and layer.isValid():
         layerId = layer.id()
         layer.setFeatureFormSuppress(QgsVectorLayer.SuppressOn)
         self._iface.legendInterface().setLayerExpanded(layer, False)
     else:
         layer = None
     return layer, layerId
Ejemplo n.º 2
0
 def _loadBufferLayer(self, sourceLayer, layerPath, layerName):
     layer = None
     layerId = ''
     layerList = QgsMapLayerRegistry.instance().mapLayersByName(layerName)
     if (len(layerList) > 0):
         layer = layerList[0]
         self._iface.legendInterface().moveLayer(layer,
                                                 self._bufferGroupIndex)
     else:
         fullLayerPath = self.projectPath + '/' + layerPath
         if (layerName and layerPath and sourceLayer
                 and sourceLayer.isValid()):
             if not QFile.exists(fullLayerPath):
                 # If the layer doesn't exist, clone from the source layer
                 layer = layers.cloneAsShapefile(sourceLayer, fullLayerPath,
                                                 layerName)
             else:
                 # If the layer does exist, then load it and copy the style
                 layer = QgsVectorLayer(fullLayerPath, layerName, 'ogr')
             layer = layers.addLayerToLegend(self._iface, layer,
                                             self._bufferGroupIndex)
     if layer and layer.isValid():
         layerId = layer.id()
         layers.loadStyle(layer, fromLayer=sourceLayer)
         self._setDefaultSnapping(layer)
         layer.startEditing()
         layer.setFeatureFormSuppress(QgsVectorLayer.SuppressOn)
         self._iface.legendInterface().setLayerExpanded(layer, False)
     else:
         layer = None
     return layer, layerId
Ejemplo n.º 3
0
 def _loadBufferLayer(self, sourceLayer, layerPath, layerName):
     layer = None
     layerId = ''
     layerList = QgsMapLayerRegistry.instance().mapLayersByName(layerName)
     if (len(layerList) > 0):
         layer = layerList[0]
         self._iface.legendInterface().moveLayer(layer, self._bufferGroupIndex)
     else:
         fullLayerPath = self.projectPath + '/' + layerPath
         if (layerName and layerPath and sourceLayer and sourceLayer.isValid()):
             if not QFile.exists(fullLayerPath):
                 # If the layer doesn't exist, clone from the source layer
                 layer = layers.cloneAsShapefile(sourceLayer, fullLayerPath, layerName)
             else:
                 # If the layer does exist, then load it and copy the style
                 layer = QgsVectorLayer(fullLayerPath, layerName, 'ogr')
             layer = layers.addLayerToLegend(self._iface, layer, self._bufferGroupIndex)
     if layer and layer.isValid():
         layerId = layer.id()
         layers.loadStyle(layer, fromLayer=sourceLayer)
         self._setDefaultSnapping(layer)
         layer.startEditing()
         layer.setFeatureFormSuppress(QgsVectorLayer.SuppressOn)
         self._iface.legendInterface().setLayerExpanded(layer, False)
     else:
         layer = None
     return layer, layerId
Ejemplo n.º 4
0
 def _loadLogLayer(self, sourceLayer, layerPath, layerName):
     layer = None
     layerId = ''
     layerList = QgsMapLayerRegistry.instance().mapLayersByName(layerName)
     if (len(layerList) > 0):
         layer = layerList[0]
         self._iface.legendInterface().moveLayer(layer,
                                                 self._bufferGroupIndex)
     else:
         fullLayerPath = self.projectPath + '/' + layerPath
         if (layerName and layerPath and sourceLayer
                 and sourceLayer.isValid()):
             if not QFile.exists(fullLayerPath):
                 # If the layer doesn't exist, clone from the source layer
                 layer = layers.cloneAsShapefile(sourceLayer, fullLayerPath,
                                                 layerName)
                 if layer and layer.isValid():
                     layer.dataProvider().addAttributes([
                         QgsField('timestamp', QVariant.String, '', 10, 0,
                                  'timestamp')
                     ])
                     layer.dataProvider().addAttributes([
                         QgsField('event', QVariant.String, '', 6, 0,
                                  'event')
                     ])
             else:
                 # If the layer does exist, then load it and copy the style
                 layer = QgsVectorLayer(fullLayerPath, layerName, 'ogr')
                 if layer and layer.isValid():
                     layers.loadStyle(layer, fromLayer=sourceLayer)
     if layer and layer.isValid():
         layerId = layer.id()
         layer.setFeatureFormSuppress(QgsVectorLayer.SuppressOn)
         self._iface.legendInterface().setLayerExpanded(layer, False)
     else:
         layer = None
     return layer, layerId