import os import re import uuid from datetime import datetime, timezone import fiona from pyproj import CRS, Transformer # --------------------------------------------------------------------- # Load GPKG and extract info # --------------------------------------------------------------------- script_dir = os.path.dirname(os.path.abspath(__file__)) for filename in os.listdir(script_dir): if filename.endswith(".gpkg") or filename.endswith(".gdb"): gpkg_path = os.path.join(script_dir, filename) print(f"Found data file: {gpkg_path}") break else: raise FileNotFoundError("No GPKG or GDB file found in the script directory.") # Read layers layers = fiona.listlayers(gpkg_path) # Find CLC layer clc_layers = [lyr for lyr in layers if lyr.startswith("clc24_")] if not clc_layers: raise ValueError("No layer starting with 'clc24_' found in the GPKG.") if len(clc_layers) > 1: print(f"WARNING: multiple clc24_* layers found {clc_layers}, using the first one.") layer_name = clc_layers[0] print(f"Detected layer: {layer_name}") # Extract aoicode (everything after "clc24_") m = re.match(r"clc24_(.+)", layer_name) if not m: raise ValueError("Could not extract AOI code from layer name.") aoicode = m.group(1).lower() # -------------------------------------------------- # Extract bounding box and CRS of the layer # -------------------------------------------------- with fiona.open(gpkg_path, layer=layer_name) as src: minx, miny, maxx, maxy = src.bounds src_crs = CRS(src.crs) epsg = src_crs.to_epsg() if epsg is None: raise ValueError("Layer CRS has no EPSG code") # -------------------------------------------------- # Transform bbox → EPSG:4326 (INSPIRE requirement) # -------------------------------------------------- transformer = Transformer.from_crs(src_crs, CRS.from_epsg(4326), always_xy=True) # transform_bounds densifies the bbox edges, giving a correct WGS84 # envelope for projected CRS (corner-only transforms can underestimate it) west, south, east, north = transformer.transform_bounds(minx, miny, maxx, maxy) print("Bounding box:", west, south, east, north) print("EPSG:", epsg) print("AOICODE:", aoicode) # --------------------------------------------------------------------- # Ask for user email # --------------------------------------------------------------------- email = input("Enter contact e-mail: ").strip() # --------------------------------------------------------------------- # Determine Country Name from AOICODE # --------------------------------------------------------------------- AOI_COUNTRY = { "al": "Albania", "at": "Austria", "ba": "Bosnia and Herzegovina", "be": "Belgium", "bg": "Bulgaria", "ch": "Switzerland", "cy": "Cyprus", "cz": "Czech Republic", "de": "Germany", "dk": "Denmark", "dk_fo": "Faroe Islands", "ee": "Estonia", "es": "Spain", "es_cn": "Canary Islands", "fi": "Finland", "fr": "France", "fr_glp": "Guadeloupe", "fr_guf": "French Guiana", "fr_mtq": "Martinique", "fr_myt": "Mayotte", "fr_reu": "Réunion", "gr": "Greece", "hr": "Croatia", "hu": "Hungary", "ie": "Ireland", "is": "Iceland", "it": "Italy", "li": "Liechtenstein", "lt": "Lithuania", "lu": "Luxembourg", "lv": "Latvia", "md": "Moldova", "me": "Montenegro", "mk": "North Macedonia", "mt": "Malta", "nl": "Netherlands", "no": "Norway", "pl": "Poland", "pt": "Portugal", "pt_ram": "Madeira", "pt_raa_ceg": "Azores (Central Group)", "pt_raa_weg": "Azores (Western Group)", "ro": "Romania", "rs": "Serbia", "se": "Sweden", "si": "Slovenia", "sk": "Slovakia", "tr": "Turkey", "uk_gb": "United Kingdom", "uk_ni": "Northern Ireland", "uk_gg": "Guernsey", "uk_je": "Jersey", "xk": "Kosovo" } country = AOI_COUNTRY.get(aoicode, aoicode) # --------------------------------------------------------------------- # XML TEMPLATE (placeholders) # --------------------------------------------------------------------- xml_template_reference = """ {file_uuid} National CLC team contact {email} {date_stamp} ISO 19115/19139 1.0 EPSG:{epsg_code} CORINE Land Cover 2024 (vector), {country_name} ({aoicode}) - National Data Extract, 6-yearly - version 2025_v01_r01, November 2025 2025-12-01 21.0 copernicus-{aoicode_lower}_v_{epsg_code}_100_m_clc-2024_p_2024_v01_r01 Corine Land Cover 2024 (CLC2024) is one of the Corine Land Cover (CLC) datasets produced within the frame the Copernicus Land Monitoring Service referring to land cover / land use status of year 2024. CLC service has a long-time heritage (formerly known as "CORINE Land Cover Programme"), coordinated by the European Environment Agency (EEA). It provides consistent and thematically detailed information on land cover and land cover changes across Europe. CLC datasets are based on the classification of satellite images produced by the national teams of the participating countries - the EEA members and cooperating countries (EEA39). National CLC inventories are then further integrated into a seamless land cover map of Europe. The resulting European database relies on standard methodology and nomenclature with following base parameters: 44 classes in the hierarchical 3-level CLC nomenclature; minimum mapping unit (MMU) for status layers is 25 hectares; minimum width of linear elements is 100 metres. Change layers have higher resolution, i.e. minimum mapping unit (MMU) is 5 hectares for Land Cover Changes (LCC), and the minimum width of linear elements is 100 metres. The CLC service delivers important data sets supporting the implementation of key priority areas of the Environment Action Programmes of the European Union as e.g. protecting ecosystems, halting the loss of biological diversity, tracking the impacts of climate change, monitoring urban land take, assessing developments in agriculture or dealing with water resources directives. CLC belongs to the Pan-European component of the Copernicus Land Monitoring Service (https://land.copernicus.eu/), part of the European Copernicus Programme coordinated by the European Environment Agency, providing environmental information from a combination of air- and space-based observation systems and in-situ monitoring. Additional information about CLC product description including mapping guides can be found at https://land.copernicus.eu/user-corner/technical-library/. CLC class descriptions can be found at https://land.copernicus.eu/user-corner/technical-library/corine-land-cover-nomenclature-guidelines/html/. National CLC team contact {email} P6Y0M0DT0H0M0S Land cover Land use GEMET - INSPIRE themes, version 1.0 2008-06-01 geonetwork.thesaurus.external.theme.httpinspireeceuropaeutheme-theme {country_name} Countries Continents, countries, sea regions of the world. 2015-07-17 geonetwork.thesaurus.external.place.regions land cover land use landscape landscape alteration land GEMET 2021-11-30 geonetwork.thesaurus.external.theme.gemet European Spatial scope 2019-05-22 geonetwork.thesaurus.external.theme.httpinspireeceuropaeumetadatacodelistSpatialScope-SpatialScope 2013 2.6.1 Land use EEA topics 2022-10-18 2020-09-24 geonetwork.thesaurus.external.theme.eea-topics land change 2024 EEA keyword list 2002-03-01 no limitations to public access Access to data is based on a principle of full, open and free access as established by the Copernicus data and information policy Regulation (EU) No 1159/2013 of 12 July 2013. This regulation establishes registration and licensing conditions for GMES/Copernicus users. Free, full and open access to this data set is made on the conditions that: 1. When distributing or communicating Copernicus dedicated data and Copernicus service information to the public, users shall inform the public of the source of that data and information. 2. Users shall make sure not to convey the impression to the public that the user's activities are officially endorsed by the Union. 3. Where that data or information has been adapted or modified, the user shall clearly state this. 4. The data remain the sole property of the European Union. Any information and data produced in the framework of the action shall be the sole property of the European Union. Any communication and publication by the beneficiary shall acknowledge that the data were produced “with funding by the European Union”. 100 environment imageryBaseMapsEarthCover {west} {east} {south} {north} 2023-01-01 2024-12-31 {format_name} Commission Regulation (EU) No 1089/2010 of 23 November 2010 implementing Directive 2007/2/EC of the European Parliament and of the Council as regards interoperability of spatial data sets and services 2010-12-08 See the referenced specification Minimum Mapping Unit ha 25 Minimum Mapping Width m 100 The national team mapped the land cover changes (2018–2024) and, based on the initial 2018 layer and those changes, created the 2024 land cover status layer (CLC24). The CLC24 layer was validated within the QC tool as part of the CLC 2024 national delivery. """ xml_template_initial = """ {file_uuid} National CLC team contact {email} {date_stamp} ISO 19115/19139 1.0 EPSG:{epsg_code} CORINE Land Cover 2018 (vector), {country_name} ({country_code}) - Revised National Data Extract, 6-yearly - version 2025_v01_r01, November 2025 2025-12-01 21.0 copernicus-{country_code}_v_{epsg_code}_100_m_clc-2018_p_2017-2018_v01_r01 Corine Land Cover 2018 (CLC2018) is one of the Corine Land Cover (CLC) datasets produced within the frame the Copernicus Land Monitoring Service referring to land cover / land use status of year 2018. CLC service has a long-time heritage (formerly known as "CORINE Land Cover Programme"), coordinated by the European Environment Agency (EEA). It provides consistent and thematically detailed information on land cover and land cover changes across Europe. CLC datasets are based on the classification of satellite images produced by the national teams of the participating countries - the EEA members and cooperating countries (EEA39). National CLC inventories are then further integrated into a seamless land cover map of Europe. The resulting European database relies on standard methodology and nomenclature with following base parameters: 44 classes in the hierarchical 3-level CLC nomenclature; minimum mapping unit (MMU) for status layers is 25 hectares; minimum width of linear elements is 100 metres. Change layers have higher resolution, i.e. minimum mapping unit (MMU) is 5 hectares for Land Cover Changes (LCC), and the minimum width of linear elements is 100 metres. The CLC service delivers important data sets supporting the implementation of key priority areas of the Environment Action Programmes of the European Union as e.g. protecting ecosystems, halting the loss of biological diversity, tracking the impacts of climate change, monitoring urban land take, assessing developments in agriculture or dealing with water resources directives. CLC belongs to the Pan-European component of the Copernicus Land Monitoring Service (https://land.copernicus.eu/), part of the European Copernicus Programme coordinated by the European Environment Agency, providing environmental information from a combination of air- and space-based observation systems and in-situ monitoring. Additional information about CLC product description including mapping guides can be found at https://land.copernicus.eu/user-corner/technical-library/. CLC class descriptions can be found at https://land.copernicus.eu/user-corner/technical-library/corine-land-cover-nomenclature-guidelines/html/. National CLC team contact {email} P6Y0M0DT0H0M0S Land cover Land use GEMET - INSPIRE themes, version 1.0 2008-06-01 geonetwork.thesaurus.external.theme.httpinspireeceuropaeutheme-theme {country_name} Countries Continents, countries, sea regions of the world. 2015-07-17 geonetwork.thesaurus.external.place.regions land cover land use landscape landscape alteration land GEMET 2021-11-30 geonetwork.thesaurus.external.theme.gemet European Spatial scope 2019-05-22 geonetwork.thesaurus.external.theme.httpinspireeceuropaeumetadatacodelistSpatialScope-SpatialScope 2013 2.6.1 Land use EEA topics 2022-10-18 2020-09-24 geonetwork.thesaurus.external.theme.eea-topics land change 2018 EEA keyword list 2002-03-01 no limitations to public access Access to data is based on a principle of full, open and free access as established by the Copernicus data and information policy Regulation (EU) No 1159/2013 of 12 July 2013. This regulation establishes registration and licensing conditions for GMES/Copernicus users. Free, full and open access to this data set is made on the conditions that: 1. When distributing or communicating Copernicus dedicated data and Copernicus service information to the public, users shall inform the public of the source of that data and information. 2. Users shall make sure not to convey the impression to the public that the user's activities are officially endorsed by the Union. 3. Where that data or information has been adapted or modified, the user shall clearly state this. 4. The data remain the sole property of the European Union. Any information and data produced in the framework of the action shall be the sole property of the European Union. Any communication and publication by the beneficiary shall acknowledge that the data were produced “with funding by the European Union”. 100 environment imageryBaseMapsEarthCover {west} {east} {south} {north} 2017-01-01 2018-12-31 {format_name} Commission Regulation (EU) No 1089/2010 of 23 November 2010 implementing Directive 2007/2/EC of the European Parliament and of the Council as regards interoperability of spatial data sets and services 2010-12-08 See the referenced specification Minimum Mapping Unit ha 25 Minimum Mapping Width m 100 The CLC2018 extract was derived from the CLC2018 European product, reprojected to the local projection, and sent to the national team. The national team subsequently revised the data and validated the 2018 layer within the QC tool as part of the CLC 2024 national delivery. """ xml_template_change = """ {file_uuid} National CLC team contact {email} {date_stamp} ISO 19115/19139 1.0 EPSG:{epsg_code} CORINE Land Cover Change 2018-2024 (vector), {country_name} ({aoicode}) - National Data Extract, 6-yearly - version 2025_v01_r01, Nov 2025 2025-12-01 21.0 copernicus-{aoicode_lower}_v_{epsg_code}_100_m_cha1824_p_2018-2024_v01_r01 Corine Land Cover Change 2018-2024 (CHA1824) is one of the Corine Land Cover (CLC) datasets produced within the frame the Copernicus Land Monitoring Service referring to changes in land cover / land use status between the years 2018 and 2024. CLC service has a long-time heritage (formerly known as "CORINE Land Cover Programme"), coordinated by the European Environment Agency (EEA). It provides consistent and thematically detailed information on land cover and land cover changes across Europe. CLC datasets are based on the classification of satellite images produced by the national teams of the participating countries - the EEA members and cooperating countries (EEA39). National CLC inventories are then further integrated into a seamless land cover map of Europe. The resulting European database relies on standard methodology and nomenclature with following base parameters: 44 classes in the hierarchical 3-level CLC nomenclature; minimum mapping unit (MMU) for status layers is 25 hectares; minimum width of linear elements is 100 metres. Change layers have higher resolution, i.e. minimum mapping unit (MMU) is 5 hectares for Land Cover Changes (CHA), and the minimum width of linear elements is 100 metres. The CLC service delivers important data sets supporting the implementation of key priority areas of the Environment Action Programmes of the European Union as e.g. protecting ecosystems, halting the loss of biological diversity, tracking the impacts of climate change, monitoring urban land take, assessing developments in agriculture or dealing with water resources directives. part of the European Copernicus Programme coordinated by the European Environment Agency, providing environmental information from a combination of air- and space-based observation systems and in-situ monitoring. National CLC team contact {email} P6Y0M0DT0H0M0S Land cover Land use GEMET - INSPIRE themes, version 1.0 2008-06-01 geonetwork.thesaurus.external.theme.httpinspireeceuropaeutheme-theme Countries {country_name} Continents, countries, sea regions of the world. 2015-07-17 geonetwork.thesaurus.external.place.regions land cover land use landscape landscape alteration land GEMET 2021-11-30 geonetwork.thesaurus.external.theme.gemet European Spatial scope 2019-05-22 geonetwork.thesaurus.external.theme.httpinspireeceuropaeumetadatacodelistSpatialScope-SpatialScope 2013 2.6.1 Land use EEA topics 2022-10-18 2020-09-24 geonetwork.thesaurus.external.theme.eea-topics land change 2018-2024 EEA keyword list 2002-03-01 no limitations to public access Access to data is based on a principle of full, open and free access as established by the Copernicus data and information policy Regulation (EU) No 1159/2013 of 12 July 2013. This regulation establishes registration and licensing conditions for GMES/Copernicus users. Free, full and open access to this data set is made on the conditions that: 1. When distributing or communicating Copernicus dedicated data and Copernicus service information to the public, users shall inform the public of the source of that data and information. 2. Users shall make sure not to convey the impression to the public that the user's activities are officially endorsed by the Union. 3. Where that data or information has been adapted or modified, the user shall clearly state this. 4. The data remain the sole property of the European Union. Any information and data produced in the framework of the action shall be the sole property of the European Union. Any communication and publication by the beneficiary shall acknowledge that the data were produced “with funding by the European Union”. 100 environment imageryBaseMapsEarthCover {west} {east} {south} {north} 2018-01-01 2024-12-31 {format_name} Commission Regulation (EU) No 1089/2010 of 23 November 2010 implementing Directive 2007/2/EC of the European Parliament and of the Council as regards interoperability of spatial data sets and services 2010-12-08 See the referenced specification Minimum Mapping Unit ha 5 Minimum Mapping Width m 100 The national team mapped the land cover changes that occurred between 2018 and 2024. The resulting change layer was validated within the CLMS QC tool as part of the CLC 2024 national delivery. """ xml_template_solar = """ {file_uuid} National CLC team contact {email} {date_stamp} ISO 19115/19139 1.0 EPSG:{epsg_code} CORINE Land Cover Change-Solar 2018-2024 (vector), {country_name} ({aoicode}) - National Data Extract, 6-yearly - version 2025_v01_r01, Nov 2025 2025-12-01 21.0 copernicus-{aoicode_lower}_v_{epsg_code}_100_m_sol1824_p_2018-2024_v01_r01 Corine Land Cover Change Solar 2018-2024 (SOL1824) is one of the Corine Land Cover (CLC) datasets produced within the frame the Copernicus Land Monitoring Service referring to changes in land cover / land use status between the years 2018 and 2024. CLC service has a long-time heritage (formerly known as "CORINE Land Cover Programme"), coordinated by the European Environment Agency (EEA). It provides consistent and thematically detailed information on land cover and land cover changes across Europe. CLC datasets are based on the classification of satellite images produced by the national teams of the participating countries - the EEA members and cooperating countries (EEA39). National CLC inventories are then further integrated into a seamless land cover map of Europe. The resulting European database relies on standard methodology and nomenclature with following base parameters: 44 classes in the hierarchical 3-level CLC nomenclature; minimum mapping unit (MMU) for status layers is 25 hectares; minimum width of linear elements is 100 metres. Change layers have higher resolution, i.e. minimum mapping unit (MMU) is 5 hectares for Land Cover Changes (CHA), and the minimum width of linear elements is 100 metres. The CLC service delivers important data sets supporting the implementation of key priority areas of the Environment Action Programmes of the European Union as e.g. protecting ecosystems, halting the loss of biological diversity, tracking the impacts of climate change, monitoring urban land take, assessing developments in agriculture or dealing with water resources directives. part of the European Copernicus Programme coordinated by the European Environment Agency, providing environmental information from a combination of air- and space-based observation systems and in-situ monitoring National CLC team contact {email} P6Y0M0DT0H0M0S Land cover Land use GEMET - INSPIRE themes, version 1.0 2008-06-01 geonetwork.thesaurus.external.theme.httpinspireeceuropaeutheme-theme {country_name} Countries Continents, countries, sea regions of the world. 2015-07-17 geonetwork.thesaurus.external.place.regions land cover land use landscape landscape alteration land GEMET 2021-11-30 geonetwork.thesaurus.external.theme.gemet European Spatial scope 2019-05-22 geonetwork.thesaurus.external.theme.httpinspireeceuropaeumetadatacodelistSpatialScope-SpatialScope 2013 2.6.1 Land use EEA topics 2022-10-18 2020-09-24 geonetwork.thesaurus.external.theme.eea-topics land change solar 2018-2024 EEA keyword list 2002-03-01 no limitations to public access Access to data is based on a principle of full, open and free access as established by the Copernicus data and information policy Regulation (EU) No 1159/2013 of 12 July 2013. This regulation establishes registration and licensing conditions for GMES/Copernicus users. Free, full and open access to this data set is made on the conditions that: 1. When distributing or communicating Copernicus dedicated data and Copernicus service information to the public, users shall inform the public of the source of that data and information. 2. Users shall make sure not to convey the impression to the public that the user's activities are officially endorsed by the Union. 3. Where that data or information has been adapted or modified, the user shall clearly state this. 4. The data remain the sole property of the European Union. Any information and data produced in the framework of the action shall be the sole property of the European Union. Any communication and publication by the beneficiary shall acknowledge that the data were produced “with funding by the European Union”. 100 environment imageryBaseMapsEarthCover {west} {east} {south} {north} 2018-01-01 2024-12-31 {format_name} Commission Regulation (EU) No 1089/2010 of 23 November 2010 implementing Directive 2007/2/EC of the European Parliament and of the Council as regards interoperability of spatial data sets and services 2010-12-08 See the referenced specification Minimum Mapping Unit ha 5 Minimum Mapping Width m 100 The solar parks changes layer is a new layer introduced in the CLC 2024 dataset. The national team mapped the changes that occurred between 2018 and 2024. Subsequently, the national team extracted the changes specific to solar parks into a dedicated layer, and these were validated by the CLMS QC tool as part of the CLC 2024 national delivery. """ # --------------------------------------------------------------------- file_uuid = str(uuid.uuid4()) date_stamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") if gpkg_path.lower().endswith(".gpkg"): format_name = "GPKG" else: format_name = "GDB" aoicode = aoicode.lower() # XML for reference clc24_xx.xml xml_filled = xml_template_reference.format( file_uuid=file_uuid, email=email, epsg_code=epsg, west=west, east=east, south=south, north=north, country_name=country, country_code=aoicode, aoicode=aoicode, aoicode_lower=aoicode.lower(), format_name=format_name, date_stamp=date_stamp ) output_path = os.path.join(script_dir, f"clc24_{aoicode}.xml") with open(output_path, "w", encoding="utf-8") as f: f.write(xml_filled) print(f"\nMetadata written to: {output_path}") # XML for initial clc18_xx.xml file_uuid_initial = str(uuid.uuid4()) xml_filled_initial = xml_template_initial.format( file_uuid=file_uuid_initial, email=email, epsg_code=epsg, west=west, east=east, south=south, north=north, country_name=country, country_code=aoicode, aoicode=aoicode, aoicode_lower=aoicode.lower(), format_name=format_name, date_stamp=date_stamp ) output_path = os.path.join(script_dir, f"clc18_{aoicode}.xml") with open(output_path, "w", encoding="utf-8") as f: f.write(xml_filled_initial) print(f"\nMetadata written to: {output_path}") # XML template for change cha1824_xx.xml file_uuid_change = str(uuid.uuid4()) xml_filled_change = xml_template_change.format( file_uuid=file_uuid_change, email=email, epsg_code=epsg, west=west, east=east, south=south, north=north, country_name=country, country_code=aoicode, aoicode=aoicode, aoicode_lower=aoicode.lower(), format_name=format_name, date_stamp=date_stamp ) output_path = os.path.join(script_dir, f"cha1824_{aoicode}.xml") with open(output_path, "w", encoding="utf-8") as f: f.write(xml_filled_change) print(f"\nMetadata written to: {output_path}") # XML template for solar sol1824_xx.xml file_uuid_solar = str(uuid.uuid4()) xml_filled_solar = xml_template_solar.format( file_uuid=file_uuid_solar, email=email, epsg_code=epsg, west=west, east=east, south=south, north=north, country_name=country, country_code=aoicode, aoicode=aoicode, aoicode_lower=aoicode.lower(), format_name=format_name, date_stamp=date_stamp ) output_path = os.path.join(script_dir, f"sol1824_{aoicode}.xml") with open(output_path, "w", encoding="utf-8") as f: f.write(xml_filled_solar) print(f"\nMetadata written to: {output_path}")