def processAlgorithm(self, progress): """Here is where the processing itself takes place.""" progress.setInfo(u'Start querying "{}" in PCJupiterXL...'.format( self.name)) # Get user input compounds = self.getParameterValue(self.COMPOUND) input_table = self.getParameterValue(self.INPUT_TABLE) boreholeno_field = self.getParameterValue(self.DGUNR_FIELD) date_from = self.getParameterValue(self.DATE_FROM) date_to = self.getParameterValue(self.DATE_TO) progress.setText('<br><b>Data hentes og graf beregnes....</b><br>') qgis = JupiterQGIS() selected_boreholeno = qgis.get_selected_boreholeno( input_table, boreholeno_field) if selected_boreholeno is None: progress.setText( u'<b>Der er ikke udvalgt nogle boringer<br></b><br>') return mapplot = JupiterMatplot() if 'test_mode' == 'XXXXtest_mode': result, not_found = self.test_onecompound_multipleborehole_bymapselect( ) else: result, not_found = mapplot.timeseries_onecompound_multipleborehole( selected_boreholeno, compounds, date_from, date_to, progress=progress) if result and len(not_found) == 0: progress.setText( u'<b>Tidsserie for "{}" i boringer: "{}" er oprettet.<br></b><br>' .format(compounds.replace(';', ','), ', '.join(selected_boreholeno))) elif result and len(not_found) > 0: progress.setText( u'<b>Tidsserie for "{}" i boringer: "{}" er oprettet.<br>Boringer hvor stof ikke er fundet er: "{}"</b><br>' .format(compounds.replace(';', ','), selected_boreholeno, ', '.join(not_found))) else: progress.setText( u'<b>NO DATE: Boringer: "{}" har ingen analyser for {} i tidsperioden {} til {}.<br></b><br>' .format(selected_boreholeno, compounds.replace(';', ','), date_from, date_to)) progress.setPercentage(100)
def processAlgorithm(self, progress): JupiterAux.log_info(u'\nprocessAlgorithm: {}'.format(self.tablename)) progress.setInfo(u'Start querying "{}" in PCJupiterXL...'.format( self.name)) progress.setPercentage(30) extent = self.getParameterValue(self.EXTENT) extent_layer = self.getParameterValue(self.VECTOR_SELECTION) compoundname1 = unicode(self.getParameterValue(self.COMPOUNDNAME1)) compoundname2 = unicode(self.getParameterValue(self.COMPOUNDNAME2)) xaxeline = self.getParameterValue(self.XAXELINE) yaxeline = self.getParameterValue(self.YAXELINE) showannotations = self.getParameterValue(self.SHOWANNOTATIONS) date_from = self.getParameterValue(self.DATE_FROM) date_to = self.getParameterValue(self.DATE_TO) qgis = JupiterQGIS() if extent == "0,0,0,0": if qgis.countSelectedFeatures(extent_layer) != 1: JupiterAux.msg_box( u'Der skal være valgt een (og kun en) geometri i {}\nNår afgrænsningen er 0,0,0,0' .format(extent_layer)) return # Create plot mapplot = JupiterMatplot() result = mapplot.scatterplot(extent, compoundname1, compoundname2, date_from, date_to, extent_layer=extent_layer, x_marker=xaxeline, y_marker=yaxeline, showannotations=showannotations) progress.setPercentage(100) #if self.tablename == u'Plot Nitrat mod sulfat': # pgtablename = u'mstmvw_bulk_grwchem_alldates' #else: # raise Exception(u'Fejl: Tabel eller view: "{}" findes ikke'.format(self.tablename)) if result: progress.setInfo(u'End querying "{}" in PCJupiterXL...'.format( self.name)) progress.setText(u'<br><b>RESULTAT:</b>') progress.setText(u'<br><b>Scatterplot oprettet og åbnet</b>') else: progress.setInfo(u'Der er sket en fejl i "{}"'.format(self.name))
def processAlgorithm(self, progress): """Here is where the processing itself takes place.""" progress.setInfo(u'Fjerner markeringer fra kort') progress.setPercentage(40) remove = self.getParameterValue(self.REMOVECANVASITEMS) if remove: qgis = JupiterQGIS() qgis.remove_canvas_items(vertexmarker=True) progress.setInfo(u'Fjerning af markeringer i kort færdig') progress.setPercentage(100)
def onpick(event): thisline = event.artist borehole_graph_pick = thisline.get_label() #JupiterAux.msg_box('Picked borehole graph: {}'.format(borehole_graph_pick)) #xdata = thisline.get_xdata() #convert to dates.num2date(dt) #ydata = thisline.get_ydata() #ind = event.ind #points = tuple(zip(xdata[ind], ydata[ind])) #JupiterAux.msg_box('{} - onpick points: {}'.format(borehole_graph_selection, points)) qgis = JupiterQGIS() qgis.add_vertexmarker_borehole(borehole_graph_pick)
def processAlgorithm(self, progress): """Here is where the processing itself takes place.""" progress.setInfo(u'Start querying "{}" in PCJupiterXL...'.format(self.name)) progress.setPercentage(50) extent = self.getParameterValue(self.EXTENT) extent_layer = self.getParameterValue(self.VECTOR_SELECTION) date_from = self.getParameterValue(self.DATE_FROM) date_to = self.getParameterValue(self.DATE_TO) output = self.getOutputFromName(self.OUTPUT) where_sql = None JupiterAux.log_info(u'\nprocessAlgorithm: {}'.format(self.tablename)) if self.tablename == u'Hent alle stoffer fra grundvand (boring)': pgtablename = u'mstmvw_bulk_grwchem_alldates' where_sql = u"sampledate > to_date('{}', 'YYYY-MM-DD') AND sampledate < to_date('{}', 'YYYY-MM-DD') AND geom IS NOT NULL".\ format(date_from, date_to) output.description = 'Alle_stoffer_grw' elif self.tablename == u'Hent alle stoffer fra vandværk (anlæg)': pgtablename = u'mstmvw_bulk_pltchem_alldates' where_sql = u"sampledate > to_date('{}', 'YYYY-MM-DD') AND sampledate < to_date('{}', 'YYYY-MM-DD') AND geom IS NOT NULL".\ format(date_from, date_to) output.description = 'Alle_stoffer_plt' else: raise Exception(u'Fejl: Tabel eller view: "{}" findes ikke'.format(self.tablename)) jq = JupiterQGIS() ok_add_map = jq.add_maplayer( progress, pgtablename, output, extent, selectionLayername=extent_layer, rowid='row_id', where_sql2=where_sql) if ok_add_map: progress.setInfo(u'End querying "{}" in PCJupiterXL...'.format(self.name)) progress.setText(u'<br><b>RESULTAT:</b>') progress.setText(u'<br><b>Tabel med alle stofanalyser er åbnet</b>') else: progress.setInfo(u'Der er sket en fejl i "{}"'.format(self.name))
def processAlgorithm(self, progress): """Here is where the processing itself takes place """ progress.setInfo(u'Start querying "{}" in PCJupiterXL...'.format( self.name)) progress.setPercentage(10) # Get user input output = self.getOutputFromName( self.OUTPUT) #<class 'processing.core.outputs.OutputVector'> pgtablename = '' if self.dktablename == u'Åbn synchronizationlog': output.description = u'synchronizationlog' pgtablename = u'synchronizationlog' elif self.dktablename == u'Åbn synchronizationevent': output.description = u'synchronizationevent' pgtablename = u'synchronizationevent' elif self.dktablename == u'Åbn exporttime': output.description = u'exporttime' pgtablename = u'exporttime' JupiterAux.log_info( u'Valgt alphanumeric tabel med pgtablename: {}\n'.format( pgtablename)) qgis = JupiterQGIS() ok_add_alphatable = qgis.add_alphaview(progress, pgtablename, output) progress.setPercentage(100) if ok_add_alphatable: progress.setInfo(u'End querying "{}" in PCJupiterXL...'.format( self.name)) progress.setText(u'<br><b>RESULTAT:</b>') progress.setText( u'<br><b>Tabel med databasenavn: {} er åbnet som: {}</b>'. format(pgtablename, output.description)) else: progress.setText(u'<br><b>Fejl i udtræk. Se log:</b>')
def processAlgorithm(self, progress): """Here is where the processing itself takes place.""" progress.setInfo(u'Start querying "{}" in PCJupiterXL...'.format(self.name)) progress.setPercentage(50) pgtablename = u'mst_bekendtgoerelse_pesticide_list' output = self.getOutputFromName(self.OUTPUT) #<class 'processing.core.outputs.OutputVector'> JupiterAux.log_info('Valgte tabel eller view: {}\n'.format(self.dktablename)) jq = JupiterQGIS() ok_added = jq.add_alphaview(progress, pgtablename, output) if ok_added: progress.setInfo(u'End querying "{}" in PCJupiterXL...'.format(self.name)) progress.setPercentage(100) progress.setText(u'<br><b>RESULTAT:</b>') progress.setText(u'<br><b>Tabel: {} er åbnet med navnet: {}</b>'.format(self.dktablename, pgtablename)) else: progress.setInfo(u'Der er sket en fejl i "{}"'.format(self.name)) progress.setPercentage(100)
def processAlgorithm(self, progress): """Here is where the processing itself takes place.""" progress.setInfo(u'Start querying "{}" in PCJupiterXL...'.format( self.name)) progress.setPercentage(50) pgtablename = u'borehole' input = self.getParameterValue(self.INPUT) fieldname = self.getParameterValue(self.DGUNR_FIELD) output = self.getOutputFromName( self.OUTPUT) #<class 'processing.core.outputs.OutputVector'> JupiterAux.log_info('Valgte tabel med dgunummer: {}\n'.format( self.dktablename)) jq = JupiterQGIS() ok_added, str_no_match, str_duplicates = jq.make_dguno_spatial( progress, pgtablename, input, fieldname, output) if ok_added: progress.setInfo(u'End querying "{}" in PCJupiterXL...'.format( self.name)) progress.setPercentage(100) progress.setText(u'<br><b>RESULTAT:</b>') progress.setText( u'<br><b>Tabel: {} er åbnet med navnet: {}</b>'.format( pgtablename, self.dktablename)) progress.setText(u'<br><b>BEMÆRK:</b>') progress.setText( u'<br><b>Ikke fundet dguno: "{}" og fejl dublere: {}</b><br>'. format(str_no_match, str_duplicates)) else: progress.setInfo(u'Der er sket en fejl i "{}"'.format(self.name)) progress.setPercentage(100)
def onpick(event): # Warning matplotlib fails in silence - https://matplotlib.org/examples/event_handling/pick_event_demo.html index = event.ind borehole_arr_pick = np.take(boreholenos, index) #JupiterAux.msg_box('onpick scatter: {}'.format(borehole_arr_pick)) qgis = JupiterQGIS() for j, b in enumerate(borehole_arr_pick): if j == 0: qgis.add_vertexmarker_borehole(b) else: qgis.add_vertexmarker_borehole(b, keepExistingMarkers=True)
def processAlgorithm(self, progress): """Here is where the processing itself takes place """ progress.setInfo(u'Start querying "{}" in PCJupiterXL...'.format( self.name)) progress.setPercentage(10) # Get user input extent = self.getParameterValue(self.EXTENT) maplayerselection = self.getParameterValue(self.VECTOR_SELECTION) output = self.getOutputFromName( self.OUTPUT) #<class 'processing.core.outputs.OutputVector'> rowid = None # rowid on view is compulsory where_sql = None # Time interval query if self.dktablename == u'Åbn boringstabellen': output.description = u'Boringer' pgtablename = u'borehole' elif self.dktablename == u'Åbn miljøboringer': output.description = u'Miljoeboringer' pgtablename = u'borehole' where_sql = "(geom is not null) and (use = 'L' or purpose = 'L')" elif self.dktablename == u'Åbn sløjfede boringer': output.description = u'Sloejfede boringer' rowid = 'objectid' pgtablename = u'mstmvw_boring_canceled' elif self.dktablename == u'Åbn GRUMO boringer': output.description = u'GRUMO boringer' rowid = 'row_id1' pgtablename = u'mstmvw_grumo_boringer' elif self.dktablename == u'Åbn anlægstabellen': output.description = u'Anlaeg' pgtablename = u'drwplant' elif self.dktablename == u'Åbn vandforsyningsboringer': output.description = u'Vandforsyningsboringer' rowid = 'row_id1' pgtablename = u'mstmvw_vandforsyningsboringer' elif self.dktablename == u'Åbn pejlinger': output.description = u'Pejlinger' rowid = 'row_id' pgtablename = u'mstmvw_waterlevel_all_dates' else: raise Exception( u'Tabel eller view: {} findes ikke i metoden_geoalgorithm.processAlgotithm' .format(self.dktablename)) JupiterAux.log_info( u'Valgt tabel eller view: {} med pgtablename: {}\n'.format( self.dktablename, pgtablename)) qgis = JupiterQGIS() ok_add_map = qgis.add_maplayer(progress, pgtablename, output, extent, selectionLayername=maplayerselection, rowid=rowid, where_sql2=where_sql) progress.setPercentage(100) if ok_add_map: progress.setInfo(u'End querying "{}" in PCJupiterXL...'.format( self.name)) progress.setText(u'<br><b>RESULTAT:</b>') progress.setText( u'<br><b>Tabel med databasenavn: {} er åbnet som: {}</b>'. format(pgtablename, output.description)) else: progress.setText(u'<br><b>Fejl i udtræk. Se log:</b>')
def processAlgorithm(self, progress): """Here is where the processing itself takes place """ progress.setInfo(u'Start querying "{}" in PCJupiterXL...'.format(self.name)) progress.setPercentage(10) # Get user input extent = self.getParameterValue(self.EXTENT) maplayerselection = self.getParameterValue(self.VECTOR_SELECTION) date_to = self.getParameterValue(self.DATE_TO) date_from = self.getParameterValue(self.DATE_FROM) onlyload_latest = self.getParameterValue(self.LOAD_ONLY_LATEST) output = self.getOutputFromName(self.OUTPUT) #<class 'processing.core.outputs.OutputVector'> where_sql = None # Time interval query if self.dktablename == u'Beregn vandtype': output.description = u'Vandtype' if onlyload_latest: pgtablename = u'mstmvw_watertype4_latestdate' else: pgtablename = u'mstmvw_watertype4_alldates' where_sql = u"sampledate > to_date('{}', 'YYYY-MM-DD') AND sampledate < to_date('{}', 'YYYY-MM-DD')".format(date_from, date_to) elif self.dktablename == u'Beregn ionbalance': output.description = u'Ionbalance' if onlyload_latest: pgtablename = u'mstmvw_ionbalance_latest_dates' else: pgtablename = u'mstmvw_ionbalance_all_dates' where_sql = u"sampledate > to_date('{}', 'YYYY-MM-DD') AND sampledate < to_date('{}', 'YYYY-MM-DD')".format(date_from, date_to) elif self.dktablename == u'Hent uorganiske stoffer': output.description = u'Uorganiske stoffer' if onlyload_latest: pgtablename = u'mstmvw_inorganic_compound_latest_dates' else: pgtablename = u'mstmvw_inorganic_compound_all_dates' where_sql = u"sampledate > to_date('{}', 'YYYY-MM-DD') AND sampledate < to_date('{}', 'YYYY-MM-DD')".format(date_from, date_to) elif self.dktablename == u'Åbn pejlinger': output.description = u'Pejlinger' if onlyload_latest: pgtablename = u'mstmvw_waterlevel_latest_dates' else: pgtablename = u'mstmvw_waterlevel_all_dates' where_sql = u"pejledato > to_date('{}', 'YYYY-MM-DD') AND pejledato < to_date('{}', 'YYYY-MM-DD')".format(date_from, date_to) elif self.dktablename == u'Kombineret kemiskudtræk': output.description = u'Kemi' if onlyload_latest: pgtablename = u'mstmvw_combined_chemestry_latestdates' else: pgtablename = u'mstmvw_combined_chemestry_alldates' where_sql = u"sampledate > to_date('{}', 'YYYY-MM-DD') AND sampledate < to_date('{}', 'YYYY-MM-DD')".format( date_from, date_to) else: raise Exception(u'Fejl. tabel eller view: {} findes ikke'.format(self.dktablename)) JupiterAux.log_info(u'Valgt tabel eller view: {} med pgtablename: {}\n'.format(self.dktablename, pgtablename)) jq = JupiterQGIS() ok_add_map = jq.add_maplayer( progress, pgtablename, output, extent, selectionLayername=maplayerselection, rowid='row_id', where_sql2=where_sql) progress.setPercentage(100) if ok_add_map: progress.setInfo(u'End querying "{}" in PCJupiterXL...'.format(self.name)) progress.setText(u'<br><b>RESULTAT:</b>') progress.setText(u'<br><b>Tabel med databasenavn: {} er åbnet som: {}</b>'.format(pgtablename, output.description)) else: progress.setText(u'<br><b>Fejl i udtræk. Se log:</b>')
def scatterplot(self, extent_or_wkt, compoundname_x, compoundname_y, datefrom, dateto, extent_layer=None, x_marker=None, y_marker=None, showannotations=False): """ Create a scatter plot Either from boreholes in bbox or wkt selected geometries :param extent_or_wkt: Either a extent string or a wkt geometry :param compoundname_x: Compound name for x axe :param compoundname_y: Compound name for y axe :param datefrom: Query from date :param dateto: Query to date :param extent_layer: layername with selection. Only relevant if WKT bound. :param x_marker: marker line for given value :param y_marker: marker line for given value :return: True if no error :param showannotations: Show boreholeno label for each scatter point """ def onpick(event): # Warning matplotlib fails in silence - https://matplotlib.org/examples/event_handling/pick_event_demo.html index = event.ind borehole_arr_pick = np.take(boreholenos, index) #JupiterAux.msg_box('onpick scatter: {}'.format(borehole_arr_pick)) qgis = JupiterQGIS() for j, b in enumerate(borehole_arr_pick): if j == 0: qgis.add_vertexmarker_borehole(b) else: qgis.add_vertexmarker_borehole(b, keepExistingMarkers=True) db = JupiterDb() compoundno_x = db.compoundname_to_no(compoundname_x) compoundno_y = db.compoundname_to_no(compoundname_y) unit_x = db.get_unit_quess(compoundno_x) unit_y = db.get_unit_quess(compoundno_y) if compoundno_x is None or compoundno_y is None: JupiterAux.msg_box( 'Et af de to indtastede stoffer: "{}, {}" findes ikke i PCJupiterXL' .format(compoundname1, compoundname2)) return qgis = JupiterQGIS() qgis.remove_canvas_items() # Remove marker from a previous plot boreholenos = [] if extent_or_wkt != '0,0,0,0': bbox = qgis.extentToBoundingbox(extent_or_wkt) x, y, boreholenos = db.get_scatter_array_bbox( compoundno_x, compoundno_y, bbox, datefrom, dateto, compoundname_x, compoundname_y) else: wkt = qgis.selectedFeatureToWKT(extent_layer) x, y, boreholenos = db.get_scatter_array_wkt( compoundno_x, compoundno_y, wkt, datefrom, dateto, compoundname_x, compoundname_y) # General Figure plt.figure(1) fig = plt.figure(1) # Connect pick event on plot cid = fig.canvas.mpl_connect('pick_event', onpick) plt.scatter( x, y, alpha=0.8, picker=True) # plt.scatter(x, y, s=area, c=colors, alpha=0.5) ax = fig.add_subplot(1, 1, 1) ax.set_xlabel('{} [{}]'.format(compoundname_x, unit_x)) ax.set_ylabel('{} [{}]'.format(compoundname_y, unit_y)) ax.xaxis.grid() ax.yaxis.grid() # label points in scatter plot if showannotations: for i, txt in enumerate(boreholenos): ax.annotate(str(txt), (x[i], y[i])) plt.axhline(y=y_marker) plt.axvline(x=x_marker) plt.title('Scatterplot') plt.show() return True
def processAlgorithm(self, progress): """Here is where the processing itself takes place.""" progress.setInfo(u'Start querying "{}" in PCJupiterXL...'.format( self.name)) progress.setPercentage(50) extent = self.getParameterValue(self.EXTENT) extent_layer = self.getParameterValue(self.VECTOR_SELECTION) compoundname = unicode(self.getParameterValue(self.COMPOUNDNAME)) compoundlimit = self.getParameterValue(self.COMPOUNDLIMIT) date_from = self.getParameterValue(self.DATE_FROM) date_to = self.getParameterValue(self.DATE_TO) onlyload_latest = self.getParameterValue(self.LOAD_ONLY_LATEST) output = self.getOutputFromName(self.OUTPUT) where_sql = None db = JupiterDb() compoundno = db.compoundname_to_no(compoundname) if compoundno is None: JupiterAux.msg_box( u'Stoffet: "{}" findes ikke i PCJupiterXL'.format( compoundname)) progress.setPercentage(100) return JupiterAux.log_info(u'\nprocessAlgorithm: {}'.format(self.tablename)) output.description = compoundname if self.tablename == u'Søg et stof fra grundvand (boring)': if onlyload_latest: pgtablename = u'mstvw_bulk_grwchem_latestdates' where_sql = u"compoundno = {} AND amount > {} AND geom IS NOT NULL".format( compoundno, compoundlimit) else: pgtablename = u'mstvw_bulk_grwchem' #is alldates where_sql = u"sampledate > to_date('{}', 'YYYY-MM-DD') AND sampledate < to_date('{}', 'YYYY-MM-DD') AND compoundno = {} AND amount > {} AND geom IS NOT NULL".\ format(date_from, date_to, compoundno, compoundlimit) elif self.tablename == u'Søg et stof fra vandværk (anlæg)': if onlyload_latest: pgtablename = u'mstmvw_bulk_pltchem_latestdates' where_sql = u"compoundno = {} AND amount > {} AND geom IS NOT NULL".format( compoundno, compoundlimit) else: pgtablename = u'mstmvw_bulk_pltchem_alldates' where_sql = u"sampledate > to_date('{}', 'YYYY-MM-DD') AND sampledate < to_date('{}', 'YYYY-MM-DD') AND compoundno = {} AND amount > {} AND geom IS NOT NULL".\ format(date_from, date_to, compoundno, compoundlimit) else: raise Exception(u'Fejl: Tabel eller view: "{}" findes ikke'.format( self.tablename)) jq = JupiterQGIS() ok_add_map = jq.add_maplayer(progress, pgtablename, output, extent, selectionLayername=extent_layer, rowid='row_id', where_sql2=where_sql) if ok_add_map: progress.setInfo(u'End querying "{}" in PCJupiterXL...'.format( self.name)) progress.setText(u'<br><b>RESULTAT:</b>') progress.setText( u'<br><b>Tabel {} er åbnet med navnet {}</b>'.format( self.tablename, compoundname)) else: progress.setInfo(u'Der er sket en fejl i "{}"'.format(self.name))