idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
26,900 | def on_output_path_textChanged ( self ) : output_path = self . output_path . text ( ) output_not_xml_msg = tr ( 'output file is not .tif' ) if output_path and not output_path . endswith ( '.tif' ) : self . warning_text . add ( output_not_xml_msg ) elif output_path and output_not_xml_msg in self . warning_text : self . warning_text . remove ( output_not_xml_msg ) self . update_warning ( ) | Action when output file name is changed . | 123 | 8 |
26,901 | def on_input_path_textChanged ( self ) : input_path = self . input_path . text ( ) input_not_grid_msg = tr ( 'input file is not .xml' ) if input_path and not input_path . endswith ( '.xml' ) : self . warning_text . add ( input_not_grid_msg ) elif input_path and input_not_grid_msg in self . warning_text : self . warning_text . remove ( input_not_grid_msg ) if self . use_output_default . isChecked ( ) : self . get_output_from_input ( ) self . update_warning ( ) | Action when input file name is changed . | 149 | 8 |
26,902 | def prepare_place_layer ( self ) : if os . path . exists ( self . input_place . text ( ) ) : self . place_layer = QgsVectorLayer ( self . input_place . text ( ) , tr ( 'Nearby Cities' ) , 'ogr' ) if self . place_layer . isValid ( ) : LOGGER . debug ( 'Get field information' ) self . name_field . setLayer ( self . place_layer ) self . population_field . setLayer ( self . place_layer ) else : LOGGER . debug ( 'failed to set name field' ) | Action when input place layer name is changed . | 131 | 9 |
26,903 | def get_output_from_input ( self ) : input_path = self . input_path . text ( ) if input_path . endswith ( '.xml' ) : output_path = input_path [ : - 3 ] + 'tif' elif input_path == '' : output_path = '' else : last_dot = input_path . rfind ( '.' ) if last_dot == - 1 : output_path = '' else : output_path = input_path [ : last_dot + 1 ] + 'tif' self . output_path . setText ( output_path ) | Create default output location based on input location . | 131 | 9 |
26,904 | def accept ( self ) : input_path = self . input_path . text ( ) input_title = self . line_edit_title . text ( ) input_source = self . line_edit_source . text ( ) output_path = self . output_path . text ( ) if not output_path . endswith ( '.tif' ) : # noinspection PyArgumentList,PyCallByClass,PyTypeChecker QMessageBox . warning ( self , tr ( 'InaSAFE' ) , tr ( 'Output file name must be tif file' ) ) if not os . path . exists ( input_path ) : # noinspection PyArgumentList,PyCallByClass,PyTypeChecker QMessageBox . warning ( self , tr ( 'InaSAFE' ) , tr ( 'Input file does not exist' ) ) return algorithm = 'nearest' if self . nearest_mode . isChecked ( ) : algorithm = 'nearest' elif self . inverse_distance_mode . isChecked ( ) : algorithm = 'invdist' elif self . use_ascii_mode . isChecked ( ) : algorithm = 'use_ascii' # Smoothing smoothing_method = NONE_SMOOTHING if self . numpy_smoothing . isChecked ( ) : smoothing_method = NUMPY_SMOOTHING if self . scipy_smoothing . isChecked ( ) : smoothing_method = SCIPY_SMOOTHING # noinspection PyUnresolvedReferences QgsApplication . instance ( ) . setOverrideCursor ( QtGui . QCursor ( QtCore . Qt . WaitCursor ) ) extra_keywords = { } if self . check_box_custom_shakemap_id . isChecked ( ) : event_id = self . line_edit_shakemap_id . text ( ) extra_keywords [ extra_keyword_earthquake_event_id [ 'key' ] ] = event_id current_index = self . combo_box_source_type . currentIndex ( ) source_type = self . combo_box_source_type . itemData ( current_index ) if source_type : extra_keywords [ extra_keyword_earthquake_source [ 'key' ] ] = source_type file_name = convert_mmi_data ( input_path , input_title , input_source , output_path , algorithm = algorithm , algorithm_filename_flag = True , smoothing_method = smoothing_method , extra_keywords = extra_keywords ) file_info = QFileInfo ( file_name ) base_name = file_info . baseName ( ) self . output_layer = QgsRasterLayer ( file_name , base_name ) # noinspection PyUnresolvedReferences QgsApplication . instance ( ) . restoreOverrideCursor ( ) if self . load_result . isChecked ( ) : # noinspection PyTypeChecker mmi_ramp_roman ( self . output_layer ) self . output_layer . saveDefaultStyle ( ) if not self . output_layer . isValid ( ) : LOGGER . debug ( "Failed to load" ) else : # noinspection PyArgumentList QgsProject . instance ( ) . addMapLayer ( self . output_layer ) iface . zoomToActiveLayer ( ) if ( self . keyword_wizard_checkbox . isChecked ( ) and self . keyword_wizard_checkbox . isEnabled ( ) ) : self . launch_keyword_wizard ( ) self . done ( self . Accepted ) | Handler for when OK is clicked . | 804 | 7 |
26,905 | def on_open_input_tool_clicked ( self ) : input_path = self . input_path . text ( ) if not input_path : input_path = os . path . expanduser ( '~' ) # noinspection PyCallByClass,PyTypeChecker filename , __ = QFileDialog . getOpenFileName ( self , tr ( 'Input file' ) , input_path , tr ( 'Raw grid file (*.xml)' ) ) if filename : self . input_path . setText ( filename ) | Autoconnect slot activated when open input tool button is clicked . | 115 | 13 |
26,906 | def on_open_output_tool_clicked ( self ) : output_path = self . output_path . text ( ) if not output_path : output_path = os . path . expanduser ( '~' ) # noinspection PyCallByClass,PyTypeChecker filename , __ = QFileDialog . getSaveFileName ( self , tr ( 'Output file' ) , output_path , tr ( 'Raster file (*.tif)' ) ) if filename : self . output_path . setText ( filename ) | Autoconnect slot activated when open output tool button is clicked . | 115 | 13 |
26,907 | def launch_keyword_wizard ( self ) : # make sure selected layer is the output layer if self . iface . activeLayer ( ) != self . output_layer : return # launch wizard dialog keyword_wizard = WizardDialog ( self . iface . mainWindow ( ) , self . iface , self . dock_widget ) keyword_wizard . set_keywords_creation_mode ( self . output_layer ) keyword_wizard . exec_ ( ) | Launch keyword creation wizard . | 101 | 5 |
26,908 | def union ( union_a , union_b ) : output_layer_name = union_steps [ 'output_layer_name' ] output_layer_name = output_layer_name % ( union_a . keywords [ 'layer_purpose' ] , union_b . keywords [ 'layer_purpose' ] ) keywords_union_1 = union_a . keywords keywords_union_2 = union_b . keywords inasafe_fields_union_1 = keywords_union_1 [ 'inasafe_fields' ] inasafe_fields_union_2 = keywords_union_2 [ 'inasafe_fields' ] inasafe_fields = inasafe_fields_union_1 inasafe_fields . update ( inasafe_fields_union_2 ) parameters = { 'INPUT' : union_a , 'OVERLAY' : union_b , 'OUTPUT' : 'memory:' } # TODO implement callback through QgsProcessingFeedback object initialize_processing ( ) feedback = create_processing_feedback ( ) context = create_processing_context ( feedback = feedback ) result = processing . run ( 'native:union' , parameters , context = context ) if result is None : raise ProcessingInstallationError union_layer = result [ 'OUTPUT' ] union_layer . setName ( output_layer_name ) # use to avoid modifying original source union_layer . keywords = dict ( union_a . keywords ) union_layer . keywords [ 'inasafe_fields' ] = inasafe_fields union_layer . keywords [ 'title' ] = output_layer_name union_layer . keywords [ 'layer_purpose' ] = 'aggregate_hazard' union_layer . keywords [ 'hazard_keywords' ] = keywords_union_1 . copy ( ) union_layer . keywords [ 'aggregation_keywords' ] = keywords_union_2 . copy ( ) fill_hazard_class ( union_layer ) check_layer ( union_layer ) return union_layer | Union of two vector layers . | 438 | 6 |
26,909 | def fill_hazard_class ( layer ) : hazard_field = layer . keywords [ 'inasafe_fields' ] [ hazard_class_field [ 'key' ] ] expression = '"%s" is NULL OR "%s" = \'\'' % ( hazard_field , hazard_field ) index = layer . fields ( ) . lookupField ( hazard_field ) request = QgsFeatureRequest ( ) . setFilterExpression ( expression ) layer . startEditing ( ) for feature in layer . getFeatures ( request ) : layer . changeAttributeValue ( feature . id ( ) , index , not_exposed_class [ 'key' ] ) layer . commitChanges ( ) return layer | We need to fill hazard class when it s empty . | 147 | 11 |
26,910 | def function ( receiver ) : if hasattr ( receiver , '__call__' ) : # Reassign receiver to the actual method that will be called. if hasattr ( receiver . __call__ , im_func ) or hasattr ( receiver . __call__ , im_code ) : receiver = receiver . __call__ if hasattr ( receiver , im_func ) : # an instance-method... return receiver , getattr ( getattr ( receiver , im_func ) , func_code ) , 1 elif not hasattr ( receiver , func_code ) : raise ValueError ( 'unknown reciever type %s %s' % ( receiver , type ( receiver ) ) ) return receiver , getattr ( receiver , func_code ) , 0 | Get function - like callable object for given receiver | 159 | 10 |
26,911 | def populate_template_combobox ( self , path , unwanted_templates = None ) : templates_dir = QtCore . QDir ( path ) templates_dir . setFilter ( QtCore . QDir . Files | QtCore . QDir . NoSymLinks | QtCore . QDir . NoDotAndDotDot ) templates_dir . setNameFilters ( [ '*.qpt' , '*.QPT' ] ) report_files = templates_dir . entryList ( ) if not unwanted_templates : unwanted_templates = [ ] for unwanted_template in unwanted_templates : if unwanted_template in report_files : report_files . remove ( unwanted_template ) for f in report_files : self . template_combo . addItem ( QtCore . QFileInfo ( f ) . baseName ( ) , path + '/' + f ) | Helper method for populating template combobox . | 190 | 10 |
26,912 | def retrieve_paths ( self , products , report_path , suffix = None ) : paths = [ ] for product in products : path = ImpactReport . absolute_output_path ( join ( report_path , 'output' ) , products , product . key ) if isinstance ( path , list ) : for p in path : paths . append ( p ) elif isinstance ( path , dict ) : for p in list ( path . values ( ) ) : paths . append ( p ) else : paths . append ( path ) if suffix : paths = [ p for p in paths if p . endswith ( suffix ) ] paths = [ p for p in paths if exists ( p ) ] return paths | Helper method to retrieve path from particular report metadata . | 149 | 10 |
26,913 | def open_as_pdf ( self ) : # Get output path from datastore report_urls_dict = report_urls ( self . impact_function ) # get report urls for each product tag as list for key , value in list ( report_urls_dict . items ( ) ) : report_urls_dict [ key ] = list ( value . values ( ) ) if self . dock : # create message to user status = m . Message ( m . Heading ( self . dock . tr ( 'Map Creator' ) , * * INFO_STYLE ) , m . Paragraph ( self . dock . tr ( 'Your PDF was created....opening using the default PDF ' 'viewer on your system.' ) ) , m . ImportantText ( self . dock . tr ( 'The generated pdfs were saved ' 'as:' ) ) ) for path in report_urls_dict . get ( pdf_product_tag [ 'key' ] , [ ] ) : status . add ( m . Paragraph ( path ) ) status . add ( m . Paragraph ( m . ImportantText ( self . dock . tr ( 'The generated htmls were saved as:' ) ) ) ) for path in report_urls_dict . get ( html_product_tag [ 'key' ] , [ ] ) : status . add ( m . Paragraph ( path ) ) status . add ( m . Paragraph ( m . ImportantText ( self . dock . tr ( 'The generated qpts were saved as:' ) ) ) ) for path in report_urls_dict . get ( qpt_product_tag [ 'key' ] , [ ] ) : status . add ( m . Paragraph ( path ) ) send_static_message ( self . dock , status ) for path in report_urls_dict . get ( pdf_product_tag [ 'key' ] , [ ] ) : # noinspection PyCallByClass,PyTypeChecker,PyTypeChecker QtGui . QDesktopServices . openUrl ( QtCore . QUrl . fromLocalFile ( path ) ) | Print the selected report as a PDF product . | 450 | 9 |
26,914 | def open_in_composer ( self ) : impact_layer = self . impact_function . analysis_impacted report_path = dirname ( impact_layer . source ( ) ) impact_report = self . impact_function . impact_report custom_map_report_metadata = impact_report . metadata custom_map_report_product = ( custom_map_report_metadata . component_by_tags ( [ final_product_tag , pdf_product_tag ] ) ) for template_path in self . retrieve_paths ( custom_map_report_product , report_path = report_path , suffix = '.qpt' ) : layout = QgsPrintLayout ( QgsProject . instance ( ) ) with open ( template_path ) as template_file : template_content = template_file . read ( ) document = QtXml . QDomDocument ( ) document . setContent ( template_content ) # load layout object rwcontext = QgsReadWriteContext ( ) load_status = layout . loadFromTemplate ( document , rwcontext ) if not load_status : # noinspection PyCallByClass,PyTypeChecker QtWidgets . QMessageBox . warning ( self , tr ( 'InaSAFE' ) , tr ( 'Error loading template: %s' ) % template_path ) return QgsProject . instance ( ) . layoutManager ( ) . addLayout ( layout ) self . iface . openLayoutDesigner ( layout ) | Open in layout designer a given MapReport instance . | 319 | 10 |
26,915 | def prepare_components ( self ) : # Register the components based on user option # First, tabular report generated_components = deepcopy ( all_default_report_components ) # Rohmat: I need to define the definitions here, I can't get # the definition using definition helper method. component_definitions = { impact_report_pdf_component [ 'key' ] : impact_report_pdf_component , action_checklist_pdf_component [ 'key' ] : action_checklist_pdf_component , analysis_provenance_details_pdf_component [ 'key' ] : analysis_provenance_details_pdf_component , infographic_report [ 'key' ] : infographic_report } duplicated_report_metadata = None for key , checkbox in list ( self . all_checkboxes . items ( ) ) : if not checkbox . isChecked ( ) : component = component_definitions [ key ] if component in generated_components : generated_components . remove ( component ) continue if self . is_multi_exposure : impact_report_metadata = ( standard_multi_exposure_impact_report_metadata_pdf ) else : impact_report_metadata = ( standard_impact_report_metadata_pdf ) if component in impact_report_metadata [ 'components' ] : if not duplicated_report_metadata : duplicated_report_metadata = deepcopy ( impact_report_metadata ) duplicated_report_metadata [ 'components' ] . remove ( component ) if impact_report_metadata in generated_components : generated_components . remove ( impact_report_metadata ) generated_components . append ( duplicated_report_metadata ) # Second, custom and map report # Get selected template path to use selected_template_path = None if self . search_directory_radio . isChecked ( ) : selected_template_path = self . template_combo . itemData ( self . template_combo . currentIndex ( ) ) elif self . search_on_disk_radio . isChecked ( ) : selected_template_path = self . template_path . text ( ) if not exists ( selected_template_path ) : # noinspection PyCallByClass,PyTypeChecker QtWidgets . QMessageBox . warning ( self , tr ( 'InaSAFE' ) , tr ( 'Please select a valid template before printing. ' 'The template you choose does not exist.' ) ) if map_report in generated_components : # if self.no_map_radio.isChecked(): # generated_components.remove(map_report) if self . default_template_radio . isChecked ( ) : # make sure map report is there generated_components . append ( generated_components . pop ( generated_components . index ( map_report ) ) ) elif self . override_template_radio . isChecked ( ) : hazard_type = definition ( self . impact_function . provenance [ 'hazard_keywords' ] [ 'hazard' ] ) exposure_type = definition ( self . impact_function . provenance [ 'exposure_keywords' ] [ 'exposure' ] ) generated_components . remove ( map_report ) generated_components . append ( update_template_component ( component = map_report , hazard = hazard_type , exposure = exposure_type ) ) elif selected_template_path : generated_components . remove ( map_report ) generated_components . append ( override_component_template ( map_report , selected_template_path ) ) return generated_components | Prepare components that are going to be generated based on user options . | 784 | 14 |
26,916 | def template_chooser_clicked ( self ) : path = self . template_path . text ( ) if not path : path = setting ( 'lastCustomTemplate' , '' , str ) if path : directory = dirname ( path ) else : directory = '' # noinspection PyCallByClass,PyTypeChecker file_name = QFileDialog . getOpenFileName ( self , tr ( 'Select report' ) , directory , tr ( 'QGIS composer templates (*.qpt *.QPT)' ) ) self . template_path . setText ( file_name ) | Slot activated when report file tool button is clicked . | 125 | 10 |
26,917 | def toggle_template_selector ( self ) : if self . search_directory_radio . isChecked ( ) : self . template_combo . setEnabled ( True ) else : self . template_combo . setEnabled ( False ) if self . search_on_disk_radio . isChecked ( ) : self . template_path . setEnabled ( True ) self . template_chooser . setEnabled ( True ) else : self . template_path . setEnabled ( False ) self . template_chooser . setEnabled ( False ) | Slot for template selector elements behaviour . | 117 | 7 |
26,918 | def show_help ( self ) : # Read the header and footer html snippets self . main_stacked_widget . setCurrentIndex ( 0 ) header = html_header ( ) footer = html_footer ( ) string = header message = impact_report_help ( ) string += message . to_html ( ) string += footer self . help_web_view . setHtml ( string ) | Show usage info to the user . | 87 | 7 |
26,919 | def limitations ( ) : limitation_list = list ( ) limitation_list . append ( tr ( 'InaSAFE is not a hazard modelling tool.' ) ) limitation_list . append ( tr ( 'InaSAFE is a Free and Open Source Software (FOSS) project, ' 'published under the GPL V3 license. As such you may freely ' 'download, share and (if you like) modify the software.' ) ) limitation_list . append ( tr ( 'InaSAFE carries out all processing in-memory. Your ability to ' 'use a set of hazard, exposure and aggregation data with InaSAFE ' 'will depend on the resources (RAM, Hard Disk space) available ' 'on your computer. If you run into memory errors, try doing the ' 'analysis in several smaller parts.' ) ) return limitation_list | Get InaSAFE limitations . | 178 | 7 |
26,920 | def update_helper_political_level ( self ) : current_country = self . country_comboBox . currentText ( ) index = self . admin_level_comboBox . currentIndex ( ) current_level = self . admin_level_comboBox . itemData ( index ) content = None try : content = self . countries [ current_country ] [ 'levels' ] [ str ( current_level ) ] if content == 'N/A' or content == 'fixme' or content == '' : raise KeyError except KeyError : content = self . tr ( 'undefined' ) finally : text = self . tr ( 'which represents %s in' ) % content self . boundary_helper . setText ( text ) | To update the helper about the country and the admin_level . | 160 | 13 |
26,921 | def populate_countries ( self ) : for i in range ( 1 , 12 ) : self . admin_level_comboBox . addItem ( self . tr ( 'Level %s' ) % i , i ) # Set current index to admin_level 8, the most common one self . admin_level_comboBox . setCurrentIndex ( 7 ) list_countries = sorted ( [ self . tr ( country ) for country in list ( self . countries . keys ( ) ) ] ) for country in list_countries : self . country_comboBox . addItem ( country ) self . bbox_countries = { } for country in list_countries : multipolygons = self . countries [ country ] [ 'bbox' ] self . bbox_countries [ country ] = [ ] for coords in multipolygons : bbox = QgsRectangle ( coords [ 0 ] , coords [ 3 ] , coords [ 2 ] , coords [ 1 ] ) self . bbox_countries [ country ] . append ( bbox ) self . update_helper_political_level ( ) | Populate the combobox about countries and levels . | 244 | 11 |
26,922 | def update_extent ( self , extent ) : self . x_minimum . setValue ( extent [ 0 ] ) self . y_minimum . setValue ( extent [ 1 ] ) self . x_maximum . setValue ( extent [ 2 ] ) self . y_maximum . setValue ( extent [ 3 ] ) # Updating the country if possible. rectangle = QgsRectangle ( extent [ 0 ] , extent [ 1 ] , extent [ 2 ] , extent [ 3 ] ) center = rectangle . center ( ) for country in self . bbox_countries : for polygon in self . bbox_countries [ country ] : if polygon . contains ( center ) : index = self . country_comboBox . findText ( country ) self . country_comboBox . setCurrentIndex ( index ) break else : # Continue if the inner loop wasn't broken. continue # Inner loop was broken, break the outer. break else : self . country_comboBox . setCurrentIndex ( 0 ) | Update extent value in GUI based from an extent . | 214 | 10 |
26,923 | def update_extent_from_map_canvas ( self ) : self . bounding_box_group . setTitle ( self . tr ( 'Bounding box from the map canvas' ) ) # Get the extent as [xmin, ymin, xmax, ymax] extent = viewport_geo_array ( self . iface . mapCanvas ( ) ) self . update_extent ( extent ) | Update extent value in GUI based from value in map . | 91 | 11 |
26,924 | def update_extent_from_rectangle ( self ) : self . show ( ) self . canvas . unsetMapTool ( self . rectangle_map_tool ) self . canvas . setMapTool ( self . pan_tool ) rectangle = self . rectangle_map_tool . rectangle ( ) if rectangle : self . bounding_box_group . setTitle ( self . tr ( 'Bounding box from rectangle' ) ) extent = rectangle_geo_array ( rectangle , self . iface . mapCanvas ( ) ) self . update_extent ( extent ) | Update extent value in GUI based from the QgsMapTool rectangle . | 122 | 14 |
26,925 | def drag_rectangle_on_map_canvas ( self ) : self . hide ( ) self . rectangle_map_tool . reset ( ) self . canvas . unsetMapTool ( self . pan_tool ) self . canvas . setMapTool ( self . rectangle_map_tool ) | Hide the dialog and allow the user to draw a rectangle . | 63 | 12 |
26,926 | def get_checked_features ( self ) : feature_types = [ ] if self . roads_flag . isChecked ( ) : feature_types . append ( 'roads' ) if self . buildings_flag . isChecked ( ) : feature_types . append ( 'buildings' ) if self . building_points_flag . isChecked ( ) : feature_types . append ( 'building-points' ) if self . flood_prone_flag . isChecked ( ) : feature_types . append ( 'flood-prone' ) if self . evacuation_centers_flag . isChecked ( ) : feature_types . append ( 'evacuation-centers' ) if self . boundary_flag . isChecked ( ) : level = self . admin_level_comboBox . currentIndex ( ) + 1 feature_types . append ( 'boundary-%s' % level ) return feature_types | Create a tab with all checked features . | 200 | 8 |
26,927 | def accept ( self ) : error_dialog_title = self . tr ( 'InaSAFE OpenStreetMap Downloader Error' ) # Lock the bounding_box_group self . bounding_box_group . setDisabled ( True ) # Get the extent y_minimum = self . y_minimum . value ( ) y_maximum = self . y_maximum . value ( ) x_minimum = self . x_minimum . value ( ) x_maximum = self . x_maximum . value ( ) extent = [ x_minimum , y_minimum , x_maximum , y_maximum ] # Validate extent valid_flag = validate_geo_array ( extent ) if not valid_flag : message = self . tr ( 'The bounding box is not valid. Please make sure it is ' 'valid or check your projection!' ) # noinspection PyCallByClass,PyTypeChecker,PyArgumentList display_warning_message_box ( self , error_dialog_title , message ) # Unlock the bounding_box_group self . bounding_box_group . setEnabled ( True ) return # Validate features feature_types = self . get_checked_features ( ) if len ( feature_types ) < 1 : message = self . tr ( 'No feature selected. ' 'Please make sure you have checked one feature.' ) # noinspection PyCallByClass,PyTypeChecker,PyArgumentList display_warning_message_box ( self , error_dialog_title , message ) # Unlock the bounding_box_group self . bounding_box_group . setEnabled ( True ) return if self . radio_custom . isChecked ( ) : server_url = self . line_edit_custom . text ( ) if not server_url : # It's the place holder. server_url = STAGING_SERVER else : server_url = PRODUCTION_SERVER try : self . save_state ( ) self . require_directory ( ) # creating progress dialog for download self . progress_dialog = QProgressDialog ( self ) self . progress_dialog . setAutoClose ( False ) self . progress_dialog . setWindowTitle ( self . windowTitle ( ) ) for feature_type in feature_types : output_directory = self . output_directory . text ( ) if output_directory == '' : output_directory = temp_dir ( sub_dir = 'work' ) output_prefix = self . filename_prefix . text ( ) overwrite = self . overwrite_flag . isChecked ( ) output_base_file_path = self . get_output_base_path ( output_directory , output_prefix , feature_type , overwrite ) # noinspection PyTypeChecker download ( feature_type , output_base_file_path , extent , self . progress_dialog , server_url ) try : self . load_shapefile ( feature_type , output_base_file_path ) except FileMissingError as exception : display_warning_message_box ( self , error_dialog_title , str ( exception ) ) self . done ( QDialog . Accepted ) self . rectangle_map_tool . reset ( ) except CanceledImportDialogError : # don't show anything because this exception raised # when user canceling the import process directly pass except Exception as exception : # pylint: disable=broad-except # noinspection PyCallByClass,PyTypeChecker,PyArgumentList display_warning_message_box ( self , error_dialog_title , str ( exception ) ) self . progress_dialog . cancel ( ) self . progress_dialog . deleteLater ( ) finally : # Unlock the bounding_box_group self . bounding_box_group . setEnabled ( True ) | Do osm download and display it in QGIS . | 817 | 12 |
26,928 | def get_output_base_path ( self , output_directory , output_prefix , feature_type , overwrite ) : path = os . path . join ( output_directory , '%s%s' % ( output_prefix , feature_type ) ) if overwrite : # If a shapefile exists, we must remove it (only the .shp) shp = '%s.shp' % path if os . path . isfile ( shp ) : os . remove ( shp ) else : separator = '-' suffix = self . get_unique_file_path_suffix ( '%s.shp' % path , separator ) if suffix : path = os . path . join ( output_directory , '%s%s%s%s' % ( output_prefix , feature_type , separator , suffix ) ) return path | Get a full base name path to save the shapefile . | 185 | 12 |
26,929 | def require_directory ( self ) : path = self . output_directory . text ( ) if path == '' : # If let empty, we create an temporary directory return if os . path . exists ( path ) : return title = self . tr ( 'Directory %s not exist' ) % path question = self . tr ( 'Directory %s not exist. Do you want to create it?' ) % path # noinspection PyCallByClass,PyTypeChecker answer = QMessageBox . question ( self , title , question , QMessageBox . Yes | QMessageBox . No ) if answer == QMessageBox . Yes : if len ( path ) != 0 : os . makedirs ( path ) else : # noinspection PyCallByClass,PyTypeChecker,PyArgumentList display_warning_message_box ( self , self . tr ( 'InaSAFE error' ) , self . tr ( 'Output directory can not be empty.' ) ) raise CanceledImportDialogError ( ) else : raise CanceledImportDialogError ( ) | Ensure directory path entered in dialog exist . | 224 | 9 |
26,930 | def reject ( self ) : self . canvas . unsetMapTool ( self . rectangle_map_tool ) self . rectangle_map_tool . reset ( ) super ( OsmDownloaderDialog , self ) . reject ( ) | Redefinition of the method to remove the rectangle selection tool . | 48 | 13 |
26,931 | def add_exposure ( self , layer ) : self . _exposures . append ( layer ) self . _is_ready = False | Add an exposure layer in the analysis . | 30 | 8 |
26,932 | def get_parameter ( self ) : self . _parameter . value = self . _input . value ( ) return self . _parameter | Obtain the parameter object from the current widget state . | 31 | 11 |
26,933 | def set_widgets ( self ) : # First, list available layers in order to check if there are # any available layers. Note This will be repeated in # set_widgets_step_fc_hazlayer_from_canvas because we need # to list them again after coming back from the Keyword Wizard. self . parent . step_fc_hazlayer_from_canvas . list_compatible_canvas_layers ( ) lst_wdg = self . parent . step_fc_hazlayer_from_canvas . lstCanvasHazLayers if lst_wdg . count ( ) : wizard_name = self . parent . keyword_creation_wizard_name self . rbHazLayerFromCanvas . setText ( tr ( 'I would like to use a hazard layer already loaded in QGIS\n' '(launches the {wizard_name} for hazard if needed)' ) . format ( wizard_name = wizard_name ) ) self . rbHazLayerFromCanvas . setEnabled ( True ) self . rbHazLayerFromCanvas . click ( ) else : self . rbHazLayerFromCanvas . setText ( tr ( 'I would like to use a hazard layer already loaded in QGIS\n' '(no suitable layers found)' ) ) self . rbHazLayerFromCanvas . setEnabled ( False ) self . rbHazLayerFromBrowser . click ( ) # Set the memo labels on this and next (hazard) steps ( hazard , _ , hazard_constraints , _ ) = self . parent . selected_impact_function_constraints ( ) layer_geometry = hazard_constraints [ 'name' ] text = ( select_hazard_origin_question % ( layer_geometry , hazard [ 'name' ] ) ) self . lblSelectHazLayerOriginType . setText ( text ) text = ( select_hazlayer_from_canvas_question % ( layer_geometry , hazard [ 'name' ] ) ) self . parent . step_fc_hazlayer_from_canvas . lblSelectHazardLayer . setText ( text ) text = ( select_hazlayer_from_browser_question % ( layer_geometry , hazard [ 'name' ] ) ) self . parent . step_fc_hazlayer_from_browser . lblSelectBrowserHazLayer . setText ( text ) # Set icon icon_path = get_image_path ( hazard ) self . lblIconIFCWHazardOrigin . setPixmap ( QPixmap ( icon_path ) ) | Set widgets on the Hazard Layer Origin Type tab . | 575 | 10 |
26,934 | def to_html ( self ) : if self . text is None : return level = self . level if level > 6 : level = 6 return '<h%s%s><a id="%s"></a>%s%s</h%s>' % ( level , self . html_attributes ( ) , self . element_id , self . html_icon ( ) , self . text . to_html ( ) , level ) | Render a Heading MessageElement as html | 95 | 8 |
26,935 | def to_text ( self ) : if self . text is None : return level = '*' * self . level return '%s%s\n' % ( level , self . text ) | Render a Heading MessageElement as plain text | 42 | 9 |
26,936 | def extent_string_to_array ( extent_text ) : coordinates = extent_text . replace ( ' ' , '' ) . split ( ',' ) count = len ( coordinates ) if count != 4 : message = ( 'Extent need exactly 4 value but got %s instead' % count ) LOGGER . error ( message ) return None # parse the value to float type try : coordinates = [ float ( i ) for i in coordinates ] except ValueError as e : message = str ( e ) LOGGER . error ( message ) return None return coordinates | Convert an extent string to an array . | 116 | 9 |
26,937 | def extent_to_array ( extent , source_crs , dest_crs = None ) : if dest_crs is None : geo_crs = QgsCoordinateReferenceSystem ( ) geo_crs . createFromSrid ( 4326 ) else : geo_crs = dest_crs transform = QgsCoordinateTransform ( source_crs , geo_crs , QgsProject . instance ( ) ) # Get the clip area in the layer's crs transformed_extent = transform . transformBoundingBox ( extent ) geo_extent = [ transformed_extent . xMinimum ( ) , transformed_extent . yMinimum ( ) , transformed_extent . xMaximum ( ) , transformed_extent . yMaximum ( ) ] return geo_extent | Convert the supplied extent to geographic and return as an array . | 169 | 13 |
26,938 | def validate_geo_array ( extent ) : min_longitude = extent [ 0 ] min_latitude = extent [ 1 ] max_longitude = extent [ 2 ] max_latitude = extent [ 3 ] # min_latitude < max_latitude if min_latitude >= max_latitude : return False # min_longitude < max_longitude if min_longitude >= max_longitude : return False # -90 <= latitude <= 90 if min_latitude < - 90 or min_latitude > 90 : return False if max_latitude < - 90 or max_latitude > 90 : return False # -180 <= longitude <= 180 if min_longitude < - 180 or min_longitude > 180 : return False if max_longitude < - 180 or max_longitude > 180 : return False return True | Validate a geographic extent . | 182 | 6 |
26,939 | def clone_layer ( layer , keep_selection = True ) : if is_vector_layer ( layer ) : new_layer = QgsVectorLayer ( layer . source ( ) , layer . name ( ) , layer . providerType ( ) ) if keep_selection and layer . selectedFeatureCount ( ) > 0 : request = QgsFeatureRequest ( ) request . setFilterFids ( layer . selectedFeatureIds ( ) ) request . setFlags ( QgsFeatureRequest . NoGeometry ) iterator = layer . getFeatures ( request ) new_layer . setSelectedFeatures ( [ k . id ( ) for k in iterator ] ) else : new_layer = QgsRasterLayer ( layer . source ( ) , layer . name ( ) , layer . providerType ( ) ) new_layer . keywords = copy_layer_keywords ( layer . keywords ) return layer | Duplicate the layer by taking the same source and copying keywords . | 185 | 14 |
26,940 | def is_raster_y_inverted ( layer ) : info = gdal . Info ( layer . source ( ) , format = 'json' ) y_maximum = info [ 'cornerCoordinates' ] [ 'upperRight' ] [ 1 ] y_minimum = info [ 'cornerCoordinates' ] [ 'lowerRight' ] [ 1 ] return y_maximum < y_minimum | Check if the raster is upside down ie Y inverted . | 87 | 12 |
26,941 | def is_point_layer ( layer ) : try : return ( layer . type ( ) == QgsMapLayer . VectorLayer ) and ( layer . geometryType ( ) == QgsWkbTypes . PointGeometry ) except AttributeError : return False | Check if a QGIS layer is vector and its geometries are points . | 54 | 17 |
26,942 | def is_line_layer ( layer ) : try : return ( layer . type ( ) == QgsMapLayer . VectorLayer ) and ( layer . geometryType ( ) == QgsWkbTypes . LineGeometry ) except AttributeError : return False | Check if a QGIS layer is vector and its geometries are lines . | 54 | 17 |
26,943 | def is_polygon_layer ( layer ) : try : return ( layer . type ( ) == QgsMapLayer . VectorLayer ) and ( layer . geometryType ( ) == QgsWkbTypes . PolygonGeometry ) except AttributeError : return False | Check if a QGIS layer is vector and its geometries are polygons . | 56 | 18 |
26,944 | def layer_icon ( layer ) : if is_raster_layer ( layer ) : return QgsLayerItem . iconRaster ( ) elif is_point_layer ( layer ) : return QgsLayerItem . iconPoint ( ) elif is_line_layer ( layer ) : return QgsLayerItem . iconLine ( ) elif is_polygon_layer ( layer ) : return QgsLayerItem . iconPolygon ( ) else : return QgsLayerItem . iconDefault ( ) | Helper to get the layer icon . | 107 | 7 |
26,945 | def wkt_to_rectangle ( extent ) : geometry = QgsGeometry . fromWkt ( extent ) if not geometry . isGeosValid ( ) : return None polygon = geometry . asPolygon ( ) [ 0 ] if len ( polygon ) != 5 : return None if polygon [ 0 ] != polygon [ 4 ] : return None rectangle = QgsRectangle ( QgsPointXY ( polygon [ 0 ] . x ( ) , polygon [ 0 ] . y ( ) ) , QgsPointXY ( polygon [ 2 ] . x ( ) , polygon [ 2 ] . y ( ) ) ) return rectangle | Compute the rectangle from a WKT string . | 138 | 10 |
26,946 | def qgis_version_detailed ( ) : version = str ( Qgis . QGIS_VERSION_INT ) return [ int ( version [ 0 ] ) , int ( version [ 1 : 3 ] ) , int ( version [ 3 : ] ) ] | Get the detailed version of QGIS . | 57 | 9 |
26,947 | def _tab_changed ( self ) : current = self . tab_widget . currentWidget ( ) if current == self . analysisTab : self . btn_back . setEnabled ( False ) self . btn_next . setEnabled ( True ) elif current == self . reportingTab : if self . _current_index == 0 : # Only if the user is coming from the first tab self . _populate_reporting_tab ( ) self . reporting_options_layout . setEnabled ( self . _multi_exposure_if is not None ) self . btn_back . setEnabled ( True ) self . btn_next . setEnabled ( True ) else : self . btn_back . setEnabled ( True ) self . btn_next . setEnabled ( False ) self . _current_index = current | Triggered when the current tab is changed . | 176 | 10 |
26,948 | def ordered_expected_layers ( self ) : registry = QgsProject . instance ( ) layers = [ ] count = self . list_layers_in_map_report . count ( ) for i in range ( count ) : layer = self . list_layers_in_map_report . item ( i ) origin = layer . data ( LAYER_ORIGIN_ROLE ) if origin == FROM_ANALYSIS [ 'key' ] : key = layer . data ( LAYER_PURPOSE_KEY_OR_ID_ROLE ) parent = layer . data ( LAYER_PARENT_ANALYSIS_ROLE ) layers . append ( ( FROM_ANALYSIS [ 'key' ] , key , parent , None ) ) else : layer_id = layer . data ( LAYER_PURPOSE_KEY_OR_ID_ROLE ) layer = registry . mapLayer ( layer_id ) style_document = QDomDocument ( ) layer . exportNamedStyle ( style_document ) layers . append ( ( FROM_CANVAS [ 'key' ] , layer . name ( ) , full_layer_uri ( layer ) , style_document . toString ( ) ) ) return layers | Get an ordered list of layers according to users input . | 270 | 11 |
26,949 | def _add_layer_clicked ( self ) : layer = self . tree . selectedItems ( ) [ 0 ] origin = layer . data ( 0 , LAYER_ORIGIN_ROLE ) if origin == FROM_ANALYSIS [ 'key' ] : parent = layer . data ( 0 , LAYER_PARENT_ANALYSIS_ROLE ) key = layer . data ( 0 , LAYER_PURPOSE_KEY_OR_ID_ROLE ) item = QListWidgetItem ( '%s - %s' % ( layer . text ( 0 ) , parent ) ) item . setData ( LAYER_PARENT_ANALYSIS_ROLE , parent ) item . setData ( LAYER_PURPOSE_KEY_OR_ID_ROLE , key ) else : item = QListWidgetItem ( layer . text ( 0 ) ) layer_id = layer . data ( 0 , LAYER_PURPOSE_KEY_OR_ID_ROLE ) item . setData ( LAYER_PURPOSE_KEY_OR_ID_ROLE , layer_id ) item . setData ( LAYER_ORIGIN_ROLE , origin ) self . list_layers_in_map_report . addItem ( item ) self . tree . invisibleRootItem ( ) . removeChild ( layer ) self . tree . clearSelection ( ) | Add layer clicked . | 308 | 4 |
26,950 | def _remove_layer_clicked ( self ) : layer = self . list_layers_in_map_report . selectedItems ( ) [ 0 ] origin = layer . data ( LAYER_ORIGIN_ROLE ) if origin == FROM_ANALYSIS [ 'key' ] : key = layer . data ( LAYER_PURPOSE_KEY_OR_ID_ROLE ) parent = layer . data ( LAYER_PARENT_ANALYSIS_ROLE ) parent_item = self . tree . findItems ( parent , Qt . MatchContains | Qt . MatchRecursive , 0 ) [ 0 ] item = QTreeWidgetItem ( parent_item , [ definition ( key ) [ 'name' ] ] ) item . setData ( 0 , LAYER_PARENT_ANALYSIS_ROLE , parent ) else : parent_item = self . tree . findItems ( FROM_CANVAS [ 'name' ] , Qt . MatchContains | Qt . MatchRecursive , 0 ) [ 0 ] item = QTreeWidgetItem ( parent_item , [ layer . text ( ) ] ) layer_id = layer . data ( LAYER_PURPOSE_KEY_OR_ID_ROLE ) item . setData ( 0 , LAYER_PURPOSE_KEY_OR_ID_ROLE , layer_id ) item . setData ( 0 , LAYER_ORIGIN_ROLE , origin ) index = self . list_layers_in_map_report . indexFromItem ( layer ) self . list_layers_in_map_report . takeItem ( index . row ( ) ) self . list_layers_in_map_report . clearSelection ( ) | Remove layer clicked . | 381 | 4 |
26,951 | def move_layer_down ( self ) : layer = self . list_layers_in_map_report . selectedItems ( ) [ 0 ] index = self . list_layers_in_map_report . indexFromItem ( layer ) . row ( ) item = self . list_layers_in_map_report . takeItem ( index ) self . list_layers_in_map_report . insertItem ( index + 1 , item ) self . list_layers_in_map_report . item ( index + 1 ) . setSelected ( True ) | Move the layer down . | 125 | 5 |
26,952 | def _list_selection_changed ( self ) : items = self . list_layers_in_map_report . selectedItems ( ) self . remove_layer . setEnabled ( len ( items ) >= 1 ) if len ( items ) == 1 and self . list_layers_in_map_report . count ( ) >= 2 : index = self . list_layers_in_map_report . indexFromItem ( items [ 0 ] ) index = index . row ( ) if index == 0 : self . move_up . setEnabled ( False ) self . move_down . setEnabled ( True ) elif index == self . list_layers_in_map_report . count ( ) - 1 : self . move_up . setEnabled ( True ) self . move_down . setEnabled ( False ) else : self . move_up . setEnabled ( True ) self . move_down . setEnabled ( True ) else : self . move_up . setEnabled ( False ) self . move_down . setEnabled ( False ) | Selection has changed in the list . | 224 | 8 |
26,953 | def _populate_reporting_tab ( self ) : self . tree . clear ( ) self . add_layer . setEnabled ( False ) self . remove_layer . setEnabled ( False ) self . move_up . setEnabled ( False ) self . move_down . setEnabled ( False ) self . tree . setColumnCount ( 1 ) self . tree . setRootIsDecorated ( False ) self . tree . setHeaderHidden ( True ) analysis_branch = QTreeWidgetItem ( self . tree . invisibleRootItem ( ) , [ FROM_ANALYSIS [ 'name' ] ] ) analysis_branch . setFont ( 0 , bold_font ) analysis_branch . setExpanded ( True ) analysis_branch . setFlags ( Qt . ItemIsEnabled ) if self . _multi_exposure_if : expected = self . _multi_exposure_if . output_layers_expected ( ) for group , layers in list ( expected . items ( ) ) : group_branch = QTreeWidgetItem ( analysis_branch , [ group ] ) group_branch . setFont ( 0 , bold_font ) group_branch . setExpanded ( True ) group_branch . setFlags ( Qt . ItemIsEnabled ) for layer in layers : layer = definition ( layer ) if layer . get ( 'allowed_geometries' , None ) : item = QTreeWidgetItem ( group_branch , [ layer . get ( 'name' ) ] ) item . setData ( 0 , LAYER_ORIGIN_ROLE , FROM_ANALYSIS [ 'key' ] ) item . setData ( 0 , LAYER_PARENT_ANALYSIS_ROLE , group ) item . setData ( 0 , LAYER_PURPOSE_KEY_OR_ID_ROLE , layer [ 'key' ] ) item . setFlags ( Qt . ItemIsEnabled | Qt . ItemIsSelectable ) canvas_branch = QTreeWidgetItem ( self . tree . invisibleRootItem ( ) , [ FROM_CANVAS [ 'name' ] ] ) canvas_branch . setFont ( 0 , bold_font ) canvas_branch . setExpanded ( True ) canvas_branch . setFlags ( Qt . ItemIsEnabled ) # List layers from the canvas loaded_layers = list ( QgsProject . instance ( ) . mapLayers ( ) . values ( ) ) canvas_layers = self . iface . mapCanvas ( ) . layers ( ) flag = setting ( 'visibleLayersOnlyFlag' , expected_type = bool ) for loaded_layer in loaded_layers : if flag and loaded_layer not in canvas_layers : continue title = loaded_layer . name ( ) item = QTreeWidgetItem ( canvas_branch , [ title ] ) item . setData ( 0 , LAYER_ORIGIN_ROLE , FROM_CANVAS [ 'key' ] ) item . setData ( 0 , LAYER_PURPOSE_KEY_OR_ID_ROLE , loaded_layer . id ( ) ) item . setFlags ( Qt . ItemIsEnabled | Qt . ItemIsSelectable ) self . tree . resizeColumnToContents ( 0 ) | Populate trees about layers . | 704 | 6 |
26,954 | def validate_impact_function ( self ) : # Always set it to False self . btn_run . setEnabled ( False ) for combo in list ( self . combos_exposures . values ( ) ) : if combo . count ( ) == 1 : combo . setEnabled ( False ) hazard = layer_from_combo ( self . cbx_hazard ) aggregation = layer_from_combo ( self . cbx_aggregation ) exposures = [ ] for combo in list ( self . combos_exposures . values ( ) ) : exposures . append ( layer_from_combo ( combo ) ) exposures = [ layer for layer in exposures if layer ] multi_exposure_if = MultiExposureImpactFunction ( ) multi_exposure_if . hazard = hazard multi_exposure_if . exposures = exposures multi_exposure_if . debug = False multi_exposure_if . callback = self . progress_callback if aggregation : multi_exposure_if . use_selected_features_only = ( self . use_selected_only ) multi_exposure_if . aggregation = aggregation else : multi_exposure_if . crs = ( self . iface . mapCanvas ( ) . mapSettings ( ) . destinationCrs ( ) ) if len ( self . ordered_expected_layers ( ) ) != 0 : self . _multi_exposure_if . output_layers_ordered = ( self . ordered_expected_layers ( ) ) status , message = multi_exposure_if . prepare ( ) if status == PREPARE_SUCCESS : self . _multi_exposure_if = multi_exposure_if self . btn_run . setEnabled ( True ) send_static_message ( self , ready_message ( ) ) self . list_layers_in_map_report . clear ( ) return else : disable_busy_cursor ( ) send_error_message ( self , message ) self . _multi_exposure_if = None | Check validity of the current impact function . | 437 | 8 |
26,955 | def create_section ( aggregation_summary , analysis_layer , postprocessor_fields , section_header , use_aggregation = True , units_label = None , use_rounding = True , extra_component_args = None ) : if use_aggregation : return create_section_with_aggregation ( aggregation_summary , analysis_layer , postprocessor_fields , section_header , units_label = units_label , use_rounding = use_rounding , extra_component_args = extra_component_args ) else : return create_section_without_aggregation ( aggregation_summary , analysis_layer , postprocessor_fields , section_header , units_label = units_label , use_rounding = use_rounding , extra_component_args = extra_component_args ) | Create demographic section context . | 173 | 5 |
26,956 | def create_section_without_aggregation ( aggregation_summary , analysis_layer , postprocessor_fields , section_header , units_label = None , use_rounding = True , extra_component_args = None ) : aggregation_summary_fields = aggregation_summary . keywords [ 'inasafe_fields' ] analysis_layer_fields = analysis_layer . keywords [ 'inasafe_fields' ] # retrieving postprocessor postprocessors_fields_found = [ ] for output_field in postprocessor_fields [ 'fields' ] : if output_field [ 'key' ] in aggregation_summary_fields : postprocessors_fields_found . append ( output_field ) if not postprocessors_fields_found : return { } # figuring out displaced field try : analysis_layer_fields [ displaced_field [ 'key' ] ] aggregation_summary_fields [ displaced_field [ 'key' ] ] except KeyError : # no displaced field, can't show result return { } """Generating header name for columns.""" # First column header is aggregation title total_population_header = resolve_from_dictionary ( extra_component_args , [ 'defaults' , 'total_population_header' ] ) columns = [ section_header , total_population_header , ] """Generating values for rows.""" row_values = [ ] for idx , output_field in enumerate ( postprocessors_fields_found ) : name = output_field . get ( 'header_name' ) if not name : name = output_field . get ( 'name' ) row = [ ] if units_label or output_field . get ( 'unit' ) : unit = None if units_label : unit = units_label [ idx ] elif output_field . get ( 'unit' ) : unit = output_field . get ( 'unit' ) . get ( 'abbreviation' ) if unit : header_format = '{name} [{unit}]' else : header_format = '{name}' header = header_format . format ( name = name , unit = unit ) else : header_format = '{name}' header = header_format . format ( name = name ) row . append ( header ) # if no aggregation layer, then aggregation summary only contain one # feature field_name = analysis_layer_fields [ output_field [ 'key' ] ] value = value_from_field_name ( field_name , analysis_layer ) value = format_number ( value , use_rounding = use_rounding , is_population = True ) row . append ( value ) row_values . append ( row ) return { 'columns' : columns , 'rows' : row_values , } | Create demographic section context without aggregation . | 590 | 7 |
26,957 | def check_inputs ( compulsory_fields , fields ) : for field in compulsory_fields : # noinspection PyTypeChecker if not fields . get ( field [ 'key' ] ) : # noinspection PyTypeChecker msg = '%s not found in %s' % ( field [ 'key' ] , fields ) raise InvalidKeywordsForProcessingAlgorithm ( msg ) | Helper function to check if the layer has every compulsory fields . | 84 | 12 |
26,958 | def create_absolute_values_structure ( layer , fields ) : # Let's create a structure like : # key is the index of the field : (flat table, definition name) source_fields = layer . keywords [ 'inasafe_fields' ] absolute_fields = [ field [ 'key' ] for field in count_fields ] summaries = { } for field in source_fields : if field in absolute_fields : field_name = source_fields [ field ] index = layer . fields ( ) . lookupField ( field_name ) flat_table = FlatTable ( * fields ) summaries [ index ] = ( flat_table , field ) return summaries | Helper function to create the structure for absolute values . | 142 | 10 |
26,959 | def add_fields ( layer , absolute_values , static_fields , dynamic_structure ) : for new_dynamic_field in dynamic_structure : field_definition = new_dynamic_field [ 0 ] unique_values = new_dynamic_field [ 1 ] for column in unique_values : if ( column == '' or ( hasattr ( column , 'isNull' ) and column . isNull ( ) ) ) : column = 'NULL' field = create_field_from_definition ( field_definition , column ) layer . addAttribute ( field ) key = field_definition [ 'key' ] % column value = field_definition [ 'field_name' ] % column layer . keywords [ 'inasafe_fields' ] [ key ] = value for static_field in static_fields : field = create_field_from_definition ( static_field ) layer . addAttribute ( field ) # noinspection PyTypeChecker layer . keywords [ 'inasafe_fields' ] [ static_field [ 'key' ] ] = ( static_field [ 'field_name' ] ) # For each absolute values for absolute_field in list ( absolute_values . keys ( ) ) : field_definition = definition ( absolute_values [ absolute_field ] [ 1 ] ) field = create_field_from_definition ( field_definition ) layer . addAttribute ( field ) key = field_definition [ 'key' ] value = field_definition [ 'field_name' ] layer . keywords [ 'inasafe_fields' ] [ key ] = value | Function to add fields needed in the output layer . | 334 | 10 |
26,960 | def reset ( self ) : self . start_point = self . end_point = None self . is_emitting_point = False self . rubber_band . reset ( QgsWkbTypes . PolygonGeometry ) | Clear the rubber band for the analysis extents . | 48 | 10 |
26,961 | def canvasPressEvent ( self , e ) : self . start_point = self . toMapCoordinates ( e . pos ( ) ) self . end_point = self . start_point self . is_emitting_point = True self . show_rectangle ( self . start_point , self . end_point ) | Handle canvas press events so we know when user is capturing the rect . | 70 | 14 |
26,962 | def canvasReleaseEvent ( self , e ) : _ = e # NOQA self . is_emitting_point = False self . rectangle_created . emit ( ) | Handle canvas release events has finished capturing e . | 36 | 9 |
26,963 | def show_rectangle ( self , start_point , end_point ) : self . rubber_band . reset ( QgsWkbTypes . PolygonGeometry ) if ( start_point . x ( ) == end_point . x ( ) or start_point . y ( ) == end_point . y ( ) ) : return point1 = start_point point2 = QgsPointXY ( end_point . x ( ) , start_point . y ( ) ) point3 = end_point point4 = QgsPointXY ( start_point . x ( ) , end_point . y ( ) ) update_canvas = False self . rubber_band . addPoint ( point1 , update_canvas ) self . rubber_band . addPoint ( point2 , update_canvas ) self . rubber_band . addPoint ( point3 , update_canvas ) self . rubber_band . addPoint ( point4 , update_canvas ) # noinspection PyArgumentEqualDefault # no False so canvas will update # close the polygon otherwise it shows as a filled rect self . rubber_band . addPoint ( point1 ) self . rubber_band . show ( ) | Show the rectangle on the canvas . | 256 | 7 |
26,964 | def rectangle ( self ) : if self . start_point is None or self . end_point is None : return QgsRectangle ( ) elif self . start_point . x ( ) == self . end_point . x ( ) or self . start_point . y ( ) == self . end_point . y ( ) : return QgsRectangle ( ) return QgsRectangle ( self . start_point , self . end_point ) | Accessor for the rectangle . | 97 | 6 |
26,965 | def deactivate ( self ) : self . rubber_band . reset ( QgsWkbTypes . PolygonGeometry ) QgsMapTool . deactivate ( self ) self . deactivated . emit ( ) | Disable the tool . | 44 | 4 |
26,966 | def clean_layer ( layer ) : output_layer_name = clean_geometry_steps [ 'output_layer_name' ] output_layer_name = output_layer_name % layer . keywords [ 'layer_purpose' ] # start editing layer . startEditing ( ) count = 0 # iterate through all features request = QgsFeatureRequest ( ) . setSubsetOfAttributes ( [ ] ) for feature in layer . getFeatures ( request ) : geom = feature . geometry ( ) was_valid , geometry_cleaned = geometry_checker ( geom ) if was_valid : # Do nothing if it was valid pass elif not was_valid and geometry_cleaned : # Update the geometry if it was not valid, and clean now layer . changeGeometry ( feature . id ( ) , geometry_cleaned , True ) else : # Delete if it was not valid and not able to be cleaned count += 1 layer . deleteFeature ( feature . id ( ) ) if count : LOGGER . critical ( '%s features have been removed from %s because of invalid ' 'geometries.' % ( count , layer . name ( ) ) ) else : LOGGER . info ( 'No feature has been removed from the layer: %s' % layer . name ( ) ) # save changes layer . commitChanges ( ) layer . keywords [ 'title' ] = output_layer_name check_layer ( layer ) return layer | Clean a vector layer . | 306 | 5 |
26,967 | def geometry_checker ( geometry ) : if geometry is None : # The geometry can be None. return False , None if geometry . isGeosValid ( ) : return True , geometry else : new_geom = geometry . makeValid ( ) if new_geom . isGeosValid ( ) : return False , new_geom else : # Make valid was not enough, the feature will be deleted. return False , None | Perform a cleaning if the geometry is not valid . | 91 | 11 |
26,968 | def remove_provenance_project_variables ( ) : project_context_scope = QgsExpressionContextUtils . projectScope ( QgsProject . instance ( ) ) existing_variable_names = project_context_scope . variableNames ( ) # Save the existing variables that's not provenance variable. existing_variables = { } for existing_variable_name in existing_variable_names : existing_variables [ existing_variable_name ] = project_context_scope . variable ( existing_variable_name ) for the_provenance in provenance_list : if the_provenance [ 'provenance_key' ] in existing_variables : existing_variables . pop ( the_provenance [ 'provenance_key' ] ) # Removing generated key from dictionary (e.g. # action_checklist__0__item_list__0) will_be_removed = [ ] for existing_variable in existing_variables : for the_provenance in provenance_list : if existing_variable . startswith ( the_provenance [ 'provenance_key' ] ) : will_be_removed . append ( existing_variable ) continue for variable in will_be_removed : existing_variables . pop ( variable ) # Need to change to None, to be able to store it back. non_null_existing_variables = { } for k , v in list ( existing_variables . items ( ) ) : if v is None or ( hasattr ( v , 'isNull' ) and v . isNull ( ) ) : non_null_existing_variables [ k ] = None else : non_null_existing_variables [ k ] = v # This method will set non_null_existing_variables, and remove the # other variable QgsExpressionContextUtils . setProjectVariables ( QgsProject . instance ( ) , non_null_existing_variables ) | Removing variables from provenance data . | 420 | 8 |
26,969 | def aggregation ( self , layer ) : # We need to disconnect first. if self . _aggregation and self . use_selected_features_only : self . _aggregation . selectionChanged . disconnect ( self . validate_impact_function ) self . _aggregation = layer if self . use_selected_features_only and layer : self . _aggregation . selectionChanged . connect ( self . validate_impact_function ) | Setter for the current aggregation layer . | 90 | 8 |
26,970 | def _show_organisation_logo ( self ) : dock_width = float ( self . width ( ) ) # Don't let the image be more tha 100px height maximum_height = 100.0 # px pixmap = QPixmap ( self . organisation_logo_path ) if pixmap . height ( ) < 1 or pixmap . width ( ) < 1 : return height_ratio = maximum_height / pixmap . height ( ) maximum_width = int ( pixmap . width ( ) * height_ratio ) # Don't let the image be more than the dock width wide if maximum_width > dock_width : width_ratio = dock_width / float ( pixmap . width ( ) ) maximum_height = int ( pixmap . height ( ) * width_ratio ) maximum_width = dock_width too_high = pixmap . height ( ) > maximum_height too_wide = pixmap . width ( ) > dock_width if too_wide or too_high : pixmap = pixmap . scaled ( maximum_width , maximum_height , Qt . KeepAspectRatio ) self . organisation_logo . setMaximumWidth ( maximum_width ) # We have manually scaled using logic above self . organisation_logo . setScaledContents ( False ) self . organisation_logo . setPixmap ( pixmap ) self . organisation_logo . show ( ) | Show the organisation logo in the dock if possible . | 317 | 10 |
26,971 | def save_auxiliary_files ( self , layer , destination ) : enable_busy_cursor ( ) auxiliary_files = [ 'xml' , 'json' ] for auxiliary_file in auxiliary_files : source_basename = os . path . splitext ( layer . source ( ) ) [ 0 ] source_file = "%s.%s" % ( source_basename , auxiliary_file ) destination_basename = os . path . splitext ( destination ) [ 0 ] destination_file = "%s.%s" % ( destination_basename , auxiliary_file ) # noinspection PyBroadException,PyBroadException try : if os . path . isfile ( source_file ) : shutil . copy ( source_file , destination_file ) except ( OSError , IOError ) : display_critical_message_bar ( title = self . tr ( 'Error while saving' ) , message = self . tr ( 'The destination location must be writable.' ) , iface_object = self . iface ) except Exception : # pylint: disable=broad-except display_critical_message_bar ( title = self . tr ( 'Error while saving' ) , message = self . tr ( 'Something went wrong.' ) , iface_object = self . iface ) disable_busy_cursor ( ) | Save auxiliary files when using the save as function . | 292 | 10 |
26,972 | def index_changed_aggregation_layer_combo ( self , index ) : if index == 0 : # No aggregation layer, we should display the user requested extent self . aggregation = None extent = setting ( 'user_extent' , None , str ) if extent : extent = QgsGeometry . fromWkt ( extent ) if not extent . isGeosValid ( ) : extent = None crs = setting ( 'user_extent_crs' , None , str ) if crs : crs = QgsCoordinateReferenceSystem ( crs ) if not crs . isValid ( ) : crs = None mode = setting ( 'analysis_extents_mode' , HAZARD_EXPOSURE_VIEW ) if crs and extent and mode == HAZARD_EXPOSURE_BOUNDINGBOX : self . extent . set_user_extent ( extent , crs ) else : # We have one aggregation layer. We should not display the user # extent. self . extent . clear_user_analysis_extent ( ) self . aggregation = layer_from_combo ( self . aggregation_layer_combo ) self . validate_impact_function ( ) | Automatic slot executed when the Aggregation combo is changed . | 256 | 12 |
26,973 | def toggle_aggregation_layer_combo ( self ) : selected_hazard_layer = layer_from_combo ( self . hazard_layer_combo ) selected_exposure_layer = layer_from_combo ( self . exposure_layer_combo ) # more than 1 because No aggregation is always there if ( ( self . aggregation_layer_combo . count ( ) > 1 ) and ( selected_hazard_layer is not None ) and ( selected_exposure_layer is not None ) ) : self . aggregation_layer_combo . setEnabled ( True ) else : self . aggregation_layer_combo . setCurrentIndex ( 0 ) self . aggregation_layer_combo . setEnabled ( False ) | Toggle the aggregation combo enabled status . | 157 | 8 |
26,974 | def unblock_signals ( self ) : self . aggregation_layer_combo . blockSignals ( False ) self . exposure_layer_combo . blockSignals ( False ) self . hazard_layer_combo . blockSignals ( False ) | Let the combos listen for event changes again . | 55 | 9 |
26,975 | def block_signals ( self ) : self . disconnect_layer_listener ( ) self . aggregation_layer_combo . blockSignals ( True ) self . exposure_layer_combo . blockSignals ( True ) self . hazard_layer_combo . blockSignals ( True ) | Prevent the combos and dock listening for event changes . | 64 | 11 |
26,976 | def debug_group_toggled ( self ) : use_debug = self . use_debug_action . isChecked ( ) set_setting ( 'use_debug_analysis' , use_debug ) disable_rounding = self . disable_rounding_action . isChecked ( ) set_setting ( 'disable_rounding' , disable_rounding ) if use_debug or disable_rounding : self . debug_group_button . setStyleSheet ( 'QToolButton{ background: rgb(244, 137, 137);}' ) else : self . debug_group_button . setStyleSheet ( '' ) | Helper to set a color on the debug button to know if it s debugging . | 138 | 16 |
26,977 | def show_print_dialog ( self ) : if not self . impact_function : # Now try to read the keywords and show them in the dock try : active_layer = self . iface . activeLayer ( ) keywords = self . keyword_io . read_keywords ( active_layer ) provenances = keywords . get ( 'provenance_data' , { } ) extra_keywords = keywords . get ( 'extra_keywords' , { } ) is_multi_exposure = ( extra_keywords . get ( extra_keyword_analysis_type [ 'key' ] ) == ( MULTI_EXPOSURE_ANALYSIS_FLAG ) ) if provenances and is_multi_exposure : self . impact_function = ( MultiExposureImpactFunction . load_from_output_metadata ( keywords ) ) else : self . impact_function = ( ImpactFunction . load_from_output_metadata ( keywords ) ) except ( KeywordNotFoundError , HashNotFoundError , InvalidParameterError , NoKeywordsFoundError , MetadataReadError , # AttributeError This is hiding some real error. ET ) as e : # Added this check in 3.2 for #1861 active_layer = self . iface . activeLayer ( ) LOGGER . debug ( e ) if active_layer is None : if self . conflicting_plugin_detected : send_static_message ( self , conflicting_plugin_message ( ) ) else : send_static_message ( self , getting_started_message ( ) ) else : show_no_keywords_message ( self ) except Exception as e : # pylint: disable=broad-except error_message = get_error_message ( e ) send_error_message ( self , error_message ) if self . impact_function : dialog = PrintReportDialog ( self . impact_function , self . iface , dock = self , parent = self ) dialog . show ( ) else : display_critical_message_bar ( "InaSAFE" , self . tr ( 'Please select a valid layer before printing. ' 'No Impact Function found.' ) , iface_object = self ) | Open the print dialog | 468 | 4 |
26,978 | def show_busy ( self ) : self . progress_bar . show ( ) self . question_group . setEnabled ( False ) self . question_group . setVisible ( False ) enable_busy_cursor ( ) self . repaint ( ) qApp . processEvents ( ) self . busy = True | Hide the question group box and enable the busy cursor . | 68 | 11 |
26,979 | def hide_busy ( self , check_next_impact = True ) : self . progress_bar . hide ( ) self . show_question_button . setVisible ( True ) self . question_group . setEnabled ( True ) self . question_group . setVisible ( False ) if check_next_impact : # We check if we can run an IF self . validate_impact_function ( ) self . repaint ( ) disable_busy_cursor ( ) self . busy = False | A helper function to indicate processing is done . | 108 | 9 |
26,980 | def show_impact ( self , report_path ) : # We can display an impact report. # We need to open the file in UTF-8, the HTML may have some accents with codecs . open ( report_path , 'r' , 'utf-8' ) as report_file : report = report_file . read ( ) self . print_button . setEnabled ( True ) # right now send the report as html texts, not message send_static_message ( self , report ) # also hide the question and show the show question button self . show_question_button . setVisible ( True ) self . question_group . setEnabled ( True ) self . question_group . setVisible ( False ) | Show the report . | 153 | 4 |
26,981 | def show_generic_keywords ( self , layer ) : keywords = KeywordIO ( layer ) self . print_button . setEnabled ( False ) try : message = keywords . to_message ( ) send_static_message ( self , message ) except InvalidMessageItemError : # FIXME (elpaso) pass self . show_question_button . setVisible ( False ) self . question_group . setEnabled ( True ) self . question_group . setVisible ( True ) | Show the keywords defined for the active layer . | 105 | 9 |
26,982 | def save_state ( self ) : state = { 'hazard' : self . hazard_layer_combo . currentText ( ) , 'exposure' : self . exposure_layer_combo . currentText ( ) , 'aggregation' : self . aggregation_layer_combo . currentText ( ) , 'report' : self . results_webview . page ( ) . currentFrame ( ) . toHtml ( ) } self . state = state | Save the current state of the ui to an internal class member . | 98 | 14 |
26,983 | def restore_state ( self ) : if self . state is None : return for myCount in range ( 0 , self . exposure_layer_combo . count ( ) ) : item_text = self . exposure_layer_combo . itemText ( myCount ) if item_text == self . state [ 'exposure' ] : self . exposure_layer_combo . setCurrentIndex ( myCount ) break for myCount in range ( 0 , self . hazard_layer_combo . count ( ) ) : item_text = self . hazard_layer_combo . itemText ( myCount ) if item_text == self . state [ 'hazard' ] : self . hazard_layer_combo . setCurrentIndex ( myCount ) break for myCount in range ( 0 , self . aggregation_layer_combo . count ( ) ) : item_text = self . aggregation_layer_combo . itemText ( myCount ) if item_text == self . state [ 'aggregation' ] : self . aggregation_layer_combo . setCurrentIndex ( myCount ) break self . results_webview . setHtml ( self . state [ 'report' ] ) | Restore the state of the dock to the last known state . | 254 | 13 |
26,984 | def define_user_analysis_extent ( self , extent , crs ) : extent = QgsGeometry . fromRect ( extent ) self . extent . set_user_extent ( extent , crs ) self . validate_impact_function ( ) | Slot called when user has defined a custom analysis extent . | 55 | 11 |
26,985 | def _search_inasafe_layer ( self ) : selected_nodes = self . iface . layerTreeView ( ) . selectedNodes ( ) for selected_node in selected_nodes : tree_layers = [ child for child in selected_node . children ( ) if ( isinstance ( child , QgsLayerTreeLayer ) ) ] for tree_layer in tree_layers : layer = tree_layer . layer ( ) keywords = self . keyword_io . read_keywords ( layer ) if keywords . get ( 'inasafe_fields' ) : return layer | Search for an inasafe layer in an active group . | 124 | 12 |
26,986 | def _visible_layers_count ( self ) : treeroot = QgsProject . instance ( ) . layerTreeRoot ( ) return len ( [ lyr for lyr in treeroot . findLayers ( ) if lyr . isVisible ( ) ] ) | Calculate the number of visible layers in the legend . | 56 | 12 |
26,987 | def _validate_question_area ( self ) : hazard_index = self . hazard_layer_combo . currentIndex ( ) exposure_index = self . exposure_layer_combo . currentIndex ( ) if hazard_index == - 1 or exposure_index == - 1 : if self . conflicting_plugin_detected : message = conflicting_plugin_message ( ) else : message = getting_started_message ( ) return False , message else : return True , None | Helper method to evaluate the current state of the dialog . | 101 | 11 |
26,988 | def default_value ( self , default_value ) : # For custom value if default_value not in self . default_values : if len ( self . default_labels ) == len ( self . default_values ) : self . default_values [ - 1 ] = default_value else : self . default_values . append ( default_value ) self . _default_value = default_value | Setter for default_value . | 85 | 7 |
26,989 | def classFactory ( iface ) : # Try to import submodule to check if there are present. try : from parameters . generic_parameter import GenericParameter except ImportError : # Don't use safe.utilities.i18n.tr as we need to be outside of `safe`. # Some safe functions will import safe_extras.parameters QMessageBox . warning ( None , QCoreApplication . translate ( '@default' , 'InaSAFE submodule not found' ) , QCoreApplication . translate ( '@default' , 'InaSAFE could not find the submodule "parameters". ' 'You should do "git submodule update" or if you need a new ' 'clone, do "git clone --recursive git@github.com:inasafe/' 'inasafe.git". If this is already a new clone, you should ' 'do "git submodule init" before "git submodule update".' 'Finally, restart QGIS.' ) ) from . safe . plugin import Plugin return Plugin ( iface ) | Load Plugin class from file Plugin . | 225 | 7 |
26,990 | def metadata_converter_help ( ) : message = m . Message ( ) message . add ( m . Brand ( ) ) message . add ( heading ( ) ) message . add ( content ( ) ) return message | Help message for metadata converter Dialog . | 46 | 8 |
26,991 | def qt_at_least ( needed_version , test_version = None ) : major , minor , patch = needed_version . split ( '.' ) needed_version = '0x0%s0%s0%s' % ( major , minor , patch ) needed_version = int ( needed_version , 0 ) installed_version = Qt . QT_VERSION if test_version is not None : installed_version = test_version if needed_version <= installed_version : return True else : return False | Check if the installed Qt version is greater than the requested | 112 | 11 |
26,992 | def disable_busy_cursor ( ) : while QgsApplication . instance ( ) . overrideCursor ( ) is not None and QgsApplication . instance ( ) . overrideCursor ( ) . shape ( ) == QtCore . Qt . WaitCursor : QgsApplication . instance ( ) . restoreOverrideCursor ( ) | Disable the hourglass cursor and listen for layer changes . | 70 | 11 |
26,993 | def subcategories_for_layer ( self ) : purpose = self . parent . step_kw_purpose . selected_purpose ( ) layer_geometry_key = self . parent . get_layer_geometry_key ( ) if purpose == layer_purpose_hazard : return hazards_for_layer ( layer_geometry_key ) elif purpose == layer_purpose_exposure : return exposures_for_layer ( layer_geometry_key ) | Return a list of valid subcategories for a layer . Subcategory is hazard type or exposure type . | 98 | 21 |
26,994 | def on_lstSubcategories_itemSelectionChanged ( self ) : self . clear_further_steps ( ) # Set widgets subcategory = self . selected_subcategory ( ) # Exit if no selection if not subcategory : return # Set description label self . lblDescribeSubcategory . setText ( subcategory [ 'description' ] ) icon_path = get_image_path ( subcategory ) self . lblIconSubcategory . setPixmap ( QPixmap ( icon_path ) ) # Enable the next button self . parent . pbnNext . setEnabled ( True ) | Update subcategory description label . | 130 | 6 |
26,995 | def selected_subcategory ( self ) : item = self . lstSubcategories . currentItem ( ) try : return definition ( item . data ( QtCore . Qt . UserRole ) ) except ( AttributeError , NameError ) : return None | Obtain the subcategory selected by user . | 53 | 9 |
26,996 | def set_widgets ( self ) : self . clear_further_steps ( ) # Set widgets purpose = self . parent . step_kw_purpose . selected_purpose ( ) self . lstSubcategories . clear ( ) self . lblDescribeSubcategory . setText ( '' ) self . lblIconSubcategory . setPixmap ( QPixmap ( ) ) self . lblSelectSubcategory . setText ( get_question_text ( '%s_question' % purpose [ 'key' ] ) ) for i in self . subcategories_for_layer ( ) : # noinspection PyTypeChecker item = QListWidgetItem ( i [ 'name' ] , self . lstSubcategories ) # noinspection PyTypeChecker item . setData ( QtCore . Qt . UserRole , i [ 'key' ] ) self . lstSubcategories . addItem ( item ) # Check if layer keywords are already assigned key = self . parent . step_kw_purpose . selected_purpose ( ) [ 'key' ] keyword = self . parent . get_existing_keyword ( key ) # Overwrite the keyword if it's KW mode embedded in IFCW mode if self . parent . parent_step : keyword = self . parent . get_parent_mode_constraints ( ) [ 1 ] [ 'key' ] # Set values based on existing keywords or parent mode if keyword : subcategories = [ ] for index in range ( self . lstSubcategories . count ( ) ) : item = self . lstSubcategories . item ( index ) subcategories . append ( item . data ( QtCore . Qt . UserRole ) ) if keyword in subcategories : self . lstSubcategories . setCurrentRow ( subcategories . index ( keyword ) ) self . auto_select_one_item ( self . lstSubcategories ) | Set widgets on the Subcategory tab . | 414 | 8 |
26,997 | def select_output_directory ( self ) : # Input layer input_layer_path = self . layer . source ( ) input_file_name = os . path . basename ( input_layer_path ) input_extension = os . path . splitext ( input_file_name ) [ 1 ] # Get current path current_file_path = self . output_path_line_edit . text ( ) if not current_file_path or not os . path . exists ( current_file_path ) : current_file_path = input_layer_path # Filtering based on input layer extension_mapping = { '.shp' : tr ( 'Shapefile (*.shp);;' ) , '.geojson' : tr ( 'GeoJSON (*.geojson);;' ) , '.tif' : tr ( 'Raster TIF/TIFF (*.tif, *.tiff);;' ) , '.tiff' : tr ( 'Raster TIF/TIFF (*.tiff, *.tiff);;' ) , '.asc' : tr ( 'Raster ASCII File (*.asc);;' ) , } # Open File Dialog file_path , __ = QFileDialog . getSaveFileName ( self , tr ( 'Output File' ) , current_file_path , extension_mapping [ input_extension ] ) if file_path : self . output_path_line_edit . setText ( file_path ) | Select output directory | 320 | 3 |
26,998 | def show_current_metadata ( self ) : LOGGER . debug ( 'Showing layer: ' + self . layer . name ( ) ) keywords = KeywordIO ( self . layer ) content_html = keywords . to_message ( ) . to_html ( ) full_html = html_header ( ) + content_html + html_footer ( ) self . metadata_preview_web_view . setHtml ( full_html ) | Show metadata of the current selected layer . | 96 | 8 |
26,999 | def get_user_name ( ) : if sys . platform == 'win32' : #user = os.getenv('USERPROFILE') user = os . getenv ( 'USERNAME' ) else : user = os . getenv ( 'LOGNAME' ) return user | Get user name provide by operating system | 59 | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.