# -*- coding: utf-8 -*-
"""Moduł pomocniczy do odczytu xml
"""
from Mapa_PU.swdl.model.tags import Tags
from Mapa_PU.swdl.model.swdl.subarea_data import SubareaData,ArodStandPec,ArodCategory,Cue,Goal,Phenomena,SoilSpec,SpecArea,SpeciesSpecArea,TreeLayer,TreeSpecies,SubareaParcel,ParcelLandUse,OwnershipShare,LandUseMeasure,ProtectArea
from Mapa_PU.swdl.model.swdl.forest_global_data import ForestGlobalData,County,District,Municipality,Community,Measure
from Mapa_PU.swdl.model.swdl.forest_data_desc import ForestDataDesc,InventoryData
from Mapa_PU.swdl.model.swdl.supervisor_info import SupervisorInfo
from Mapa_PU.swdl.model.swdl.forest_map_no_sf import ForestMapNoSF
from Mapa_PU.swdl.kontroler.forest_map_no_sf_helper_xml import ForestMapNoSFHelperXml
from Mapa_PU.swdl.model.swdl.natural_values import NaturalValue


"""Klasa pomocnicza do budowania obiektów na podstawie drzewa Xml
"""
class SwdlHelperXml():
    def __init__(self,xml_converter):
        self.__xml=xml_converter
    
    def value(self,element,name):
        """Wartośc elementu
        :param element; element drzewa
        :param name; nazwa wartości
        """ 
        try:
            return self.__xml.get_value(self.__xml.get_element(element,name))
        except Exception as e:
            raise e
    
    def create_forest_data_desc(self,tree):
        """Zwraca obiekty opisu zestawu danych
        :param tree; gałąź drzewa
        """
        try:
            fdd=self.__xml.get_element(tree,Tags.FOREST_DATA_DESC.value)
            #organ nadzorujący
            s_xml=self.__xml.get_element(fdd,Tags.SUPERVISOR.value)
            supervisor=SupervisorInfo(self.value(s_xml,Tags.ORGANIZATION_NAME.value),self.value(s_xml,Tags.ORGANIZATION_INFO.value), self.value(s_xml,Tags.STREET.value), 
                                      self.value(s_xml,Tags.CITY.value),self.value(s_xml,Tags.POSTAL_CODE.value),self.value(s_xml,Tags.COUNTRY.value)
                                      ,self.value(s_xml,Tags.PHONE.value),self.value(s_xml,Tags.FAX.value),self.value(s_xml,Tags.EMAIL.value))
            #organ administrujacy, któremu powierzono nadzór (opcjonalny)
            ds_xml=self.__xml.get_element(fdd,Tags.DELEGATE_SUPERVISOR.value)
            delegate_supervisor=SupervisorInfo(self.value(ds_xml,Tags.ORGANIZATION_NAME.value),self.value(ds_xml,Tags.ORGANIZATION_INFO.value), self.value(ds_xml,Tags.STREET.value), 
                                      self.value(ds_xml,Tags.CITY.value),self.value(ds_xml,Tags.POSTAL_CODE.value),self.value(ds_xml,Tags.COUNTRY.value)
                                      ,self.value(ds_xml,Tags.PHONE.value),self.value(ds_xml,Tags.FAX.value),self.value(ds_xml,Tags.EMAIL.value))
            
            inventory_data=InventoryData(self.value(fdd,Tags.INVENTORY_OBJECT_NAME.value),self.value(fdd,Tags.INVENT_YEAR.value),supervisor,delegate_supervisor)
            #opis zestawu danych
            forest_data=ForestDataDesc(self.value(fdd,Tags.ADRESS_FOREST.value),self.value(fdd,Tags.STATE_DATE.value),self.value(fdd,Tags.INVENT_EXECUTOR.value),inventory_data)
            return forest_data
        except Exception as e:
            raise e
    
    def create_forest_global_data(self,tree):
        """Zwraca obiekt ForestGlobalData
        :param tree; gałąz drzewa
        """
        try:
            ##Województwa
            counties=[County(self.value(so,Tags.COUNTY_CD.value),self.value(so,Tags.COUNTY_NAME.value)) 
                             for so in self.__xml.get_elements(tree,Tags.COUNTY.value)]
            ##Powiaty
            districts=[District(self.value(di,Tags.COUNTY_CD.value),self.value(di,Tags.DISTRICT_CD.value),self.value(di,Tags.DISTRICT_NAME.value))
                       for di in self.__xml.get_elements(tree,Tags.DISTRICT.value)]
            ##Gminy
            municipalities=[Municipality(self.value(mu,Tags.COUNTY_CD.value), self.value(mu,Tags.DISTRICT_CD.value),self.value(mu,Tags.MUNICIPALITY_CD.value),self.value(mu,Tags.MUNICIPALITY_NAME.value))
                            for mu in self.__xml.get_elements(tree,Tags.MUNICIPALITY.value)]
            ##Obręby ewidencyjne
            communities=[Community(self.value(co,Tags.COUNTY_CD.value), self.value(co,Tags.DISTRICT_CD.value), self.value(co,Tags.MUNICIPALITY_CD.value), 
                                   self.value(co,Tags.COMMUNITY_CD.value), self.value(co,Tags.COMMUNITY_NAME.value),
                                   self.value(co, Tags.ALLOW_CUT_LCA.value),self.value(co, Tags.ALLOW_CUT_PCA.value),self.value(co, Tags.ALLOW_CUT_CN.value),
                                   self.value(co, Tags.ALLOW_CUT_ADOPTED.value),self.value(co, Tags.ALLOW_CUT_OTHER_CUT.value),self.value(co, Tags.ALLOW_CUT_MAX_VOL.value))
                         for co in self.__xml.get_elements(tree,Tags.COMMUNITY.value)]
            
            ##Słownik wskazówek
            measures=[Measure(self.value(me,Tags.MEASURE_CD.value),self.value(me,Tags.MEASURE_NR.value), self.value(me,Tags.MEASURE_NAME.value))
                      for me in self.__xml.get_elements(tree,Tags.MEASURE.value)]
            
            return ForestGlobalData(counties,  districts,  municipalities, communities, measures)
        except Exception as e:
            raise e
    
    def create_subarea_data_list(self,tree):
        """Lista obiektow Subarea z drzewa xml
        :param tree gałąź drzewa xml
        """
        try:
            #lista obiektów Subarea z drzewa xml
            subareaList=[]
            data=self.__xml.get_elements(tree,Tags.SUBAREA_DATA.value)
            for sub in data:
                address_forest=self.__xml.get_value(self.__xml.get_element(sub,Tags.ADRESS_FOREST.value))
                damage_degree=self.__xml.get_value(self.__xml.get_element(sub,Tags.DAMAGE_DEGREE.value))
                cause_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.CAUSE_CD.value))
                area_type_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.AREA_TYPE_CD.value))
                position_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.POSITION_CD.value))
                relief_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.RELIEF_CD.value))
                site_type_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.SITE_TYPE_CD.value))
                degradation_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.DEGRADATION_CD.value))
                veg_cover_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.VEG_COVER_CD.value))
                forest_func_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.FOREST_FUNC_CD.value))
                stand_struct_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.STAND_STRUCT_CD.value))
                slope_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.SLOPE_CD.value))
                exposure_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.EXPOSURE_CD.value))
                moisture_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.MOISTURE_CD.value))
                soil_pec_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.SOIL_PEC_CD.value))
                soil_sub_type_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.SOIL_SUB_TYPE_CD.value))
                plant_comm_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.PLANT_COMM_CD.value))
                rotation_age=self.__xml.get_value(self.__xml.get_element(sub,Tags.ROTATION_AGE.value))
                
                #subarea=self.__xml.get_value(self.__xml.get_element(sub,Tags.SUB_AREA.value))
                subarea=self.__xml.get_float(self.__xml.get_element(sub,Tags.SUB_AREA.value))
                subarea_info=self.__xml.get_value(self.__xml.get_element(sub,Tags.SUBAREA_INFO.value))
                altitude_min=self.__xml.get_value(self.__xml.get_element(sub,Tags.ALTITUDE_MIN.value))
                altitude_max=self.__xml.get_value(self.__xml.get_element(sub,Tags.ALTITUDE_MAX.value))
                accord_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.ACCORD_CD.value))
                silviculture_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.SILVICULTURE_CD.value))
                reconstr_period=self.__xml.get_value(self.__xml.get_element(sub,Tags.RECONSTR_PERIOD.value))
                seed_base_nr=self.__xml.get_value(self.__xml.get_element(sub,Tags.SEED_BASE_NR.value))
                control_unit_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.CONTROL_UNIT_CD.value))
                reconstr_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.RECONSTR_CD.value))
                phase_cd=self.__xml.get_value(self.__xml.get_element(sub,Tags.PHASE_CD.value))
                
                subarea_object=SubareaData(None,address_forest,damage_degree,cause_cd,area_type_cd,position_cd,relief_cd,site_type_cd,degradation_cd,veg_cover_cd,
                 forest_func_cd,stand_struct_cd,slope_cd,exposure_cd,moisture_cd,soil_pec_cd,soil_sub_type_cd,plant_comm_cd,rotation_age,subarea,
                 subarea_info,altitude_min,altitude_max,accord_cd,silviculture_cd,reconstr_period,seed_base_nr,control_unit_cd,
                 reconstr_cd, phase_cd)
                
                geometry=self.__xml.get_child(sub,Tags.GEOMETRY.value)
                if geometry is not None:
                    subarea_object.geometry=self.__xml.to_string(geometry[0])
                
