idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
27,000 | def mmi_ramp_roman ( raster_layer ) : items = [ ] sorted_mmi_scale = sorted ( earthquake_mmi_scale [ 'classes' ] , key = itemgetter ( 'value' ) ) for class_max in sorted_mmi_scale : colour = class_max [ 'color' ] label = '%s' % class_max [ 'key' ] ramp_item = QgsColorRampShader . ColorRampItem ( class_max [ 'value' ] ,... | Generate an mmi ramp using range of 1 - 10 on roman . |
27,001 | def load_layer_from_registry ( layer_path ) : the_layer = load_layer ( layer_path ) [ 0 ] layers = QgsProject . instance ( ) . mapLayers ( ) for _ , layer in list ( layers . items ( ) ) : if full_layer_uri ( layer ) == full_layer_uri ( the_layer ) : monkey_patch_keywords ( layer ) return layer return the_layer | Helper method to load a layer from registry if its already there . |
27,002 | def reclassify_value ( one_value , ranges ) : if ( one_value is None or ( hasattr ( one_value , 'isNull' ) and one_value . isNull ( ) ) ) : return None for threshold_id , threshold in list ( ranges . items ( ) ) : value_min = threshold [ 0 ] value_max = threshold [ 1 ] if value_min == value_max and value_max == one_val... | This function will return the classified value according to ranges . |
27,003 | def decode_full_layer_uri ( full_layer_uri_string ) : if not full_layer_uri_string : return None , None split = full_layer_uri_string . split ( '|qgis_provider=' ) if len ( split ) == 1 : return split [ 0 ] , None else : return split | Decode the full layer URI . |
27,004 | def load_layer ( full_layer_uri_string , name = None , provider = None ) : if provider : layer_path = full_layer_uri_string else : layer_path , provider = decode_full_layer_uri ( full_layer_uri_string ) if not provider : if '|' in layer_path : clean_uri = layer_path . split ( '|' ) [ 0 ] else : clean_uri = layer_path i... | Helper to load and return a single QGIS layer based on our layer URI . |
27,005 | def load_layer_with_provider ( layer_uri , provider , layer_name = 'tmp' ) : if provider in RASTER_DRIVERS : return QgsRasterLayer ( layer_uri , layer_name , provider ) elif provider in VECTOR_DRIVERS : return QgsVectorLayer ( layer_uri , layer_name , provider ) else : return None | Load a layer with a specific driver . |
27,006 | def load_layer_without_provider ( layer_uri , layer_name = 'tmp' ) : layer = QgsVectorLayer ( layer_uri , layer_name , VECTOR_DRIVERS [ 0 ] ) if layer . isValid ( ) : return layer layer = QgsRasterLayer ( layer_uri , layer_name , RASTER_DRIVERS [ 0 ] ) if layer . isValid ( ) : return layer for driver in VECTOR_DRIVERS ... | Helper to load a layer when don t know the driver . |
27,007 | def clip ( layer_to_clip , mask_layer ) : output_layer_name = clip_steps [ 'output_layer_name' ] output_layer_name = output_layer_name % ( layer_to_clip . keywords [ 'layer_purpose' ] ) parameters = { 'INPUT' : layer_to_clip , 'OVERLAY' : mask_layer , 'OUTPUT' : 'memory:' } initialize_processing ( ) feedback = create_p... | Clip a vector layer with another . |
27,008 | def download ( feature_type , output_base_path , extent , progress_dialog = None , server_url = None ) : if not server_url : server_url = PRODUCTION_SERVER min_longitude = extent [ 0 ] min_latitude = extent [ 1 ] max_longitude = extent [ 2 ] max_latitude = extent [ 3 ] box = ( '{min_longitude},{min_latitude},{max_longi... | Download shapefiles from Kartoza server . |
27,009 | def fetch_zip ( url , output_path , feature_type , progress_dialog = None ) : LOGGER . debug ( 'Downloading file from URL: %s' % url ) LOGGER . debug ( 'Downloading to: %s' % output_path ) if progress_dialog : progress_dialog . show ( ) progress_dialog . setMaximum ( 0 ) progress_dialog . setMinimum ( 0 ) progress_dial... | Download zip containing shp file and write to output_path . |
27,010 | def extract_zip ( zip_path , destination_base_path ) : handle = open ( zip_path , 'rb' ) zip_file = zipfile . ZipFile ( handle ) for name in zip_file . namelist ( ) : extension = os . path . splitext ( name ) [ 1 ] output_final_path = '%s%s' % ( destination_base_path , extension ) output_file = open ( output_final_path... | Extract different extensions to the destination base path . |
27,011 | def get_question_text ( constant ) : if constant in dir ( safe . gui . tools . wizard . wizard_strings ) : return getattr ( safe . gui . tools . wizard . wizard_strings , constant ) else : return '<b>MISSING CONSTANT: %s</b>' % constant | Find a constant by name and return its value . |
27,012 | def layers_intersect ( layer_a , layer_b ) : extent_a = layer_a . extent ( ) extent_b = layer_b . extent ( ) if layer_a . crs ( ) != layer_b . crs ( ) : coord_transform = QgsCoordinateTransform ( layer_a . crs ( ) , layer_b . crs ( ) , QgsProject . instance ( ) ) extent_b = ( coord_transform . transform ( extent_b , Qg... | Check if extents of two layers intersect . |
27,013 | def get_inasafe_default_value_fields ( qsetting , field_key ) : labels = [ tr ( 'Global (%s)' ) , tr ( 'Do not report' ) , tr ( 'Custom' ) ] values = [ get_inasafe_default_value_qsetting ( qsetting , GLOBAL , field_key ) , None , get_inasafe_default_value_qsetting ( qsetting , RECENT , field_key ) ] return labels , val... | Obtain default value for a field with default value . |
27,014 | def clear_layout ( layout ) : if layout is not None : while layout . count ( ) : item = layout . takeAt ( 0 ) widget = item . widget ( ) if widget is not None : widget . close ( ) widget . deleteLater ( ) else : clear_layout ( item . layout ( ) ) layout . removeItem ( item ) del item | Clear layout content . |
27,015 | def skip_inasafe_field ( layer , inasafe_fields ) : for inasafe_field in inasafe_fields : for field in layer . fields ( ) : if isinstance ( inasafe_field [ 'type' ] , list ) : if field . type ( ) in inasafe_field [ 'type' ] : return False else : if field . type ( ) == inasafe_field [ 'type' ] : return False return True | Check if it possible to skip inasafe field step . |
27,016 | def get_image_path ( definition ) : path = resources_path ( 'img' , 'wizard' , 'keyword-subcategory-%s.svg' % definition [ 'key' ] ) if os . path . exists ( path ) : return path else : return not_set_image_path | Helper to get path of image from a definition in resource directory . |
27,017 | def recompute_counts ( layer ) : output_layer_name = recompute_counts_steps [ 'output_layer_name' ] fields = layer . keywords [ 'inasafe_fields' ] if size_field [ 'key' ] not in fields : msg = '%s not found in %s' % ( size_field [ 'key' ] , layer . keywords [ 'title' ] ) raise InvalidKeywordsForProcessingAlgorithm ( ms... | Recompute counts according to the size field and the new size . |
27,018 | def multi_exposure_aggregation_summary ( aggregation , intermediate_layers ) : target_index_field_name = ( aggregation . keywords [ 'inasafe_fields' ] [ aggregation_id_field [ 'key' ] ] ) aggregation . startEditing ( ) request = QgsFeatureRequest ( ) request . setFlags ( QgsFeatureRequest . NoGeometry ) for layer in in... | Merge intermediate aggregations into one aggregation summary . |
27,019 | 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 . ... | Action when output file name is changed . |
27,020 | 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... | Action when input file name is changed . |
27,021 | 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... | Action when input place layer name is changed . |
27,022 | 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 [ : ... | Create default output location based on input location . |
27,023 | 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' ) : QMessageBox . warning ( self , tr ( 'InaSAFE' ) , tr ( 'Output file nam... | Handler for when OK is clicked . |
27,024 | def on_open_input_tool_clicked ( self ) : input_path = self . input_path . text ( ) if not input_path : input_path = os . path . expanduser ( '~' ) filename , __ = QFileDialog . getOpenFileName ( self , tr ( 'Input file' ) , input_path , tr ( 'Raw grid file (*.xml)' ) ) if filename : self . input_path . setText ( filen... | Autoconnect slot activated when open input tool button is clicked . |
27,025 | def on_open_output_tool_clicked ( self ) : output_path = self . output_path . text ( ) if not output_path : output_path = os . path . expanduser ( '~' ) filename , __ = QFileDialog . getSaveFileName ( self , tr ( 'Output file' ) , output_path , tr ( 'Raster file (*.tif)' ) ) if filename : self . output_path . setText (... | Autoconnect slot activated when open output tool button is clicked . |
27,026 | def launch_keyword_wizard ( self ) : if self . iface . activeLayer ( ) != self . output_layer : return 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 . |
27,027 | 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 = keywo... | Union of two vector layers . |
27,028 | 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 ( expressi... | We need to fill hazard class when it s empty . |
27,029 | def function ( receiver ) : if hasattr ( receiver , '__call__' ) : if hasattr ( receiver . __call__ , im_func ) or hasattr ( receiver . __call__ , im_code ) : receiver = receiver . __call__ if hasattr ( receiver , im_func ) : return receiver , getattr ( getattr ( receiver , im_func ) , func_code ) , 1 elif not hasattr ... | Get function - like callable object for given receiver |
27,030 | 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 . en... | Helper method for populating template combobox . |
27,031 | 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 ) : fo... | Helper method to retrieve path from particular report metadata . |
27,032 | def open_as_pdf ( self ) : report_urls_dict = report_urls ( self . impact_function ) for key , value in list ( report_urls_dict . items ( ) ) : report_urls_dict [ key ] = list ( value . values ( ) ) if self . dock : status = m . Message ( m . Heading ( self . dock . tr ( 'Map Creator' ) , ** INFO_STYLE ) , m . Paragrap... | Print the selected report as a PDF product . |
27,033 | 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_... | Open in layout designer a given MapReport instance . |
27,034 | def prepare_components ( self ) : generated_components = deepcopy ( all_default_report_components ) 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... | Prepare components that are going to be generated based on user options . |
27,035 | def template_chooser_clicked ( self ) : path = self . template_path . text ( ) if not path : path = setting ( 'lastCustomTemplate' , '' , str ) if path : directory = dirname ( path ) else : directory = '' file_name = QFileDialog . getOpenFileName ( self , tr ( 'Select report' ) , directory , tr ( 'QGIS composer templat... | Slot activated when report file tool button is clicked . |
27,036 | 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 ( Tr... | Slot for template selector elements behaviour . |
27,037 | def show_help ( self ) : 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 . |
27,038 | 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) mo... | Get InaSAFE limitations . |
27,039 | 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 ( curren... | To update the helper about the country and the admin_level . |
27,040 | def populate_countries ( self ) : for i in range ( 1 , 12 ) : self . admin_level_comboBox . addItem ( self . tr ( 'Level %s' ) % i , i ) self . admin_level_comboBox . setCurrentIndex ( 7 ) list_countries = sorted ( [ self . tr ( country ) for country in list ( self . countries . keys ( ) ) ] ) for country in list_count... | Populate the combobox about countries and levels . |
27,041 | 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 ] ) rectangle = QgsRectangle ( extent [ 0 ] , extent [ 1 ] , extent [ 2 ] , extent [ 3 ] ) center = rectan... | Update extent value in GUI based from an extent . |
27,042 | def update_extent_from_map_canvas ( self ) : self . bounding_box_group . setTitle ( self . tr ( 'Bounding box from the map canvas' ) ) extent = viewport_geo_array ( self . iface . mapCanvas ( ) ) self . update_extent ( extent ) | Update extent value in GUI based from value in map . |
27,043 | 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' ) ) ... | Update extent value in GUI based from the QgsMapTool rectangle . |
27,044 | 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 . |
27,045 | 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 . floo... | Create a tab with all checked features . |
27,046 | def accept ( self ) : error_dialog_title = self . tr ( 'InaSAFE OpenStreetMap Downloader Error' ) self . bounding_box_group . setDisabled ( True ) 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 = ... | Do osm download and display it in QGIS . |
27,047 | 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 : shp = '%s.shp' % path if os . path . isfile ( shp ) : os . remove ( shp ) else : separator = '-' suffix = self . get_u... | Get a full base name path to save the shapefile . |
27,048 | def require_directory ( self ) : path = self . output_directory . text ( ) if path == '' : 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 answer = QMessageBox . question ( self , tit... | Ensure directory path entered in dialog exist . |
27,049 | 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 . |
27,050 | def add_exposure ( self , layer ) : self . _exposures . append ( layer ) self . _is_ready = False | Add an exposure layer in the analysis . |
27,051 | def get_parameter ( self ) : self . _parameter . value = self . _input . value ( ) return self . _parameter | Obtain the parameter object from the current widget state . |
27,052 | def set_widgets ( self ) : 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 woul... | Set widgets on the Hazard Layer Origin Type tab . |
27,053 | 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 |
27,054 | 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 |
27,055 | 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 try : coordinates = [ float ( i ) for i in coordinates ]... | Convert an extent string to an array . |
27,056 | 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 ( ) ) transformed_extent = transform . transformB... | Convert the supplied extent to geographic and return as an array . |
27,057 | def validate_geo_array ( extent ) : min_longitude = extent [ 0 ] min_latitude = extent [ 1 ] max_longitude = extent [ 2 ] max_latitude = extent [ 3 ] if min_latitude >= max_latitude : return False if min_longitude >= max_longitude : return False if min_latitude < - 90 or min_latitude > 90 : return False if max_latitude... | Validate a geographic extent . |
27,058 | 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 . selectedFeatur... | Duplicate the layer by taking the same source and copying keywords . |
27,059 | 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 . |
27,060 | 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 . |
27,061 | 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 . |
27,062 | 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 . |
27,063 | 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 QgsLa... | Helper to get the layer icon . |
27,064 | 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 ( ) , pol... | Compute the rectangle from a WKT string . |
27,065 | 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 . |
27,066 | 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 : self . _populate_reporting_tab ( ) self . reporting_options_la... | Triggered when the current tab is changed . |
27,067 | 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 . ... | Get an ordered list of layers according to users input . |
27,068 | 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' % ( l... | Add layer clicked . |
27,069 | 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 . ... | Remove layer clicked . |
27,070 | 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_layer... | Move the layer down . |
27,071 | 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... | Selection has changed in the list . |
27,072 | 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 . setH... | Populate trees about layers . |
27,073 | def _create_exposure_combos ( self ) : project = QgsProject . instance ( ) canvas_layers = self . iface . mapCanvas ( ) . layers ( ) layers = list ( project . mapLayers ( ) . values ( ) ) layers . sort ( key = lambda x : x . name ( ) ) show_only_visible_layers = setting ( 'visibleLayersOnlyFlag' , expected_type = bool ... | Create one combobox for each exposure and insert them in the UI . |
27,074 | def validate_impact_function ( self ) : 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 = [ ] fo... | Check validity of the current impact function . |
27,075 | 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_field... | Create demographic section context . |
27,076 | 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 . key... | Create demographic section context without aggregation . |
27,077 | def check_inputs ( compulsory_fields , fields ) : for field in compulsory_fields : if not fields . get ( field [ 'key' ] ) : msg = '%s not found in %s' % ( field [ 'key' ] , fields ) raise InvalidKeywordsForProcessingAlgorithm ( msg ) | Helper function to check if the layer has every compulsory fields . |
27,078 | def create_absolute_values_structure ( layer , fields ) : 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 ( ) . loo... | Helper function to create the structure for absolute values . |
27,079 | 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 ( ) ) ) ... | Function to add fields needed in the output layer . |
27,080 | 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 . |
27,081 | 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 . |
27,082 | def canvasReleaseEvent ( self , e ) : _ = e self . is_emitting_point = False self . rectangle_created . emit ( ) | Handle canvas release events has finished capturing e . |
27,083 | 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_poin... | Show the rectangle on the canvas . |
27,084 | 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 . |
27,085 | def deactivate ( self ) : self . rubber_band . reset ( QgsWkbTypes . PolygonGeometry ) QgsMapTool . deactivate ( self ) self . deactivated . emit ( ) | Disable the tool . |
27,086 | def clean_layer ( layer ) : output_layer_name = clean_geometry_steps [ 'output_layer_name' ] output_layer_name = output_layer_name % layer . keywords [ 'layer_purpose' ] layer . startEditing ( ) count = 0 request = QgsFeatureRequest ( ) . setSubsetOfAttributes ( [ ] ) for feature in layer . getFeatures ( request ) : ge... | Clean a vector layer . |
27,087 | def geometry_checker ( geometry ) : if geometry is None : return False , None if geometry . isGeosValid ( ) : return True , geometry else : new_geom = geometry . makeValid ( ) if new_geom . isGeosValid ( ) : return False , new_geom else : return False , None | Perform a cleaning if the geometry is not valid . |
27,088 | def remove_provenance_project_variables ( ) : project_context_scope = QgsExpressionContextUtils . projectScope ( QgsProject . instance ( ) ) existing_variable_names = project_context_scope . variableNames ( ) existing_variables = { } for existing_variable_name in existing_variable_names : existing_variables [ existing_... | Removing variables from provenance data . |
27,089 | def aggregation ( self , layer ) : 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 .... | Setter for the current aggregation layer . |
27,090 | def _show_organisation_logo ( self ) : dock_width = float ( self . width ( ) ) maximum_height = 100.0 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_rat... | Show the organisation logo in the dock if possible . |
27,091 | 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 ... | Save auxiliary files when using the save as function . |
27,092 | def index_changed_aggregation_layer_combo ( self , index ) : if index == 0 : 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 = Qgs... | Automatic slot executed when the Aggregation combo is changed . |
27,093 | 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 ) if ( ( self . aggregation_layer_combo . count ( ) > 1 ) and ( selected_hazard_layer is not None ) and ( selected_exposure_layer ... | Toggle the aggregation combo enabled status . |
27,094 | 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 . |
27,095 | 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 . |
27,096 | 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 . s... | Helper to set a color on the debug button to know if it s debugging . |
27,097 | def get_layers ( self , * args ) : _ = args if self . get_layers_lock : return project = QgsProject . instance ( ) canvas_layers = self . iface . mapCanvas ( ) . layers ( ) layers = list ( project . mapLayers ( ) . values ( ) ) if len ( layers ) == 0 : if self . conflicting_plugin_detected : send_static_message ( self ... | Obtain a list of layers currently loaded in QGIS . |
27,098 | def show_print_dialog ( self ) : if not self . impact_function : 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 = ( ext... | Open the print dialog |
27,099 | 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 . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.