def calculate_on_GEE(self): self.close() crosses_180th, geojsons = self.aoi.bounding_box_gee_geojson() val = [] n = 1 if self.area_tab.area_fromfile.isChecked(): for f in self.aoi.get_layer_wgs84().getFeatures(): # Get an OGR geometry from the QGIS geometry geom = f.geometry() val.append(geom) n += 1 # stringify json object val_string = '{}'.format(json.loads(val[0].asJson())) # create ogr geometry val_geom = ogr.CreateGeometryFromJson(val_string) # simplify polygon to tolerance of 0.003 val_geom_simplified = val_geom.Simplify(0.003) # fetch coordinates from json coords= json.loads(val_geom_simplified.ExportToJson())['coordinates'] geometries = json.dumps([{ "coordinates":coords, "type":"Polygon" }]) elif self.area_tab.area_fromadmin.isChecked(): geometries =json.dumps([{ "coordinates":self.get_admin_poly_geojson()['geometry']['coordinates'][0], "type":"Polygon" }]) elif self.area_tab.area_frompoint.isChecked(): point = QgsPointXY(float(self.area_tab.area_frompoint_point_x.text()), float(self.area_tab.area_frompoint_point_y.text())) crs_src = QgsCoordinateReferenceSystem(self.area_tab.canvas.mapSettings().destinationCrs().authid()) point = QgsCoordinateTransform(crs_src, self.aoi.crs_dst, QgsProject.instance()).transform(point) geometries = json.dumps(json.loads(QgsGeometry.fromPointXY(point).asJson())) payload = { 'depth': self.sqi_setup_tab.use_depth.value(), 'geojsons': geometries, 'crosses_180th': crosses_180th, 'crs': self.aoi.get_crs_dst_wkt(), 'texture_matrix':self.sqi_setup_tab.dlg_texture_agg.get_agg_as_list()[1], 'task_name': self.options_tab.task_name.text(), 'task_notes': self.options_tab.task_notes.toPlainText()} resp = run_script(get_script_slug('soil-quality'), payload) if resp: mb.pushMessage(QtWidgets.QApplication.translate("MISLAND", "Submitted"), QtWidgets.QApplication.translate("MISLAND", "Soil quality task submitted to Google Earth Engine."), level=0, duration=5) else: mb.pushMessage(QtWidgets.QApplication.translate("MISLAND", "Error"), QtWidgets.QApplication.translate("MISLAND", "Unable to submit climate quality task to Google Earth Engine."), level=0, duration=5)
def btn_calculate(self): # Note that the super class has several tests in it - if they fail it # returns False, which would mean this function should stop execution # as well. ret = super(DlgTimeseries, self).btn_calculate() if not ret: return self.close() if self.ndvi.isChecked(): indices = 'NDVI' elif self.savi.isChecked(): indices = 'SAVI' else: indices = 'MSAVI2' crosses_180th, geojsons = self.aoi.bounding_box_gee_geojson() payload = { 'crosses_180th': crosses_180th, 'geojsons': json.dumps(geojsons), 'crs': self.aoi.get_crs_dst_wkt(), 'indices': indices, 'start': self.year_start.date().year(), 'end': self.year_end.date().year(), 'title': self.task_name.text(), 'task_name': self.options_tab.task_name.text(), 'task_notes': self.options_tab.task_notes.toPlainText() } # This will add in the method parameter # payload.update(self.scripts['productivity']['trajectory functions'][self.traj_indic.currentText()]['params']) resp = run_script(get_script_slug('time-series'), payload) if resp: mb.pushMessage( self.tr("Submitted"), self. tr("Time series calculation task submitted to Google Earth Engine." ), level=0, duration=5) else: mb.pushMessage( self.tr("Error"), self. tr("Unable to submit time series calculation task to Google Earth Engine." ), level=1, duration=5)
def btn_calculate(self): ret = super(DlgCalculateForestFire, self).btn_calculate() if not ret: return self.close() if self.radio_landsat8.isChecked(): prod_mode = 'L8' else: prod_mode = 'S2' crosses_180th, geojsons = self.aoi.bounding_box_gee_geojson() val = [] n = 1 if self.area_tab.area_fromfile.isChecked(): for f in self.aoi.get_layer_wgs84().getFeatures(): # Get an OGR geometry from the QGIS geometry geom = f.geometry() val.append(geom) n += 1 # stringify json object val_string = '{}'.format(json.loads(val[0].asJson())) # create ogr geometry val_geom = ogr.CreateGeometryFromJson(val_string) # simplify polygon to tolerance of 0.003 val_geom_simplified = val_geom.Simplify(0.003) # fetch coordinates from json coords = json.loads( val_geom_simplified.ExportToJson())['coordinates'] geometries = json.dumps([{ "coordinates": coords, "type": "Polygon" }]) elif self.area_tab.area_fromadmin.isChecked(): geometries = json.dumps([{ "coordinates": self.get_admin_poly_geojson()['geometry']['coordinates'][0], "type": "Polygon" }]) elif self.area_tab.area_frompoint.isChecked(): point = QgsPointXY( float(self.area_tab.area_frompoint_point_x.text()), float(self.area_tab.area_frompoint_point_y.text())) crs_src = QgsCoordinateReferenceSystem( self.area_tab.canvas.mapSettings().destinationCrs().authid()) point = QgsCoordinateTransform( crs_src, self.aoi.crs_dst, QgsProject.instance()).transform(point) geometries = json.dumps( json.loads(QgsGeometry.fromPointXY(point).asJson())) # area = self.aoi.get_area()/(1000 * 1000) # log('{0}'.format(poly)) date_format = '{0}-{1}-{2}' prefire_start = date_format.format( self.prefire_start_btn.date().year(), self.prefire_start_btn.date().month(), self.prefire_start_btn.date().day()) prefire_end = date_format.format(self.prefire_end_btn.date().year(), self.prefire_end_btn.date().month(), self.prefire_end_btn.date().day()) postfire_start = date_format.format( self.postfire_start_btn.date().year(), self.postfire_start_btn.date().month(), self.postfire_start_btn.date().day()) postfire_end = date_format.format(self.postfire_end_btn.date().year(), self.postfire_end_btn.date().month(), self.postfire_end_btn.date().day()) payload = { 'prod_mode': prod_mode, # 'area':area, 'prefire_start_btn': prefire_start, 'prefire_end_btn': prefire_end, 'postfire_start_btn': postfire_start, 'postfire_end_btn': postfire_end, 'geojsons': geometries, # 'geojsons':json.dumps(geojsons), 'crs': self.aoi.get_crs_dst_wkt(), 'crosses_180th': crosses_180th, # 'og_simple':'{}'.format(og_simple), 'task_name': self.options_tab.task_name.text(), 'task_notes': self.options_tab.task_notes.toPlainText() } resp = run_script(get_script_slug('forest-fire'), payload) if resp: mb.pushMessage( QtWidgets.QApplication.translate("MISLAND", "Submitted"), QtWidgets.QApplication.translate( "MISLAND", "Forest Fire task submitted to Google Earth Engine."), level=0, duration=5) else: mb.pushMessage( QtWidgets.QApplication.translate("MISLAND", "Error"), QtWidgets.QApplication.translate( "MISLAND", "Unable to submit forest fire task to Google Earth Engine." ), level=0, duration=5)
def btn_calculate(self): # Note that the super class has several tests in it - if they fail it # returns False, which would mean this function should stop execution # as well. ret = super(DlgDownload, self).btn_calculate() if not ret: return rows = list( set(index.row() for index in self.data_view.selectedIndexes())) self.close() crosses_180th, geojsons = self.aoi.bounding_box_gee_geojson() val = [] n = 1 if self.area_tab.area_fromfile.isChecked(): for f in self.aoi.get_layer_wgs84().getFeatures(): # Get an OGR geometry from the QGIS geometry geom = f.geometry() val.append(geom) n += 1 # stringify json object val_string = '{}'.format(json.loads(val[0].asJson())) # create ogr geometry val_geom = ogr.CreateGeometryFromJson(val_string) # simplify polygon to tolerance of 0.003 val_geom_simplified = val_geom.Simplify(0.003) # fetch coordinates from json coords = json.loads( val_geom_simplified.ExportToJson())['coordinates'] geometries = json.dumps([{ "coordinates": coords, "type": "Polygon" }]) elif self.area_tab.area_fromadmin.isChecked(): geometries = json.dumps([{ "coordinates": self.get_admin_poly_geojson()['geometry']['coordinates'][0], "type": "Polygon" }]) elif self.area_tab.area_frompoint.isChecked(): point = QgsPointXY( float(self.area_tab.area_frompoint_point_x.text()), float(self.area_tab.area_frompoint_point_y.text())) crs_src = QgsCoordinateReferenceSystem( self.area_tab.canvas.mapSettings().destinationCrs().authid()) point = QgsCoordinateTransform( crs_src, self.aoi.crs_dst, QgsProject.instance()).transform(point) geometries = json.dumps( json.loads(QgsGeometry.fromPointXY(point).asJson())) for row in rows: payload = { 'geojsons': geometries, 'crs': self.aoi.get_crs_dst_wkt(), 'year_start': self.first_year.date().year(), 'year_end': self.last_year.date().year(), 'crosses_180th': crosses_180th, 'asset': self.datasets[row]['GEE Dataset'], 'name': self.datasets[row]['title'], 'temporal_resolution': self.datasets[row]['Temporal resolution'], 'task_name': self.options_tab.task_name.text(), 'task_notes': self.options_tab.task_notes.toPlainText() } resp = run_script(get_script_slug('download-data'), payload) if resp: mb.pushMessage( QtWidgets.QApplication.translate("MISLAND", "Success"), QtWidgets.QApplication.translate( "MISLAND", "Download request submitted to Google Earth Engine."), level=0, duration=5) else: mb.pushMessage( QtWidgets.QApplication.translate("MISLAND", "Error"), QtWidgets.QApplication.translate( "MISLAND", "Unable to submit download request to Google Earth Engine." ), level=0, duration=5)
def btn_calculate(self): if self.mode_te_prod.isChecked() \ and not (self.groupBox_traj.isChecked() or self.groupBox_perf.isChecked() or self.groupBox_state.isChecked()): QtWidgets.QMessageBox.critical(None, self.tr("Error"), self.tr("Choose one or more productivity sub-indicator to calculate."), None) return # Note that the super class has several tests in it - if they fail it # returns False, which would mean this function should stop execution # as well. ret = super(DlgCalculateProd, self).btn_calculate() if not ret: return self.close() ndvi_dataset = self.datasets['NDVI'][self.dataset_ndvi.currentText()]['GEE Dataset'] log(u'ndvi_dataset is {}'.format(ndvi_dataset)) if self.traj_climate.currentText() != "": climate_gee_dataset = self.climate_datasets[self.traj_climate.currentText()]['GEE Dataset'] log(u'climate_gee_dataset {}'.format(climate_gee_dataset)) else: climate_gee_dataset = None if self.mode_te_prod.isChecked(): prod_mode = 'Trends.Earth productivity' else: prod_mode = 'JRC LPD' crosses_180th, geojsons = self.aoi.bounding_box_gee_geojson() val = [] n = 1 if self.area_tab.area_fromfile.isChecked(): for f in self.aoi.get_layer_wgs84().getFeatures(): # Get an OGR geometry from the QGIS geometry geom = f.geometry() val.append(geom) n += 1 # stringify json object val_string = '{}'.format(json.loads(val[0].asJson())) # create ogr geometry val_geom = ogr.CreateGeometryFromJson(val_string) # simplify polygon to tolerance of 0.003 val_geom_simplified = val_geom.Simplify(0.003) # fetch coordinates from json coords= json.loads(val_geom_simplified.ExportToJson())['coordinates'] geometries = json.dumps([{ "coordinates":coords, "type":"Polygon" }]) elif self.area_tab.area_fromadmin.isChecked(): geometries =json.dumps([{ "coordinates":self.get_admin_poly_geojson()['geometry']['coordinates'][0], "type":"Polygon" }]) elif self.area_tab.area_frompoint.isChecked(): point = QgsPointXY(float(self.area_tab.area_frompoint_point_x.text()), float(self.area_tab.area_frompoint_point_y.text())) crs_src = QgsCoordinateReferenceSystem(self.area_tab.canvas.mapSettings().destinationCrs().authid()) point = QgsCoordinateTransform(crs_src, self.aoi.crs_dst, QgsProject.instance()).transform(point) geometries = json.dumps(json.loads(QgsGeometry.fromPointXY(point).asJson())) payload = {'prod_mode': prod_mode, 'calc_traj': self.groupBox_traj.isChecked(), 'calc_perf': self.groupBox_perf.isChecked(), 'calc_state': self.groupBox_state.isChecked(), 'prod_traj_year_initial': self.traj_year_start.date().year(), 'prod_traj_year_final': self.traj_year_end.date().year(), 'prod_perf_year_initial': self.perf_year_start.date().year(), 'prod_perf_year_final': self.perf_year_end.date().year(), 'prod_state_year_bl_start': self.state_year_bl_start.date().year(), 'prod_state_year_bl_end': self.state_year_bl_end.date().year(), 'prod_state_year_tg_start': self.state_year_tg_start.date().year(), 'prod_state_year_tg_end': self.state_year_tg_end.date().year(), 'geojsons': geometries, # 'geojsons':json.dumps(geojsons), 'crs': self.aoi.get_crs_dst_wkt(), 'crosses_180th': crosses_180th, 'ndvi_gee_dataset': ndvi_dataset, 'climate_gee_dataset': climate_gee_dataset, 'task_name': self.options_tab.task_name.text(), 'task_notes': self.options_tab.task_notes.toPlainText()} # This will add in the trajectory-method parameter for productivity # trajectory payload.update(self.scripts['productivity']['trajectory functions'][self.traj_indic.currentText()]['params']) resp = run_script(get_script_slug('productivity'), payload) if resp: mb.pushMessage(QtWidgets.QApplication.translate("MISLAND", "Submitted"), QtWidgets.QApplication.translate("MISLAND", "Productivity task submitted to Google Earth Engine."), level=0, duration=5) else: mb.pushMessage(QtWidgets.QApplication.translate("MISLAND", "Error"), QtWidgets.QApplication.translate("MISLAND", "Unable to submit productivity task to Google Earth Engine."), level=0, duration=5)
def btn_calculate(self): ret = super(DlgCalculateVQI, self).btn_calculate() if not ret: return date_format = '{0}-{1}-{2}' plant_start =date_format.format(self.vqi_setup_tab.plant_start_btn.date().year(), self.vqi_setup_tab.plant_start_btn.date().month(), self.vqi_setup_tab.plant_start_btn.date().day()) plant_end = date_format.format(self.vqi_setup_tab.plant_end_btn.date().year(), self.vqi_setup_tab.plant_end_btn.date().month(), self.vqi_setup_tab.plant_end_btn.date().day()) if (plant_start == plant_end): QtWidgets.QMessageBox.critical(None, self.tr("Error"), self.tr("Plant Cover start and end date cannot be the same.")) return self.close() crosses_180th, geojsons = self.aoi.bounding_box_gee_geojson() val = [] n = 1 if self.area_tab.area_fromfile.isChecked(): for f in self.aoi.get_layer_wgs84().getFeatures(): # Get an OGR geometry from the QGIS geometry geom = f.geometry() val.append(geom) n += 1 # stringify json object val_string = '{}'.format(json.loads(val[0].asJson())) # create ogr geometry val_geom = ogr.CreateGeometryFromJson(val_string) # simplify polygon to tolerance of 0.003 val_geom_simplified = val_geom.Simplify(0.003) # fetch coordinates from json coords= json.loads(val_geom_simplified.ExportToJson())['coordinates'] geometries = json.dumps([{ "coordinates":coords, "type":"Polygon" }]) elif self.area_tab.area_fromadmin.isChecked(): geometries =json.dumps([{ "coordinates":self.get_admin_poly_geojson()['geometry']['coordinates'][0], "type":"Polygon" }]) elif self.area_tab.area_frompoint.isChecked(): point = QgsPointXY(float(self.area_tab.area_frompoint_point_x.text()), float(self.area_tab.area_frompoint_point_y.text())) crs_src = QgsCoordinateReferenceSystem(self.area_tab.canvas.mapSettings().destinationCrs().authid()) point = QgsCoordinateTransform(crs_src, self.aoi.crs_dst, QgsProject.instance()).transform(point) geometries = json.dumps(json.loads(QgsGeometry.fromPointXY(point).asJson())) payload = {'ndvi_start':plant_start, 'ndvi_end': plant_end, 'year':'{}'.format(self.vqi_setup_tab.use_esa_tg_year.date().year()), 'drought_matrix':self.vqi_setup_tab.dlg_drought_agg.get_agg_as_list()[1], 'fire_matrix':self.vqi_setup_tab.dlg_fire_agg.get_agg_as_list()[1], 'erosion_matrix':self.vqi_setup_tab.dlg_erosion_agg.get_agg_as_list()[1], 'geojsons': geometries, 'crs': self.aoi.get_crs_dst_wkt(), 'crosses_180th': crosses_180th, 'task_name': self.options_tab.task_name.text(), 'task_notes': self.options_tab.task_notes.toPlainText()} # log("Payload: {}".format(payload)) resp = run_script(get_script_slug('vegetation-quality'), payload) if resp: mb.pushMessage(QtWidgets.QApplication.translate("MISLAND", "Submitted"), QtWidgets.QApplication.translate("MISLAND", "Vegetation Quality task submitted to Google Earth Engine."), level=0, duration=5) else: mb.pushMessage(QtWidgets.QApplication.translate("MISLAND", "Error"), QtWidgets.QApplication.translate("MISLAND", "Unable to submit vegation quality task to Google Earth Engine."), level=0, duration=5)
def calculate_on_GEE(self, method, biomass_data): self.close() crosses_180th, geojsons = self.aoi.bounding_box_gee_geojson() val = [] n = 1 if self.area_tab.area_fromfile.isChecked(): for f in self.aoi.get_layer_wgs84().getFeatures(): # Get an OGR geometry from the QGIS geometry geom = f.geometry() val.append(geom) n += 1 # stringify json object val_string = '{}'.format(json.loads(val[0].asJson())) # create ogr geometry val_geom = ogr.CreateGeometryFromJson(val_string) # simplify polygon to tolerance of 0.003 val_geom_simplified = val_geom.Simplify(0.003) # fetch coordinates from json coords = json.loads( val_geom_simplified.ExportToJson())['coordinates'] geometries = json.dumps([{ "coordinates": coords, "type": "Polygon" }]) elif self.area_tab.area_fromadmin.isChecked(): geometries = json.dumps([{ "coordinates": self.get_admin_poly_geojson()['geometry']['coordinates'][0], "type": "Polygon" }]) elif self.area_tab.area_frompoint.isChecked(): point = QgsPointXY( float(self.area_tab.area_frompoint_point_x.text()), float(self.area_tab.area_frompoint_point_y.text())) crs_src = QgsCoordinateReferenceSystem( self.area_tab.canvas.mapSettings().destinationCrs().authid()) point = QgsCoordinateTransform( crs_src, self.aoi.crs_dst, QgsProject.instance()).transform(point) geometries = json.dumps( json.loads(QgsGeometry.fromPointXY(point).asJson())) payload = { 'year_start': self.hansen_bl_year.date().year(), 'year_end': self.hansen_tg_year.date().year(), 'fc_threshold': int(self.hansen_fc_threshold.text().replace('%', '')), 'method': method, 'biomass_data': biomass_data, # 'geojsons':json.dumps(geojsons), 'geojsons': geometries, 'crs': self.aoi.get_crs_dst_wkt(), 'crosses_180th': crosses_180th, 'task_name': self.options_tab.task_name.text(), 'task_notes': self.options_tab.task_notes.toPlainText() } resp = run_script(get_script_slug('total-carbon'), payload) if resp: mb.pushMessage( QtWidgets.QApplication.translate("MISLAND", "Submitted"), QtWidgets.QApplication.translate( "MISLAND", "Total carbon submitted to Google Earth Engine."), level=0, duration=5) else: mb.pushMessage( QtWidgets.QApplication.translate("MISLAND", "Error"), QtWidgets.QApplication.translate( "MISLAND", "Unable to submit total carbon task to Google Earth Engine." ), level=0, duration=5)
def calculate_on_GEE(self): self.close() crosses_180th, geojsons = self.aoi.bounding_box_gee_geojson() # val = [] # n = 1 # if self.area_tab.area_fromfile.isChecked(): # for f in self.aoi.get_layer_wgs84().getFeatures(): # # Get an OGR geometry from the QGIS geometry # geom = f.geometry() # val.append(geom) # n += 1 # # stringify json object # val_string = '{}'.format(json.loads(val[0].asJson())) # # create ogr geometry # val_geom = ogr.CreateGeometryFromJson(val_string) # # simplify polygon to tolerance of 0.003 # val_geom_simplified = val_geom.Simplify(0.003) # # fetch coordinates from json # coords= json.loads(val_geom_simplified.ExportToJson())['coordinates'] # geometries = json.dumps([{ # "coordinates":coords # }]) # elif self.area_tab.area_fromadmin.isChecked(): # geometries =json.dumps([{"coordinates":self.get_admin_poly_geojson()['geometry']['coordinates'][0]}]) # elif self.area_tab.area_frompoint.isChecked(): # point = QgsPointXY(float(self.area_tab.area_frompoint_point_x.text()), float(self.area_tab.area_frompoint_point_y.text())) # crs_src = QgsCoordinateReferenceSystem(self.area_tab.canvas.mapSettings().destinationCrs().authid()) # point = QgsCoordinateTransform(crs_src, self.aoi.crs_dst, QgsProject.instance()).transform(point) # geometries = json.dumps(json.loads(QgsGeometry.fromPointXY(point).asJson())) payload = {'un_adju': self.get_pop_def_is_un(), 'isi_thr': self.spinBox_isi_thr.value(), 'ntl_thr': self.spinBox_ntl_thr.value(), 'wat_thr': self.spinBox_wat_thr.value(), 'cap_ope': self.spinBox_cap_ope.value(), 'pct_suburban': self.spinBox_pct_suburban.value()/100., 'pct_urban': self.spinBox_pct_urban.value()/100., # 'geojsons': geometries, 'geojsons':json.dumps(geosjsons) 'crs': self.aoi.get_crs_dst_wkt(), 'crosses_180th': crosses_180th, 'task_name': self.options_tab.task_name.text(), 'task_notes': self.options_tab.task_notes.toPlainText()} resp = run_script(get_script_slug('urban-area'), payload) if resp: mb.pushMessage(QtWidgets.QApplication.translate("MISLAND", "Submitted"), QtWidgets.QApplication.translate("MISLAND", "Urban area change calculation submitted to Google Earth Engine."), level=0, duration=5) else: mb.pushMessage(QtWidgets.QApplication.translate("MISLAND", "Error"), QtWidgets.QApplication.translate("MISLAND", "Unable to submit urban area task to Google Earth Engine."), level=0, duration=5)