Exemplo n.º 1
0
    def make(self, composition, inomen, mapAreaLayer, showLayers):
        # Cleanup
        self.deleteGroups(['articulation'])
        mapIDsToBeDisplayed = []
        instance = QgsProject.instance()

        # Creating the articulation frame
        gridLayer = self.createGridLayer(inomen)
        self.loadStyleToGridLayer(gridLayer)
        instance.addMapLayer(gridLayer, False)
        mapIDsToBeDisplayed.append(gridLayer.id())

        # Creating a copy of mapAreaLayer
        mapAreaLayer = self.createVectorLayerFromIter('articulationMapArea', mapAreaLayer.getFeatures())
        self.loadStyleToLayer(mapAreaLayer, self.stylesFolder / 'mapExtentStyle.qml')
        instance.addMapLayer(mapAreaLayer, False)
        mapIDsToBeDisplayed.append(mapAreaLayer.id())

        # Updates composition
        self.updateMapItem(composition, gridLayer, mapAreaLayer)

        if showLayers:
            articulationNodeGroup = QgsLayerTreeGroup('articulation')
            articulationNodeGroup.setItemVisibilityChecked(False)
            for layer in (gridLayer, mapAreaLayer):
                articulationNodeGroup.addLayer(layer)
            root = instance.layerTreeRoot()
            root.addChildNode(articulationNodeGroup)
        
        return mapIDsToBeDisplayed
Exemplo n.º 2
0
    def make(self,
             composition,
             mapExtentsLayer,
             mapExtents,
             layers,
             showLayers=False):

        mapLayers = []
        self.deleteGroups(['map'])

        instance = QgsProject.instance()
        # Setting up grid layer
        mapExtent = self.getExtent(mapExtents)
        gridLayer, mapExtentsTransformed = self.createLayerForGrid(
            mapExtentsLayer, mapExtents)
        self.applyStyleGridLayer(gridLayer)
        gridLayer.triggerRepaint()
        instance.addMapLayer(gridLayer, False)

        # Setting up aux_label, which is reprojected to mapLayers
        crs = next(iter(layers['map'])).crs()
        copyLabel = self.cloneVectorLayerReproject(gridLayer, 'aux_label', crs)
        copyLabelStyle = Path(
            __file__).parent.parent / 'styles' / 'grid' / 'aux_label.qml'
        copyLabel.loadNamedStyle(str(copyLabelStyle))
        instance.addMapLayer(copyLabel, False)

        # Setting up aux_moldura
        copy = self.cloneVectorLayer(gridLayer, 'aux_moldura')
        copyStyle = Path(
            __file__).parent.parent / 'styles' / 'grid' / 'style.qml'
        copy.loadNamedStyle(str(copyStyle))
        instance.addMapLayer(copy, False)

        # Setting up mask layer
        maskLayer = self.createMaskLayer(mapExtents)
        instance.addMapLayer(maskLayer, False)

        mapLayers.extend((copy.id(), copyLabel.id(), gridLayer.id(),
                          maskLayer.id(), *layers['id_map']))
        layersToComposition = [
            gridLayer, maskLayer, copy, copyLabel, *layers['map'],
            *layers['images']
        ]
        self.updateMapItem(composition, mapExtent, mapExtentsTransformed,
                           gridLayer, layersToComposition)

        if showLayers:
            mapGroupNode = QgsLayerTreeGroup('map')
            mapGroupNode.setItemVisibilityChecked(False)
            for lyr in layersToComposition:
                mapGroupNode.addLayer(lyr)
            root = QgsProject.instance().layerTreeRoot()
            root.addChildNode(mapGroupNode)

        return mapLayers
