Esempio n. 1
0
class MemoryLayers():
    def __init__(self, iface):
        self.iface = iface
        self.settings = MySettings()

    def setLayerVisible(self, layer):
        root = QgsProject.instance().layerTreeRoot()
        node = root.findLayer(layer.id())
        node.setVisible(Qt.Checked)

    def lineLayer(self):
        layerID = self.settings.value("memoryLineLayer")
        layer = QgsMapLayerRegistry.instance().mapLayer(layerID)
        if layer is None:
            epsg = self.iface.mapCanvas().mapRenderer().destinationCrs(
            ).authid()
            layer = QgsVectorLayer(
                "LineString?crs=%s&field=id:string&field=type:string&field=x:double&field=y:double&field=observation:double&field=precision:double&index=yes"
                % epsg, "IntersectIt Lines", "memory")
            QgsMapLayerRegistry.instance().addMapLayer(layer)
            layer.layerDeleted.connect(self.__lineLayerDeleted)
            layer.featureDeleted.connect(self.__lineLayerFeatureDeleted)
            self.settings.setValue("memoryLineLayer", layer.id())
        else:
            self.setLayerVisible(layer)
        return layer

    def __lineLayerDeleted(self):
        self.settings.setValue("memoryLineLayer", "")

    def __lineLayerFeatureDeleted(self, fid):
        # todo: delete corresponding feature in other layer
        print "hay"

    def pointLayer(self):
        layerID = self.settings.value("memoryPointLayer")
        layer = QgsMapLayerRegistry.instance().mapLayer(layerID)
        if layer is None:
            epsg = self.iface.mapCanvas().mapRenderer().destinationCrs(
            ).authid()
            layer = QgsVectorLayer(
                "Point?crs=%s&field=id:string&index=yes" % epsg,
                "IntersectIt Points", "memory")
            QgsMapLayerRegistry.instance().addMapLayer(layer)
            layer.layerDeleted.connect(self.__pointLayerDeleted)
            self.settings.setValue("memoryPointLayer", layer.id())
        else:
            self.setLayerVisible(layer)
        return layer

    def __pointLayerDeleted(self):
        self.settings.setValue("memoryPointLayer", "")
Esempio n. 2
0
class MemoryLayers():
    def __init__(self, iface):
        self.iface = iface
        self.settings = MySettings()

    def set_layer_visible(self, layer):
        root = QgsProject.instance().layerTreeRoot()
        node = root.findLayer(layer.id())
        node.setVisible(Qt.Checked)
        
    def remove_layers(self):
        try:
            QgsMapLayerRegistry.instance().removeMapLayer(self.settings.value("memoryLineLayer"))
            QgsMapLayerRegistry.instance().removeMapLayer(self.settings.value("memoryPointLayer"))
        except AttributeError:
            return
        
    def clean_layers(self):
        for layer_name in ('memoryLineLayer', 'memoryPointLayer'):
            layer_id = self.settings.value(layer_name)
            layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
            layer.selectAll()
            fids = layer.selectedFeaturesIds()
            layer.dataProvider().deleteFeatures(fids)
            layer.featuresDeleted.emit(fids)
        self.iface.mapCanvas().refresh()

    def line_layer(self):
        layer_id = self.settings.value("memoryLineLayer")
        layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
        if layer is None:
            epsg = self.iface.mapCanvas().mapRenderer().destinationCrs().authid()
            layer = QgsVectorLayer("LineString?crs=%s&field=id:string&field=type:string&field=x:double&field=y:double&field=observation:double&field=precision:double&index=yes" % epsg, "IntersectIt Lines", "memory")
            QgsMapLayerRegistry.instance().addMapLayer(layer)
            layer.layerDeleted.connect(self.__line_layer_deleted)
            layer.featureDeleted.connect(self.__line_layer_feature_deleted)
            self.settings.setValue("memoryLineLayer", layer.id())
        else:
            self.set_layer_visible(layer)
        return layer

    def __line_layer_deleted(self):
        self.settings.setValue("memoryLineLayer", "")

    def __line_layer_feature_deleted(self, fid):
        # todo: delete corresponding feature in other layer
        print "hay"

    def point_layer(self):
        layer_id = self.settings.value("memoryPointLayer")
        layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
        if layer is None:
            epsg = self.iface.mapCanvas().mapRenderer().destinationCrs().authid()
            layer = QgsVectorLayer("Point?crs=%s&field=id:string&index=yes" % epsg, "IntersectIt Points", "memory")
            QgsMapLayerRegistry.instance().addMapLayer(layer)
            layer.layerDeleted.connect(self.__pointLayerDeleted)
            self.settings.setValue("memoryPointLayer", layer.id())
        else:
            self.set_layer_visible(layer)
        return layer

    def __pointLayerDeleted(self):
        self.settings.setValue("memoryPointLayer", "")
Esempio n. 3
0
class MemoryLayers():
    def __init__(self, iface):
        self.iface = iface
        self.settings = MySettings()

    def set_layer_visible(self, layer):
        root = QgsProject.instance().layerTreeRoot()
        node = root.findLayer(layer.id())
        node.setVisible(Qt.Checked)
        
    def remove_layers(self):
        try:
            QgsMapLayerRegistry.instance().removeMapLayer(self.settings.value("memoryLineLayer"))
            QgsMapLayerRegistry.instance().removeMapLayer(self.settings.value("memoryPointLayer"))
        except AttributeError:
            return
        
    def clean_layers(self):
        for layer_name in ('memoryLineLayer', 'memoryPointLayer'):
            layer_id = self.settings.value(layer_name)
            layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
            layer.selectAll()
            fids = layer.selectedFeaturesIds()
            layer.dataProvider().deleteFeatures(fids)
            layer.featuresDeleted.emit(fids)
        self.iface.mapCanvas.refresh()

    def line_layer(self):
        layer_id = self.settings.value("memoryLineLayer")
        layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
        if layer is None:
            epsg = self.iface.mapCanvas().mapRenderer().destinationCrs().authid()
            layer = QgsVectorLayer("LineString?crs=%s&field=id:string&field=type:string&field=x:double&field=y:double&field=observation:double&field=precision:double&index=yes" % epsg, "IntersectIt Lines", "memory")
            QgsMapLayerRegistry.instance().addMapLayer(layer)
            layer.layerDeleted.connect(self.__line_layer_deleted)
            layer.featureDeleted.connect(self.__line_layer_feature_deleted)
            self.settings.setValue("memoryLineLayer", layer.id())
        else:
            self.set_layer_visible(layer)
        return layer

    def __line_layer_deleted(self):
        self.settings.setValue("memoryLineLayer", "")

    def __line_layer_feature_deleted(self, fid):
        # todo: delete corresponding feature in other layer
        print "hay"

    def point_layer(self):
        layer_id = self.settings.value("memoryPointLayer")
        layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
        if layer is None:
            epsg = self.iface.mapCanvas().mapRenderer().destinationCrs().authid()
            layer = QgsVectorLayer("Point?crs=%s&field=id:string&index=yes" % epsg, "IntersectIt Points", "memory")
            QgsMapLayerRegistry.instance().addMapLayer(layer)
            layer.layerDeleted.connect(self.__pointLayerDeleted)
            self.settings.setValue("memoryPointLayer", layer.id())
        else:
            self.set_layer_visible(layer)
        return layer

    def __pointLayerDeleted(self):
        self.settings.setValue("memoryPointLayer", "")