Skip to content

Commit

Permalink
Merge pull request SistemesInformacioTerritorial#519 from SistemesInf…
Browse files Browse the repository at this point in the history
…ormacioTerritorial/plots-mapificació

Afegides classes per crear i visualitzar gràfics.
  • Loading branch information
oriolmarti97 authored Apr 8, 2020
2 parents 99c8d2f + 79c7d37 commit ca881aa
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 183 deletions.
2 changes: 1 addition & 1 deletion configuracioQvista.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
configdir=os.path.join(QvTempdir+'config/')+'/' #Configuracions i coses

docdir='n:/siteb/apl/pyqgis/qvista/dades/'
imatgesDir = os.path.abspath('Imatges/')+'/'
imatgesDir = os.path.abspath('Imatges/')
docdirPlantilles=os.path.join(docdir,'plantilles/')

arxiuAvis=os.path.join(docdir,'Avisos.htm')
Expand Down
2 changes: 1 addition & 1 deletion moduls/QvCSV.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _setTitol(self, titol):
def _mapifica(self):
fMap = QvFormNovaMapificacio(
self._carregador._llegenda, mapificacio=self._carregador._mapificador)
if fMap.exec()==QDialog.Accepted:
if fMap.exec()==QDialog.Accepted and fMap.msg=='':
self._carregador.close()

class CsvTab(QTabWidget):
Expand Down
25 changes: 22 additions & 3 deletions moduls/QvCanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, pare = None, llistaBotons= None, botoneraHoritzontal = False,

self._preparacioBotonsCanvas()
self.eines=[]
self.einesBotons={}
if self.llistaBotons is not None:
self.panCanvas()
self.panCanvas()
Expand All @@ -56,7 +57,8 @@ def keyPressEvent(self, event):
self.canviMaximitza.emit()
def uncheckBotons(self,aExcepcio):
for x in self._botons:
if x is not aExcepcio: x.setChecked(False)
if x is not aExcepcio:
x.setChecked(False)
def panCanvas(self): # MANO
# bucle para quitar todos los cursores guardados. quiero que use el que ofrece MapTool
# while self.pare.app.overrideCursor() != None:
Expand All @@ -68,6 +70,7 @@ def panCanvas(self): # MANO

self.tool_pan = QgsMapToolPan(self)
self.setMapTool(self.tool_pan)
self.einesBotons[self.tool_pan]=self.bPanning


else:
Expand All @@ -88,7 +91,9 @@ def zoomIn(self):
self.uncheckBotons(self.bZoomIn)

self.tool_zoomin = QgsMapToolZoom(self, False)
self.tool_zoomin.setCursor(QvConstants.cursorZoomIn())
self.setMapTool(self.tool_zoomin)
self.einesBotons[self.tool_zoomin]=self.bZoomIn
else:
self.bZoomIn.setChecked(True)
self.setCursor(QvConstants.cursorZoomIn())
Expand All @@ -98,7 +103,9 @@ def zoomOut(self):
self.uncheckBotons(self.bZoomOut)

self.tool_zoomout = QgsMapToolZoom(self, True)
self.tool_zoomout.setCursor(QvConstants.cursorZoomOut())
self.setMapTool(self.tool_zoomout)
self.einesBotons[self.tool_zoomout]=self.bZoomOut
else:
self.bZoomOut.setChecked(True)

Expand All @@ -117,7 +124,9 @@ def seleccioClick(self):

try:
self.tool = QvSeleccioElement(self, llegenda = self.llegenda)
self.tool.setCursor(QvConstants.cursorDit())
self.setMapTool(self.tool)
self.einesBotons[self.tool]=self.bApuntar
except:
pass
else:
Expand Down Expand Up @@ -356,6 +365,11 @@ def setMapTool(self,tool):
super().setMapTool(tool)
if len(self.eines)>0 and self.eines[-1]==tool: return
self.eines.append(tool)
if tool in self.einesBotons:
self.einesBotons[tool].setChecked(True)
self.uncheckBotons(self.einesBotons[tool])
else:
self.uncheckBotons(None)
def unsetMapTool(self,eina, ultima=False):
super().unsetMapTool(eina)
if isinstance(eina,QvMascaraEinaPlantilla):
Expand All @@ -369,10 +383,15 @@ def unsetMapTool(self,eina, ultima=False):
if self.eines[-1] is None or self.eines[-1]==eina:
self.unsetLastMapTool()
return
# self.uncheckBotons(None)
if self.eines[-1] in self.einesBotons:
self.uncheckBotons(self.einesBotons[self.eines[-1]])
self.einesBotons[self.eines[-1]].setChecked(True)
super().setMapTool(self.eines[-1])
def unsetLastMapTool(self):
eina=self.eines.pop()
self.unsetMapTool(eina,True)
if len(self.eines)>1:
eina=self.eines.pop()
self.unsetMapTool(eina,True)

def mousePressEvent(self,event):
super().mousePressEvent(event)
Expand Down
6 changes: 3 additions & 3 deletions moduls/QvEinesGrafiques.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def interficie(self):