#                 TODO brak implementacji
#                 TODO damages
#                 var damages = subareaData.GetList(DefaultNamespace + "damage");
#                 TODO doneMeasures
#                 var doneMeasures = subareaData.GetList(DefaultNamespace + "doneMeasure");
#                 TODO randomSamples
#                 var randomSamples = subareaData.GetList(DefaultNamespace + "randomSamples");
                
                subarea_object.arod_stand_pecs=self.create_arod_stand_pecs(self.__xml.get_elements(sub,Tags.FOREST_PEC_DIC.value))
                subarea_object.arod_categories=self.create_categories(self.__xml.get_elements(sub,Tags.AROD_CATEGORY.value))
                subarea_object.arod_cues=self.create_cues(self.__xml.get_elements(sub,Tags.CUE.value))
                subarea_object.arod_goals=self.create_goals(self.__xml.get_elements(sub,Tags.GOAL.value))
                
                subarea_object.arod_phenomenas=self.create_phenomenas(self.__xml.get_elements(sub,Tags.PHENOMENA.value))
                subarea_object.arod_prot_sites=self.create_prot_sites(self.__xml.get_elements(sub,Tags.PROT_SITE.value))
                subarea_object.arod_soil_specs=self.create_soil_specs(self.__xml.get_elements(sub,Tags.SOIL_SPEC.value))
                subarea_object.arod_spec_areas=self.create_spec_areas(self.__xml.get_elements(sub,Tags.SPEC_AREA.value),address_forest)
                subarea_object.tree_layers=self.create_tree_layers(self.__xml.get_elements(sub,Tags.TREE_LAYER.value))
                subarea_object.subarea_parcels=self.create_parcels(self.__xml.get_elements(sub,Tags.SUBAREA_PARCEL.value))
                
                subarea_object.subarea_ownership_structure=self.create_shares(self.__xml.get_elements(sub,Tags.OWNERSHIP_SHARE.value))
                subarea_object.protect_areas=self.create_protect_areas(self.__xml.get_elements(sub,Tags.PROTECT_AREA.value))
                
                subareaList.append(subarea_object)
               