Exemplo n.º 3
0
    def make(self, composition, mapArea, showLayers=False, isInternational=False):
        # Cleanup
        self.deleteGroups(['divisao'])

        mapLayers = []

        # Inserting necessary layers
        divisionGroupNode = QgsLayerTreeGroup('divisao')
        divisionGroupNode.setItemVisibilityChecked(False)

        layerCountyArea, layerCountyLine, layerStateLine, layerCountryArea, layerCountryLine, layerOcean = self.createLayersGroup()
        mapLayers.extend([
            layerCountyArea.id(),layerCountyLine.id(), layerStateLine.id(), layerOcean.id(), layerCountryArea.id(), layerCountryLine.id()])

        # Getting map extents
        gridBound = mapArea.geometry().boundingBox()
        gridRectangleLayer = self.createGridRectangle(gridBound, 'divisionMapArea')
        mapLayers.append(gridRectangleLayer.id())

        # Get map extent for intersections
        # TODO: Check possible refactor on getExtent
        outerExtents = self.getExtent(gridBound, mapArea)
        orderedCountiesByCentroidDistance, orderedCountiesNamesByArea = self.getIntersections(
            layerCountyArea, outerExtents, mapArea, isInternational)

        # Labeling counties
        self.setStyles(layerCountyArea, orderedCountiesByCentroidDistance, orderedCountiesNamesByArea)

        # Inserting counties table
        html_tabledata = self.customcreateHtmlTableData(orderedCountiesNamesByArea)
        self.setMunicipiosTable(composition,  html_tabledata)

        if not isInternational:
            self.hideInternationalCouties(layerCountryArea)
            # self.unsetLabel(layerCountry)

        # Update map in correct sequence
        layersToShow = (
            gridRectangleLayer, layerOcean, layerCountryLine, layerCountryArea, layerStateLine, layerCountyLine, layerCountyArea)
        for layer in layersToShow:
            QgsProject.instance().addMapLayer(layer, False)
            divisionGroupNode.addLayer(layer)
        if showLayers:
            root = QgsProject.instance().layerTreeRoot()
            root.addChildNode(divisionGroupNode)
        self.updateMapItem(composition, outerExtents, layersToShow)
        return mapLayers
Exemplo n.º 4
0
    def make(self,
             composition,
             mapAreaFeature,
             showLayers=False,
             isInternational=False):
        # Cleanup
        self.deleteGroups(['localizacao'])
        mapLayers = []
        instance = QgsProject.instance()

        # Creating layer for mapArea
        mapAreaBoundingBox = mapAreaFeature.geometry().boundingBox()
        mapAreaLayer = self.createGridRectangle(mapAreaBoundingBox,
                                                'localizationMapArea')
        mapLayers.append(mapAreaLayer.id())

        # Getting state layer
        stateShpPath = Path(
            __file__).parent.parent / 'limites' / '2020' / 'Estados_2020.shp'
        stateLayerBackground = self.loadShapeLayer(stateShpPath, '',
                                                   'backgroundStates')
        mapExtents = self.getExtent(mapAreaFeature, stateLayerBackground,
                                    isInternational)
        self.setupBackgroundLayer(stateLayerBackground)
        self.setLabel(stateLayerBackground, isInternational)
        mapLayers.append(stateLayerBackground.id())

        # Adding layers
        instance.addMapLayer(stateLayerBackground, False)
        instance.addMapLayer(mapAreaLayer, False)

        # Updating composition
        self.updateMapItem(composition, stateLayerBackground, mapAreaLayer,
                           mapExtents)

        if showLayers:
            localizationGroupNode = QgsLayerTreeGroup('localizacao')
            localizationGroupNode.setItemVisibilityChecked(False)
            for layer in (mapAreaLayer, stateLayerBackground):
                localizationGroupNode.addLayer(layer)
            root = QgsProject.instance().layerTreeRoot()
            root.addChildNode(localizationGroupNode)

        return mapLayers
Exemplo n.º 5
0
	def make(self, composition, mapArea, layers, showLayers=False):	
		self.deleteGroups(['minimap'])	

		mapExtents = mapArea.geometry().convexHull().boundingBox()
		# Creating layers to lock map
		layersToLock = []
		layersToLock.extend(layers['minimap'])
		layersToLock.extend(layers['images'])
		self.updateMapItem(composition, mapExtents, layersToLock)	

		if showLayers:
			miniMapGroupNode = QgsLayerTreeGroup('minimap')	
			miniMapGroupNode.setItemVisibilityChecked(False)								
			for layer in layersToLock:
				miniMapGroupNode.addLayer(layer)
			root = QgsProject.instance().layerTreeRoot()		
			root.addChildNode(miniMapGroupNode)

		return layers['id_minimap']
Exemplo n.º 6
0
def _apply_group_settings(
    group: qgc.QgsLayerTreeGroup,
    settings: LayerGroupSettings,
) -> None:
    group.setItemVisibilityChecked(settings.show)
    group.setExpanded(settings.expand)