def read(self, params, real_estate, bbox): # pylint: disable=W:0221 """ The read point which creates a extract, depending on a passed real estate. Args: params (pyramid_oereb.views.webservice.Parameter): The parameters of the extract request. real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real estate in its record representation. bbox (shapely.geometry.base.BaseGeometry): The bbox to search the records. """ # Check if the plr is marked as available if self._is_available(real_estate): session = self._adapter_.get_session(self._key_) try: if session.query(self._model_).count() == 0: # We can stop here already because there are no items in the database self.records = [ EmptyPlrRecord( Config.get_theme_by_code_sub_code( self._plr_info['code'])) ] else: # We need to investigate more in detail # Try to find geometries which have spatial relation with real estate geometry_results = self.collect_related_geometries_by_real_estate( session, real_estate) if len(geometry_results) == 0: # We checked if there are spatially related elements in database. But there is none. # So we can stop here. self.records = [ EmptyPlrRecord( Config.get_theme_by_code_sub_code( self._plr_info['code'])) ] else: # We found spatially related elements. This means we need to extract the actual plr # information related to the found geometries. self.records = [] legend_entries_from_db = self.collect_legend_entries_by_bbox( session, bbox) for geometry_result in geometry_results: self.records.append( self.from_db_to_plr_record( params, geometry_result.public_law_restriction, legend_entries_from_db)) finally: session.close() # Add empty record if topic is not available else: self.records = [ EmptyPlrRecord(Config.get_theme_by_code_sub_code( self._plr_info['code']), has_data=False) ]
def from_db_to_plr_record(self, params, public_law_restriction_from_db, legend_entries_from_db): thresholds = self._plr_info.get('thresholds') min_length = thresholds.get('length').get('limit') length_unit = thresholds.get('length').get('unit') min_area = thresholds.get('area').get('limit') area_unit = thresholds.get('area').get('unit') legend_entry_record = self.from_db_to_legend_entry_record( public_law_restriction_from_db.legend_entry) legend_entry_records = self.from_db_to_legend_entry_records( legend_entries_from_db, legend_entry_record.theme.sub_code) symbol = ImageRecord( b64.decode( binascii.b2a_base64( public_law_restriction_from_db.legend_entry.symbol).decode( 'ascii'))) view_service_record = self.from_db_to_view_service_record( public_law_restriction_from_db.view_service, legend_entry_records, self._plr_info.get('code')) theme = Config.get_theme_by_code_sub_code( public_law_restriction_from_db.legend_entry.theme, public_law_restriction_from_db.legend_entry.sub_theme) document_records = eliminate_duplicated_document_records( theme.document_records, self.get_document_records(params, public_law_restriction_from_db)) geometry_records = self.from_db_to_geometry_records( public_law_restriction_from_db.geometries) law_status = Config.get_law_status_by_data_code( self._plr_info.get('code'), public_law_restriction_from_db.law_status) sub_theme_legend_entry_record = \ legend_entry_record.theme if legend_entry_record.theme.sub_code else None plr_record = self._plr_record_class( Config.get_theme_by_code_sub_code(legend_entry_record.theme.code), legend_entry_record, law_status, public_law_restriction_from_db.published_from, public_law_restriction_from_db.published_until, self.from_db_to_office_record( public_law_restriction_from_db.responsible_office), symbol, view_service_record, geometry_records, sub_theme=sub_theme_legend_entry_record, type_code=public_law_restriction_from_db.legend_entry.type_code, type_code_list=public_law_restriction_from_db.legend_entry. type_code_list, documents=document_records, min_area=min_area, min_length=min_length, area_unit=area_unit, length_unit=length_unit, view_service_id=public_law_restriction_from_db.view_service.t_id) return plr_record
def from_db_to_legend_entry_record(self, legend_entry_from_db): theme = Config.get_theme_by_code_sub_code( legend_entry_from_db.theme, legend_entry_from_db.sub_theme) legend_entry_record = self._legend_entry_record_class( ImageRecord(b64.decode(legend_entry_from_db.symbol)), legend_entry_from_db.legend_text, legend_entry_from_db.type_code, legend_entry_from_db.type_code_list, theme, view_service_id=legend_entry_from_db.view_service_id, ) return legend_entry_record
def from_db_to_legend_entry_record(self, legend_entry_from_db): theme = Config.get_theme_by_code_sub_code( legend_entry_from_db.theme, legend_entry_from_db.sub_theme) legend_entry_record = self._legend_entry_record_class( ImageRecord( b64.decode( binascii.b2a_base64( legend_entry_from_db.symbol).decode('ascii'))), from_multilingual_text_to_dict( de=legend_entry_from_db.legend_text_de, fr=legend_entry_from_db.legend_text_fr, it=legend_entry_from_db.legend_text_it, rm=legend_entry_from_db.legend_text_rm, en=legend_entry_from_db.legend_text_en), legend_entry_from_db.type_code, legend_entry_from_db.type_code_list, theme, view_service_id=legend_entry_from_db.view_service_id, ) return legend_entry_record