#             subareaList=[SubareaData(id,address_forest,damage_degree,cause_cd,area_type_cd,position_cd,relief_cd,site_type_cd,degradation_cd,veg_cover_cd,
#                  forest_func_cd,stand_struct_cd,slope_cd,exposure_cd,moisture_cd,soil_pec_cd,soil_sub_type_cd,plant_comm_cd,rotation_age,subarea,
#                  subarea_info,altitude_min,altitude_max) ]
            return subareaList
        except Exception as e:
            raise e
        
    def create_protect_areas(self,elements):
        """Tworzy listę obszarów chronionych ProtectArea na podstawie gałęzi xml"""
        try:
            return [ProtectArea(self.__xml.get_value(self.__xml.get_element(pa,Tags.PROTECT_AREA_CD.value)),
                                                    self.__xml.get_value(self.__xml.get_element(pa,Tags.PROTECT_AREA_NAME.value))) for pa in elements]
        except Exception as e:
            raise e
        
    def create_arod_stand_pecs(self,elements):
        """Tworzy obiekty ArodStandPecs
        :param elements; lista obiektów ArodStandPecs
        """
        try:
            return [ArodStandPec(None,self.__xml.get_value(forest_pec)) for forest_pec in elements]
        except Exception as e:
            raise e
        
    def create_categories(self,elements):
        """Tworzy obiekty CreateCategories
        :param elements; lista obiketów xml CreateCategories
        """
        try:
            return [ArodCategory(None,self.__xml.get_value(self.__xml.get_element(ac,Tags.CATEGORY_CD.value)),self.__xml.get_value(self.__xml.get_element(ac,Tags.CATEGORY_RANK_ORDER.value))) for ac in elements]
        except Exception as e:
            raise e
        
    def create_cues(self,elements):
        """Tworzy listę obiektów Cue
        :param elements; obiekty Cue
        """
        try:
            return [Cue(None,site_nr=self.__xml.get_value(self.__xml.get_element(cue,Tags.SITE_NR.value)),
                        measure_cd=self.__xml.get_value(self.__xml.get_element(cue,Tags.MEASURE_CD.value)),
                        urgency=self.__xml.get_value(self.__xml.get_element(cue,Tags.URGENCY.value)),
                        cutting_area=self.__xml.get_value(self.__xml.get_element(cue,Tags.CUTTING_AREA.value)),
                        large_timber_perc=self.__xml.get_value(self.__xml.get_element(cue,Tags.LARGE_TIMBER_PERC.value)),
                        cutting_nr=self.__xml.get_value(self.__xml.get_element(cue,Tags.CUTTING_NR.value)),
                        large_timber=self.__xml.get_value(self.__xml.get_element(cue,Tags.LARGE_TIMBER.value)),
                        large_timber_netto=self.__xml.get_value(self.__xml.get_element(cue,Tags.LARGE_TIMBER_NETTO.value)),
                        cue_rank_order=self.__xml.get_value(self.__xml.get_element(cue,Tags.CUE_RANK_ORDER.value))
                        ) for cue in elements]
        except Exception as e:
            raise e
      
    def create_goals(self,elements):
        """Tworzy listę obiektów goal
        :params elements; obikety goal
        """
        try:
            return [Goal(None,self.value(g,Tags.GOAL_TYPE_FL.value), self.value(g,Tags.SPECIES_CD.value), self.value(g,Tags.GOAL_RANK_ORDER.value),self.value(g,Tags.GOAL_SPECIES_PERC.value)) 
                    for g in elements]
        except Exception as e:
            raise e
        
    def create_phenomenas(self,elements):
        """Tworzy listę obiektów phenomena
        :param elements; obiekty phenomena
        """
        try:
            phenomenas=[]
            for el in elements:
                phenomena=Phenomena(None,self.value(el,Tags.PHENOMENA_CD.value),self.value(el,Tags.LOCATION_CD.value),self.value(el,Tags.SPECIES_CD.value),self.value(el,Tags.PLANT_CD.value)
                                    ,self.value(el,Tags.PHEN_NUM.value),self.value(el,Tags.PHEN_AREA.value),self.value(el,Tags.NATURE_MON_FL.value))
                geometry=self.__xml.get_element(el,Tags.GEOMETRY.value)
                if geometry is not None:
                    phenomena.set_geometry(self.__xml.to_string(geometry[0]))
                phenomenas.append(phenomena)
            return phenomenas
        except Exception as e:
            raise e
    
    def create_prot_sites(self,elements):
        """Tworzy listę obiektów ProtSite
        :param elements; lista obiektów drzewa xml
        """
        try:
            #TODO zaimplementowac
            return []
        except Exception as e:
            raise e    
        
    def create_soil_specs(self,elements):
        """Lista obiektów soilSpec
        :param elements; Obiekty soilSpec
        """
        try:
            return [SoilSpec(None,self.value(el,Tags.SOIL_SPECIES_CD.value), self.value(el,Tags.SOIL_LEVEL_DIC_CD.value)
                             ,self.value(el,Tags.SOIL_SPEC_RANK_ORDER.value)) for el in elements]
        except Exception as e:
            raise e
        
    def create_spec_areas(self,elements,address_forest):
        """Lista obiektów specAreas
        :param elements; obiekty SpecAreas
        """
        try:
            spec_areas=[]
            for el in elements:
                spec_area=SpecArea(None,self.value(el,Tags.SPECIAL_AREA_CD.value),self.value(el,Tags.LOCATION_CD.value),
                                   self.value(el,Tags.SPECIAL_AREA.value),self.value(el,Tags.SPECIAL_AREA_NUM.value),self.value(el,Tags.SPECIAL_AREA_YEAR.value),
                                   self.value(el,Tags.SPAREA_ORDER.value),address_forest)
                
                spec_area.parcel_nr=self.value(el,Tags.PARCEL_NR.value)
                
                geometry=self.__xml.get_element(el,Tags.GEOMETRY.value)
                
                if geometry is not None:
                    spec_area.set_geometry([self.__xml.to_string(g) for g in self.__xml.get_childs(geometry)]) #self.__xml.to_string(geometry[0]))
                
                species_spec_area_list=[SpeciesSpecArea(None,self.value(ssa,Tags.SPECIES_CD.value),self.value(ssa,Tags.SPECIES_AGE.value)) for ssa in self.__xml.get_elements(el,Tags.SPECIES_SPEC_AREA.value)]
                
                spec_area.set_species_spec_areas(species_spec_area_list)
                
                spec_areas.append(spec_area)
        
            return spec_areas
        except Exception as e:
            raise e
        
    def create_tree_layers(self,elements):
        """Lista obiektów TreeLayer
        :param elemnets; obiekty treeLayer
        """
        try:
            tree_layers=[]
            for layer in elements:
                tree_layer=TreeLayer(None,self.value(layer,Tags.STOREY_CD.value),self.value(layer,Tags.STAND_DENSITY_INDEX.value),
                                    self.value(layer,Tags.MIXTURE_CD.value),self.value(layer,Tags.DENSITY_CD.value), 
                                    self.value(layer,Tags.STOREY_RANK_ORDER.value),self.value(layer,Tags.LOCATION_CD.value),
                                    self.value(layer,Tags.TREE_STOCK_CD.value),self.value(layer,Tags.SILV_QUALITY_CD.value))
                tree_species=[TreeSpecies(self.value(ts,Tags.SPECIES_CD.value),self.value(ts,Tags.VOLUME_HA.value),self.value(ts,Tags.PART_CD.value),
                                          self.value(ts,Tags.DBH.value),self.value(ts,Tags.HEIGHT.value),self.value(ts,Tags.SITE_CLASS_CD.value),
                                          self.value(ts,Tags.SPECIES_AGE.value), self.value(ts,Tags.SPECIES_RANK_ORDER.value),
                                          self.value(ts,Tags.INCREMENT_HA.value),self.value(ts,Tags.VOLUME.value),self.value(ts,Tags.INCREMENT.value),
                                          self.value(ts,Tags. TECH_QUALITY_CD.value)) 
                              for ts in self.__xml.get_elements(layer,Tags.TREE_SPECIES.value)]
                tree_layer.set_layer_species(tree_species)
                tree_layers.append(tree_layer)
            return tree_layers
        except Exception as e:
            raise e
        
    def create_parcels(self,elements):
        """Lista obiektów parcel
        :param elements; obiekty parcel w xml
        """
        try:
            parcels=[]
            for el in elements:
                parcel=SubareaParcel(None,self.value(el,Tags.PARCEL_NR.value),self.value(el,Tags.COUNTY_CD.value),self.value(el,Tags.DISTRICT_CD.value),
                                     self.value(el,Tags.MUNICIPALITY_CD.value),self.value(el,Tags.COMMUNITY_CD.value),
                                     self.value(el,Tags.OWNERSHIP_CD.value),self.value(el,Tags.PARCEL_AREA.value),self.value(el,Tags.REG_SHEET_NR2.value))
                geo_parcel=self.__xml.get_child(el,Tags.GEOMETRY.value)#self.__xml.get_element(el,Tags.GEOMETRY.value)
                if geo_parcel is not None:
                    parcel.geometry=self.__xml.to_string(geo_parcel[0])
                    
                parcel_land_use_list=[]
                for plu in self.__xml.get_elements(el,Tags.PARCEL_LAND_USE.value):
                    parcel_land_use=ParcelLandUse(self.value(plu,Tags.AREA_USE_DIC.value), self.value(plu,Tags.SOIL_QUALITY_DIC.value),
                                                    self.value(plu,Tags.LAND_USE_AREA.value),self.value(plu,Tags.AROD_LAND_USE_AREA.value),
                                                    self.value(plu, Tags.FOR_AFFORESTATION.value),self.value(plu, Tags.SHAPE_NR.value))
                    geo_p_l_u=self.__xml.get_element(plu,Tags.GEOMETRY.value)
                    if geo_p_l_u is not None:
                        parcel_land_use.geometry=self.__xml.to_string(geo_p_l_u[0])
                    #Dodanie zabiegów gospodarczych
                    parcel_land_use.land_use_measures=[LandUseMeasure(self.value(lum,Tags.MEASURE_CD.value),
                                                                     self.value(lum,Tags.LARGE_TIMBER.value),
                                                                     self.value(lum,Tags.LARGE_TIMBER_NETTO.value), 
                                                                     self.value(lum,Tags.CUE_AREA_DIV.value),
                                                                     self.value(lum,Tags.CUE_RANK_ORDER.value)) for lum in self.__xml.get_elements(plu,Tags.LAND_USE_MEASURE.value)]
                    
                    parcel_land_use_list.append(parcel_land_use)
                parcel.set_parcel_land_use(parcel_land_use_list)
                parcels.append(parcel)
            return parcels
        except Exception as e:
            raise e
        
    def create_shares(self,elements):
        """Lista obiektow OwnershipShare
        :param elements; elementy drzewa
        """
        try:
            return [OwnershipShare(None,self.value(os,Tags.OWNERSHIP_CATEGORY_GUS.value),self.value(os,Tags.SHARE.value),self.value(os,Tags.SHARE_AREA.value)) 
                    for os in elements]
        except Exception as e:
            raise e
        
    def create_forest_map_no_sf(self,tree)->ForestMapNoSF:
        """Zwraca obiekt ForestMapNoSF z pliku swdl"""
        try:
            helper=ForestMapNoSFHelperXml(self.__xml)
            return helper.create_forest_map_no_sf(tree)
        except Exception as e:
            raise e

    def create_forest_natural_values(self,tree)->[]:
        """Zwraca walory przyrodnicze z pliku swdl"""
        try:
            elements=self.__xml.get_elements(tree,Tags.NATURAL_VALUE.value)
            return [NaturalValue(self.value(nv,Tags.COUNTY_CD.value),
                                 self.value(nv,Tags.DISTRICT_CD.value),
                                 self.value(nv,Tags.MUNICIPALITY_CD.value),
                                 self.value(nv,Tags.COMMUNITY_CD.value),
                                 self.value(nv,Tags.ENV_COUNT.value),
                                 self.value(nv,Tags.NATURAL_VALUE_CD.value),
                                 self.value(nv,Tags.TOTAL_AREA.value),
                                 self.value(nv,Tags.PUL_AREA.value),
                                 self.value(nv,Tags.FOREST_AREA.value),
                                 self.value(nv,Tags.FOREST_AREA_P.value),
                                 self.value(nv,Tags.NFOREST_AREA_P.value),
                                 self.value(nv,Tags.NFOREST_AREA.value)
                                 ) for nv in elements]
        except Exception as e:
            raise e
                    
                