self.bs1 = QvPushButton(flat=True)
# self.bs1.setCheckable(True)
self.bs1.setIcon(QIcon(imatgesDir+'apuntar.png'))
self.bs1.setIcon(QIcon(os.path.join(imatgesDir,'apuntar.png')))
self.bs1.setToolTip('Seleccionar elements de la capa activa')
self.bs2 = QvPushButton(flat=True)
# self.bs2.setCheckable(True)
self.bs2.setIcon(QIcon(imatgesDir+'shape-polygon-plus.png'))
self.bs2.setIcon(QIcon(os.path.join(imatgesDir,'shape-polygon-plus.png')))
self.bs2.setToolTip('Dibuixar un polígon')
self.bs3 = QvPushButton(flat=True)
# self.bs3.setCheckable(True)
self.bs3.setIcon(QIcon(imatgesDir+'vector-circle-variant.png'))
self.bs3.setIcon(QIcon(os.path.join(imatgesDir,'vector-circle-variant.png')))
self.bs3.setToolTip('Dibuixar un cercle')
self.bs4 = QvPushButton('Netejar')
# self.bs4.setCheckable(True)
Expand Down
4 changes: 2 additions & 2 deletions moduls/QvLlegenda.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def __init__(self, canvas=None, atributs=None, canviCapaActiva=None, editable=Tr
self.setMenuProvider(QvMenuLlegenda(self))

self.iconaFiltre = qgGui.QgsLayerTreeViewIndicator()
self.iconaFiltre.setIcon(qtGui.QIcon(imatgesDir+'filter.png'))
self.iconaFiltre.setIcon(qtGui.QIcon(os.path.join(imatgesDir,'filter.png')))
self.iconaFiltre.setToolTip('Filtre actiu')
self.iconaFiltre.clicked.connect(self.filterElements)

self.iconaMap = qgGui.QgsLayerTreeViewIndicator()
self.iconaMap.setIcon(qtGui.QIcon(imatgesDir+'categories2.png'))
self.iconaMap.setIcon(qtGui.QIcon(os.path.join(imatgesDir,'categories2.png')))
self.iconaMap.setToolTip('Categories de mapificació')
self.iconaMap.clicked.connect(self.mapRenderer.modifyRenderer)

Expand Down
34 changes: 31 additions & 3 deletions moduls/QvMapificacio.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,29 @@
import pandas as pd
import geopandas as gpd

_TRANS_ALL = str.maketrans(
"ÁÉÍÓÚáéíóúÀÈÌÒÙàèìòùÂÊÎÔÛâêîôûÄËÏÖÜäëïöüºª€$çÇñÑ ·.,;:()[]¡!¿?|%&*/\\\'\"@#",
"AEIOUaeiouAEIOUaeiouAEIOUaeiouAEIOUaeiouoaEDcCnN______________________aN")
from qgis.core import (QgsApplication, QgsVectorLayer, QgsLayerDefinition, QgsVectorFileWriter,
QgsSymbol, QgsRendererCategory, QgsCategorizedSymbolRenderer,
QgsGraduatedSymbolRenderer, QgsRendererRange, QgsAggregateCalculator, QgsError, QgsWkbTypes,
QgsGradientColorRamp, QgsRendererRangeLabelFormat, QgsReadWriteContext, QgsExpressionContextUtils)
from qgis.PyQt.QtCore import QDate, QObject, pyqtSignal, pyqtSlot

import os
import csv
import time
import chardet
import collections
import re

from moduls.QvApp import QvApp
from moduls.QvSqlite import QvSqlite
from moduls.QvMapVars import *
from configuracioQvista import *

from typing import List
from moduls.QvPlotly import QvPlot

_TRANS_ALL = str.maketrans("ÁÉÍÓÚáéíóúÀÈÌÒÙàèìòùÂÊÎÔÛâêîôûÄËÏÖÜäëïöüºª€$çÇñÑ ·.,;:()[]¡!¿?|%&*/\\\'\"@#",
"AEIOUaeiouAEIOUaeiouAEIOUaeiouAEIOUaeiouoaEDcCnN______________________aN")

_TRANS_MINI = str.maketrans(" \'\"",
"___")
Expand All @@ -44,6 +64,9 @@
RUTA_DADES = os.path.abspath('Dades').replace('\\', '/') + '/'
CAMP_QVISTA = 'QVISTA_'

def creaPlot(out, fRes):
pl = QvPlot.barres(out['RESULTAT'],out['DESCRIPCIO'],arxiu=fRes,horitzontal=True)
pl.write()

class QvMapificacio(QObject):
"""Clase que, a partir de un CSV con campos de dirección postal es capaz de:
Expand Down Expand Up @@ -694,10 +717,15 @@ def generaCapaGpd(self, nomCapa: str, tipusAgregacio: str, tipusDistribucio: str
else:
if not self.form.msgContinuarProces(msg):
return False


# Guardar capa de mapa como Geopackage
self.fSQL = self.nomArxiuSortida(nomCapa)
out.to_file(self.fSQL, driver="GPKG", layer=nomCapa, overwrite=True)
# gràfic
# Aquí caldria comprovar si la regió utilitzada és un districte o un barri
if 'DESCRIPCIO' in out:
creaPlot(out,self.fSQL)
return True
except Exception as err:
self.msgError = "Error al calcular l'agregació de dades.\n\n" + str(err)
Expand Down
Loading

0 comments on commit ca881aa

Please sign in to comment.