From f3281bc28aa9430eab010646e0268461da40ff00 Mon Sep 17 00:00:00 2001 From: Samweli Date: Tue, 10 Dec 2024 15:47:48 +0300 Subject: [PATCH 1/6] update report templates --- .../report_templates/project_instance.qpt | 1579 +++++++++------ .../report_templates/reforestation_site.qpt | 1698 ++++++++++------- 2 files changed, 2042 insertions(+), 1235 deletions(-) mode change 100644 => 100755 src/qgis_gea_plugin/data/report_templates/project_instance.qpt mode change 100644 => 100755 src/qgis_gea_plugin/data/report_templates/reforestation_site.qpt 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..0e50727 --- 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 @@ - - - + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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,18 +1636,18 @@ - + - + - + - - + 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..fa6d388 --- 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 @@ - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - - - - - - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - - - - - - - + + - - - + + + - - - - - - - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - + + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - - - + + + - - + + + + + + + + - - - + + + - - - - 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 + + + + + + + + + - + From c41a319efd0a0507eb0f5c071884998a0d451a70 Mon Sep 17 00:00:00 2001 From: Samweli Date: Tue, 10 Dec 2024 19:08:59 +0300 Subject: [PATCH 2/6] include 2013 and 2018 maps --- src/qgis_gea_plugin/lib/reports/generator.py | 59 +++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/qgis_gea_plugin/lib/reports/generator.py b/src/qgis_gea_plugin/lib/reports/generator.py index 18369b5..3b7b82c 100644 --- a/src/qgis_gea_plugin/lib/reports/generator.py +++ b/src/qgis_gea_plugin/lib/reports/generator.py @@ -570,7 +570,7 @@ def _configure_landscape_maps( self._error_messages.append(tr_msg) # 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 +597,62 @@ 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( + 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: + landscape_no_mask_layers = [self._site_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() + + + # 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: + landscape_mask_layers = [self._site_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() + + # 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( From 147419019d1f482093fa7f6ad61cbd11d22b1157 Mon Sep 17 00:00:00 2001 From: Samweli Date: Wed, 11 Dec 2024 09:25:59 +0300 Subject: [PATCH 3/6] adding check for 2018 nicfi imagery --- src/qgis_gea_plugin/lib/reports/generator.py | 28 +++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/qgis_gea_plugin/lib/reports/generator.py b/src/qgis_gea_plugin/lib/reports/generator.py index 3b7b82c..aaa439d 100644 --- a/src/qgis_gea_plugin/lib/reports/generator.py +++ b/src/qgis_gea_plugin/lib/reports/generator.py @@ -36,7 +36,7 @@ LANDSAT_IMAGERY_GROUP_NAME, OVERVIEW_ZOOM_OUT_FACTOR, REPORT_SITE_BOUNDARY_STYLE, - PROJECT_INSTANCE_STYLE + PROJECT_INSTANCE_STYLE, SATELLITE_IMAGERY ) from ...models.base import LayerNodeSearch from ...models.report import ( @@ -648,6 +648,32 @@ def _configure_landscape_maps( historic_mask_map.setFollowVisibilityPreset(False) historic_mask_map.setFollowVisibilityPresetName("") historic_mask_map.setLayers(landscape_mask_layers) + + start_date = QtCore.QDateTime.fromString("2018-12-01T00:00:00", "yyyy-MM-ddTHH:mm:ss") + end_date = QtCore.QDateTime.fromString("2018-12-31T23:59:59", "yyyy-MM-ddTHH:mm:ss") + + layers = historic_mask_map.layers() + for layer in layers: + + log(f"checking {layer.name()}") + + if (layer.temporalProperties() and + (layer.temporalProperties().fixedTemporalRange().begin().isValid() and + layer.temporalProperties().fixedTemporalRange().end().isValid()) + ): + + log(f"{layer.name()} has right temporal properties") + temporal_extent = layer.temporalProperties().fixedTemporalRange() + + visible = (temporal_extent.begin() >= start_date and + temporal_extent.end() <= end_date + ) + layer.setVisible(visible) + else: + log(f"NO temporal or valid properties in {layer.name()}") + if layer.name() == SATELLITE_IMAGERY: + layer.setVisible(False) + historic_mask_map.zoomToExtent(landscape_imagery_extent) historic_mask_map.refresh() From 67cf5a82528234cd647b528e31331c9b59663911 Mon Sep 17 00:00:00 2001 From: Samweli Date: Thu, 12 Dec 2024 01:12:13 +0300 Subject: [PATCH 4/6] include planet 2018 layer when creating reports --- src/qgis_gea_plugin/lib/reports/generator.py | 55 ++++++++++---------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/qgis_gea_plugin/lib/reports/generator.py b/src/qgis_gea_plugin/lib/reports/generator.py index aaa439d..d496074 100644 --- a/src/qgis_gea_plugin/lib/reports/generator.py +++ b/src/qgis_gea_plugin/lib/reports/generator.py @@ -641,41 +641,29 @@ def _configure_landscape_maps( ) self._error_messages.append(tr_msg) else: - landscape_mask_layers = [self._site_layer] + tile_url = \ + 'https://tiles.planet.com/basemaps/v1/' \ + 'planet-tiles/planet_medres_visual_' \ + '2018-12_2019-05_mosaic/gmap/{z}/{x}/{y}.'\ + 'png?api_key=' + layer_name = "Planet Mosaic (2018-12 to 2019-05)" + tile_layer = QgsRasterLayer(f"type=xyz&url={tile_url}", layer_name, "wms") + + QgsProject.instance().addMapLayers([tile_layer]) + + landscape_mask_layers = [self._site_layer, 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) - start_date = QtCore.QDateTime.fromString("2018-12-01T00:00:00", "yyyy-MM-ddTHH:mm:ss") - end_date = QtCore.QDateTime.fromString("2018-12-31T23:59:59", "yyyy-MM-ddTHH:mm:ss") - - layers = historic_mask_map.layers() - for layer in layers: - - log(f"checking {layer.name()}") - - if (layer.temporalProperties() and - (layer.temporalProperties().fixedTemporalRange().begin().isValid() and - layer.temporalProperties().fixedTemporalRange().end().isValid()) - ): + historic_mask_map.refresh() - log(f"{layer.name()} has right temporal properties") - temporal_extent = layer.temporalProperties().fixedTemporalRange() + QgsProject.instance().removeMapLayer(tile_layer.id()) - visible = (temporal_extent.begin() >= start_date and - temporal_extent.end() <= end_date - ) - layer.setVisible(visible) - else: - log(f"NO temporal or valid properties in {layer.name()}") - if layer.name() == SATELLITE_IMAGERY: - layer.setVisible(False) - - historic_mask_map.zoomToExtent(landscape_imagery_extent) - historic_mask_map.refresh() # Landscape with no-mask map landscape_no_mask_map = self._get_map_item_by_id("2018_historic_no_mask_map") @@ -694,7 +682,17 @@ def _configure_landscape_maps( ) self._error_messages.append(tr_msg) else: - landscape_no_mask_layers = [self._site_layer] + tile_url = \ + 'https://tiles.planet.com/basemaps/v1/' \ + 'planet-tiles/planet_medres_visual_' \ + '2018-12_2019-05_mosaic/gmap/{z}/{x}/{y}.'\ + 'png?api_key=' + layer_name = "Planet Mosaic (2018-12 to 2019-05)" + tile_layer = QgsRasterLayer(f"type=xyz&url={tile_url}", layer_name, "wms") + + QgsProject.instance().addMapLayers([tile_layer]) + + landscape_no_mask_layers = [self._site_layer, tile_layer] if self._landscape_layer is not None: landscape_no_mask_layers.append(self._landscape_layer) @@ -704,6 +702,9 @@ def _configure_landscape_maps( landscape_no_mask_map.zoomToExtent(landscape_no_mask_extent) landscape_no_mask_map.refresh() + QgsProject.instance().removeMapLayer(tile_layer.id()) + + def _configure_current_maps( self, detailed_extent: QgsRectangle, From d4cd64c380734fff7fc4f1162900e408bd3bbb34 Mon Sep 17 00:00:00 2001 From: Samweli Date: Fri, 13 Dec 2024 00:50:09 +0300 Subject: [PATCH 5/6] include 2018 nicfi imagery for the 2018 landscape map items --- src/qgis_gea_plugin/definitions/defaults.py | 2 + src/qgis_gea_plugin/lib/reports/generator.py | 151 +++++++++++-------- 2 files changed, 92 insertions(+), 61 deletions(-) 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 d496074..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, SATELLITE_IMAGERY + 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,6 +541,8 @@ 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("2013_historic_mask_map") if historic_mask_map and detailed_extent: @@ -623,7 +597,6 @@ 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: @@ -641,29 +614,55 @@ def _configure_landscape_maps( ) self._error_messages.append(tr_msg) else: - tile_url = \ - 'https://tiles.planet.com/basemaps/v1/' \ - 'planet-tiles/planet_medres_visual_' \ - '2018-12_2019-05_mosaic/gmap/{z}/{x}/{y}.'\ - 'png?api_key=' - layer_name = "Planet Mosaic (2018-12 to 2019-05)" - tile_layer = QgsRasterLayer(f"type=xyz&url={tile_url}", layer_name, "wms") + 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 - QgsProject.instance().addMapLayers([tile_layer]) + if "api_key%3D&" in nicfi_source: + source = nicfi_source.replace( + "api_key%3D", + f"api_key={api_key}" + ) - landscape_mask_layers = [self._site_layer, tile_layer] + 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(tile_layer.id()) - + 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") @@ -682,17 +681,47 @@ def _configure_landscape_maps( ) self._error_messages.append(tr_msg) else: - tile_url = \ - 'https://tiles.planet.com/basemaps/v1/' \ - 'planet-tiles/planet_medres_visual_' \ - '2018-12_2019-05_mosaic/gmap/{z}/{x}/{y}.'\ - 'png?api_key=' - layer_name = "Planet Mosaic (2018-12 to 2019-05)" - tile_layer = QgsRasterLayer(f"type=xyz&url={tile_url}", layer_name, "wms") + 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]) - QgsProject.instance().addMapLayers([tile_layer]) + landscape_no_mask_layers = [ + self._site_layer, + nicfi_tile_layer + ] - landscape_no_mask_layers = [self._site_layer, tile_layer] if self._landscape_layer is not None: landscape_no_mask_layers.append(self._landscape_layer) @@ -702,7 +731,7 @@ def _configure_landscape_maps( landscape_no_mask_map.zoomToExtent(landscape_no_mask_extent) landscape_no_mask_map.refresh() - QgsProject.instance().removeMapLayer(tile_layer.id()) + QgsProject.instance().removeMapLayer(nicfi_tile_layer.id()) def _configure_current_maps( From 4a80e395a1881a68a1aa25c0032e56114ef71919 Mon Sep 17 00:00:00 2001 From: Samweli Date: Fri, 13 Dec 2024 00:54:13 +0300 Subject: [PATCH 6/6] updated legend font size in the report templates --- .../report_templates/project_instance.qpt | 1320 ++++++++-------- .../report_templates/reforestation_site.qpt | 1366 ++++++++--------- 2 files changed, 1346 insertions(+), 1340 deletions(-) diff --git a/src/qgis_gea_plugin/data/report_templates/project_instance.qpt b/src/qgis_gea_plugin/data/report_templates/project_instance.qpt index 0e50727..ca4bb7c 100755 --- 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 +94,50 @@ - - - + + + - + - + @@ -152,50 +152,50 @@ - - - + + + - + - + @@ -210,9 +210,9 @@ @@ -220,42 +220,42 @@ - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + 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]] @@ -1636,33 +1642,33 @@ - + - + - + - - + diff --git a/src/qgis_gea_plugin/data/report_templates/reforestation_site.qpt b/src/qgis_gea_plugin/data/report_templates/reforestation_site.qpt index fa6d388..854a270 100755 --- 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,50 +152,50 @@ - - - + + + - + - + @@ -210,9 +210,9 @@ @@ -220,42 +220,42 @@ - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - + - - - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - - + + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + - + - + - + - - - + + + - + 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]] @@ -1744,18 +1744,18 @@ - + - + - + - +