diff --git a/src/qgis_gea_plugin/data/report_templates/project_instance.qpt b/src/qgis_gea_plugin/data/report_templates/project_instance.qpt old mode 100644 new mode 100755 index 8e55365..ca4bb7c --- a/src/qgis_gea_plugin/data/report_templates/project_instance.qpt +++ b/src/qgis_gea_plugin/data/report_templates/project_instance.qpt @@ -1,28 +1,28 @@ - - - + + + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -94,50 +152,50 @@ - - - + + + - + - + @@ -152,9 +210,9 @@ @@ -162,140 +220,346 @@ - - - + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -310,53 +574,53 @@ - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -837,17 +1148,17 @@ - + - - - + + + @@ -855,17 +1166,17 @@ - + - - - + + + @@ -873,17 +1184,17 @@ - + - - - + + + @@ -891,17 +1202,17 @@ - + - - - + + + @@ -909,17 +1220,17 @@ - + - - - + + + @@ -927,17 +1238,17 @@ - + - - - + + + @@ -945,17 +1256,17 @@ - + - - - + + + @@ -963,17 +1274,17 @@ - + - - - + + + @@ -981,17 +1292,17 @@ - + - - - + + + @@ -999,17 +1310,17 @@ - + - - - + + + @@ -1017,17 +1328,17 @@ - + - - - + + + @@ -1035,17 +1346,17 @@ - + - - - + + + @@ -1053,17 +1364,17 @@ - + - - - + + + @@ -1071,17 +1382,17 @@ - + - - - + + + @@ -1089,144 +1400,234 @@ - + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + + + + + + + + + + + + + + + + + + + + GEOGCRS["WGS 84",ENSEMBLE["World Geodetic System 1984 ensemble",MEMBER["World Geodetic System 1984 (Transit)"],MEMBER["World Geodetic System 1984 (G730)"],MEMBER["World Geodetic System 1984 (G873)"],MEMBER["World Geodetic System 1984 (G1150)"],MEMBER["World Geodetic System 1984 (G1674)"],MEMBER["World Geodetic System 1984 (G1762)"],ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ENSEMBLEACCURACY[2.0]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],USAGE[SCOPE["Horizontal component of 3D system."],AREA["World."],BBOX[-90,-180,90,180]],ID["EPSG",4326]] @@ -1241,48 +1642,48 @@ - + - + - + - + diff --git a/src/qgis_gea_plugin/data/report_templates/reforestation_site.qpt b/src/qgis_gea_plugin/data/report_templates/reforestation_site.qpt old mode 100644 new mode 100755 index bd5adf4..854a270 --- a/src/qgis_gea_plugin/data/report_templates/reforestation_site.qpt +++ b/src/qgis_gea_plugin/data/report_templates/reforestation_site.qpt @@ -1,28 +1,28 @@ - - - + + + - + - - - - - + + + - + - + @@ -94,50 +94,50 @@ - - - + + + - + - + @@ -152,9 +152,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -162,140 +220,346 @@ - - - + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -310,53 +574,53 @@ - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + + - + + + + + + + + + + + + + + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -838,17 +1148,17 @@ - + - - - + + + @@ -856,17 +1166,17 @@ - + - - - + + + @@ -874,17 +1184,17 @@ - + - - - + + + @@ -892,17 +1202,17 @@ - + - - - + + + @@ -910,17 +1220,17 @@ - + - - - + + + @@ -928,17 +1238,17 @@ - + - - - + + + @@ -946,17 +1256,17 @@ - + - - - + + + @@ -964,41 +1274,35 @@ - + - - - + + + - - - - - - - - + + - - - + + + @@ -1006,17 +1310,17 @@ - + - - - + + + @@ -1024,17 +1328,17 @@ - + - - - + + + @@ -1042,65 +1346,53 @@ - + - - - + + + - - - - - - - - + + - - - + + + - - - - - - - - + + - - - + + + @@ -1108,17 +1400,17 @@ - + - - - + + + @@ -1126,17 +1418,17 @@ - + - - - + + + @@ -1144,41 +1436,35 @@ - + - - - + + + - - - - - - - - + + - - - + + + @@ -1186,164 +1472,290 @@ - + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - - - + + + - - + + + + + + + + - - - + + + - - - - GEOGCRS["WGS 84",ENSEMBLE["World Geodetic System 1984 ensemble",MEMBER["World Geodetic System 1984 (Transit)"],MEMBER["World Geodetic System 1984 (G730)"],MEMBER["World Geodetic System 1984 (G873)"],MEMBER["World Geodetic System 1984 (G1150)"],MEMBER["World Geodetic System 1984 (G1674)"],MEMBER["World Geodetic System 1984 (G1762)"],ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ENSEMBLEACCURACY[2.0]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],USAGE[SCOPE["Horizontal component of 3D system."],AREA["World."],BBOX[-90,-180,90,180]],ID["EPSG",4326]] - +proj=longlat +datum=WGS84 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - EPSG:7030 - true - - + - + - + - + - - - + + + - - + + + + + + + + - - - + + + - - + + + + + + + + - - - + + + - - + + + + + + + + - - - + + + - - + + + + + + + + + + + + + + + + + + + + + + + GEOGCRS["WGS 84",ENSEMBLE["World Geodetic System 1984 ensemble",MEMBER["World Geodetic System 1984 (Transit)"],MEMBER["World Geodetic System 1984 (G730)"],MEMBER["World Geodetic System 1984 (G873)"],MEMBER["World Geodetic System 1984 (G1150)"],MEMBER["World Geodetic System 1984 (G1674)"],MEMBER["World Geodetic System 1984 (G1762)"],ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ENSEMBLEACCURACY[2.0]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],USAGE[SCOPE["Horizontal component of 3D system."],AREA["World."],BBOX[-90,-180,90,180]],ID["EPSG",4326]] + +proj=longlat +datum=WGS84 +no_defs + 3452 + 4326 + EPSG:4326 + WGS 84 + longlat + EPSG:7030 + true + + + + + + + + + - + diff --git a/src/qgis_gea_plugin/definitions/defaults.py b/src/qgis_gea_plugin/definitions/defaults.py index 957853d..4607fbe 100644 --- a/src/qgis_gea_plugin/definitions/defaults.py +++ b/src/qgis_gea_plugin/definitions/defaults.py @@ -64,6 +64,8 @@ SITE_GROUP_NAME = "Drawn Areas of Interest" PROJECT_INSTANCES_GROUP_NAME = "Project Instances" +NICFI_2018_LAYER_NAME = 'PS Tropical Visual Biannual Archive - December 2018' + SITE_REPORT_TEMPLATE_NAME = "reforestation_site.qpt" PROJECT_INSTANCE_REPORT_TEMPLATE_NAME = "project_instance.qpt" diff --git a/src/qgis_gea_plugin/lib/reports/generator.py b/src/qgis_gea_plugin/lib/reports/generator.py index 18369b5..a41316b 100644 --- a/src/qgis_gea_plugin/lib/reports/generator.py +++ b/src/qgis_gea_plugin/lib/reports/generator.py @@ -36,7 +36,9 @@ LANDSAT_IMAGERY_GROUP_NAME, OVERVIEW_ZOOM_OUT_FACTOR, REPORT_SITE_BOUNDARY_STYLE, - PROJECT_INSTANCE_STYLE + PROJECT_INSTANCE_STYLE, + RECENT_IMAGERY_GROUP_NAME, + NICFI_2018_LAYER_NAME ) from ...models.base import LayerNodeSearch from ...models.report import ( @@ -50,6 +52,13 @@ tr, ) +try: + from planet_explorer.planet_api import PlanetClient +except ImportError: + log( + f"Couldn't import planet api. " + f"Check if planet plugin has been installed." + ) class SiteReportReportGeneratorTask(QgsTask): """Class for generating the site report.""" @@ -476,43 +485,6 @@ def _set_landscape_layer(self): """Set the landscape layer i.e. Nicfi or Landsat depending on the information in the TemporalInfo object. """ - # For now, we are only interested in Landsat 2013 - # hence the commented code. - # if self._context.temporal_info.image_type == IMAGERY.NICFI: - # group_name = RECENT_IMAGERY_GROUP_NAME - # elif self._context.temporal_info.image_type == IMAGERY.HISTORICAL: - # group_name = LANDSAT_IMAGERY_GROUP_NAME - # else: - # group_name = "" - # - # if not group_name: - # tr_msg = tr("Landscape group name could not be determined") - # self._error_messages.append(tr_msg) - # return - # - # layers = self._get_layers_in_group(group_name) - # if len(layers) == 0: - # tr_msg = tr("No layers in landscape group") - # self._error_messages.append(f"{tr_msg}: {group_name}") - # return - # - # # Search corresponding layers - # for layer in layers: - # temporal_properties = layer.temporalProperties() - # if temporal_properties is None: - # continue - # - # if not temporal_properties.isActive(): - # continue - # - # if not isinstance(layer, QgsRasterLayer): - # continue - # - # temporal_range = temporal_properties.fixedTemporalRange() - # if temporal_range == self._context.temporal_info.date_range: - # self._landscape_layer = layer - # - # break landsat_2013_layer = self._get_layer_from_node_name( LANDSAT_2013_LAYER_SEGMENT, @@ -569,8 +541,10 @@ def _configure_landscape_maps( ) self._error_messages.append(tr_msg) + nicifi_imagery_layers = self._get_layers_in_group(RECENT_IMAGERY_GROUP_NAME) + # landscape layer with mask map - historic_mask_map = self._get_map_item_by_id("historic_mask_map") + historic_mask_map = self._get_map_item_by_id("2013_historic_mask_map") if historic_mask_map and detailed_extent: # Transform extent landscape_imagery_extent = self._transform_extent( @@ -597,7 +571,7 @@ def _configure_landscape_maps( historic_mask_map.refresh() # Landscape with no-mask map - landscape_no_mask_map = self._get_map_item_by_id("historic_no_mask_map") + landscape_no_mask_map = self._get_map_item_by_id("2013_historic_no_mask_map") if landscape_no_mask_map and detailed_extent: # Transform extent landscape_no_mask_extent = self._transform_extent( @@ -623,6 +597,143 @@ def _configure_landscape_maps( landscape_no_mask_map.zoomToExtent(landscape_no_mask_extent) landscape_no_mask_map.refresh() + # landscape layer with mask map + historic_mask_map = self._get_map_item_by_id("2018_historic_mask_map") + if historic_mask_map and detailed_extent: + # Transform extent + landscape_imagery_extent = self._transform_extent( + detailed_extent, + self._site_layer.crs(), + historic_mask_map.crs() + ) + + if landscape_imagery_extent.isNull(): + tr_msg = tr( + "Invalid extent for setting in the current imagery " + "with mask map" + ) + self._error_messages.append(tr_msg) + else: + nicfi_2018_layer = None + for layer in nicifi_imagery_layers: + if layer.name() == NICFI_2018_LAYER_NAME: + nicfi_2018_layer = layer + break + + has_api_key = PlanetClient.getInstance().has_api_key() + if not has_api_key: + log( + f"Warning user not logged in a Planet account. " + f"Some of the layout maps won't " + f"contain background imagery." + ) + + api_key = ( + PlanetClient.getInstance().api_key() + if has_api_key + else '' + ) + + nicfi_source = nicfi_2018_layer.source() + source = nicfi_source + + if "api_key%3D&" in nicfi_source: + source = nicfi_source.replace( + "api_key%3D", + f"api_key={api_key}" + ) + + nicfi_tile_layer = QgsRasterLayer( + f"{source}", + "Planet Mosaic 2018", + "wms" + ) + QgsProject.instance().addMapLayers([nicfi_tile_layer]) + + landscape_mask_layers = [self._site_layer, nicfi_tile_layer] + landscape_mask_layers.extend(mask_layers) + + if self._landscape_layer is not None: + landscape_mask_layers.append(self._landscape_layer) + + historic_mask_map.setFollowVisibilityPreset(False) + historic_mask_map.setFollowVisibilityPresetName("") + historic_mask_map.setLayers(landscape_mask_layers) + historic_mask_map.zoomToExtent(landscape_imagery_extent) + historic_mask_map.refresh() + + QgsProject.instance().removeMapLayer(nicfi_tile_layer.id()) + + # Landscape with no-mask map + landscape_no_mask_map = self._get_map_item_by_id("2018_historic_no_mask_map") + if landscape_no_mask_map and detailed_extent: + # Transform extent + landscape_no_mask_extent = self._transform_extent( + detailed_extent, + self._site_layer.crs(), + landscape_no_mask_map.crs() + ) + + if landscape_no_mask_extent.isNull(): + tr_msg = tr( + "Invalid extent for setting in the landscape imagery " + "with no-mask map" + ) + self._error_messages.append(tr_msg) + else: + nicfi_2018_layer = None + for layer in nicifi_imagery_layers: + if layer.name() == NICFI_2018_LAYER_NAME: + nicfi_2018_layer = layer + break + + has_api_key = PlanetClient.getInstance().has_api_key() + if not has_api_key: + log( + f"Warning user not logged in a Planet account. " + f"Some of the layout maps won't " + f"contain background imagery." + ) + + api_key = ( + PlanetClient.getInstance().api_key() + if has_api_key + else '' + ) + + nicfi_source = nicfi_2018_layer.source() + source = nicfi_source + + if "api_key%3D&" in nicfi_source: + source = nicfi_source.replace( + "api_key%3D", + f"api_key={api_key}" + ) + + nicfi_tile_layer = QgsRasterLayer( + f"{source}", + "Planet Mosaic 2018", + "wms" + ) + QgsProject.instance().addMapLayers([nicfi_tile_layer]) + + landscape_no_mask_layers = [ + self._site_layer, + nicfi_tile_layer + ] + + if self._landscape_layer is not None: + landscape_no_mask_layers.append(self._landscape_layer) + + landscape_no_mask_map.setFollowVisibilityPreset(False) + landscape_no_mask_map.setFollowVisibilityPresetName("") + landscape_no_mask_map.setLayers(landscape_no_mask_layers) + landscape_no_mask_map.zoomToExtent(landscape_no_mask_extent) + landscape_no_mask_map.refresh() + + QgsProject.instance().removeMapLayer(nicfi_tile_layer.id()) + + def _configure_current_maps( self, detailed_extent: QgsRectangle,