def join(self, processing, output_file_name, input_layer, join_layer): """Join attributes by location creating output file(s) discarting non-matching from the match results and return a join count""" output_match_type, output_file_path = self._get_output_file_details( output_file_name) try: r = processing.run( "native:joinattributesbylocation", { 'INPUT': input_layer, 'JOIN': join_layer, 'PREDICATE': self._geopredicate_criteria, 'JOIN_FIELDS': self._join_layer_fields, 'METHOD': self._join_type, 'DISCARD_NONMATCHING': self._DEFAULT_DISCARD_NONMATCHING_FROM_MATCH_RESULTS, 'PREFIX': f"{self._join_layer_name}_", output_match_type: output_file_path }) except: raise C_Exceptions.UnexpectedError(sys.exc_info()[0]) if 'JOINED_COUNT' in r: return r['JOINED_COUNT'] else: return None
def main(argv): script_name = os.path.basename(__file__) try: # options/arguments + initialization print("Initialization...") aaif = Add(argv) # load input layer print("Loading input layer...") input_layer = aaif.create_vector_layer(aaif.get_input_layer_path(), script_name) # split input layer print("Adding autoincremental field...") aaif.add_autoincremental_field(processing, input_layer, aaif.get_field_name(), aaif.get_start(), aaif.get_output_file_path()) except ( \ C_Exceptions.DisplayHelpError, \ C_Exceptions.MissingArgumentsError, \ C_Exceptions.OptionsError): C_Help.display(script_name) except ( \ C_Exceptions.LoadVectorLayerError, \ C_Exceptions.LoadVectorLayerNotValidError, \ C_Exceptions.ProcessingError, \ C_Exceptions.UnexpectedError): pass except Exception as ex: C_Exceptions.UnexpectedError(ex)
def main(argv): script_name = os.path.basename(__file__) try: # options/arguments + initialization print("Initialization...") simplify = Simplify(argv) # load input layer print("Loading input layer...") input_layer = simplify.create_vector_layer(simplify.get_input_layer_path(), script_name) # simplify polygon print("Simplifying geometries...") simplify.simplify_geometries(processing, input_layer, simplify.get_method(), simplify.get_tolerance(), simplify.get_output_file_path()) except ( \ C_Exceptions.DisplayHelpError, \ C_Exceptions.MissingArgumentsError, \ C_Exceptions.OptionsError): C_Help.display(script_name) except ( \ C_Exceptions.LoadVectorLayerError, \ C_Exceptions.LoadVectorLayerNotValidError, \ C_Exceptions.ProcessingError, \ C_Exceptions.UnexpectedError): pass except Exception as ex: C_Exceptions.UnexpectedError(ex)
def main(argv): script_name = os.path.basename(__file__) try: # options/arguments + initialization print("Initialization...") cgrid = Create(argv) # load grid extent layer print("Loading grid extent layer...") grid_extent = cgrid.create_vector_layer(cgrid.get_grid_extent_path(), script_name) # create grid from extent layer print("Creating grid from extent layer...") cgrid.create_grid(processing, grid_extent) except ( \ C_Exceptions.DisplayHelpError, \ C_Exceptions.MissingArgumentsError, \ C_Exceptions.OptionsError): C_Help.display(script_name) except ( \ C_Exceptions.LoadVectorLayerError, \ C_Exceptions.LoadVectorLayerNotValidError, \ C_Exceptions.ProcessingError, \ C_Exceptions.UnexpectedError): pass except Exception as ex: C_Exceptions.UnexpectedError(ex)
def _load_options(argv, short_options, long_options): """Load options from arguments""" try: opts, args = getopt.getopt(argv, short_options, long_options) except (getopt.GetoptError, C_Exceptions.MissingArgumentsError, C_Exceptions.DisplayHelpError) as ex: raise C_Exceptions.OptionsError(ex) except Exception as ex: raise C_Exceptions.UnexpectedError(ex) return opts
def add_autoincremental_field(self, processing, input_layer, field_name, start, output_file): """Add autoincremenetal field to vector layer features""" try: processing.run("native:addautoincrementalfield", { 'INPUT': self._input_layer_path, 'FIELD_NAME': self._field_name, 'START': self._start, 'OUTPUT': self._output_file }) except QgsProcessingException as ex: raise C_Exceptions.ProcessingError(ex) except Exception as ex: raise C_Exceptions.UnexpectedError(ex)
def split_with_lines(self, processing, input_layer, split_layer, output_file): """Split the input layer along the lines of the split layer""" try: processing.run( "native:splitwithlines", { 'INPUT': self._input_layer_path, 'LINES': self._split_layer_path, 'OUTPUT': self._output_file }) except QgsProcessingException as ex: raise C_Exceptions.ProcessingError(ex) except Exception as ex: raise C_Exceptions.UnexpectedError(ex)
def extract_polygon_from_layer_extent(self, processing, input_layer, output_file): """Create a polygon from the input layer extent""" try: processing.run( "native:polygonfromlayerextent", { 'INPUT': self._input_layer_path, 'ROUND_TO': 0, 'OUTPUT': self._output_file }) except QgsProcessingException as ex: raise C_Exceptions.ProcessingError(ex) except Exception as ex: raise C_Exceptions.UnexpectedError(ex)
def simplify_geometries(self, processing, input_layer, method, tolerance, output_file): """Simplify geometries of a polygon using a given method and a tolerance""" try: processing.run( "native:simplifygeometries", { 'INPUT': self._input_layer_path, 'METHOD': self._method, 'TOLERANCE': self._tolerance, 'OUTPUT': self._output_file }) except QgsProcessingException as ex: raise C_Exceptions.ProcessingError(ex) except Exception as ex: raise C_Exceptions.UnexpectedError(ex)
def create_grid(self, processing, grid_extent): """Create a grid and save it to an output file""" try: processing.run( "native:creategrid", { 'TYPE': self._grid_type, 'EXTENT': grid_extent, 'HSPACING': self._horizontal_spacing, 'VSPACING': self._vertical_spacing, 'HOVERLAY': 0, 'VOVERLAY': 0, 'CRS': self._grid_crs, 'OUTPUT': self._output_file }) except QgsProcessingException as ex: raise C_Exceptions.ProcessingError(ex) except Exception as ex: raise C_Exceptions.UnexpectedError(ex)
def main(argv): script_name = os.path.basename(__file__) try: # options/arguments + initialization print("Initialization...") split = Split(argv) # load input layer print("Loading input layer...") input_layer = split.create_vector_layer(split.get_input_layer_path(), script_name) # load split layer print("Loading split layer...") split_layer = split.create_vector_layer(split.get_split_layer_path(), script_name) # split input layer print("Splitting input layer...") split.split_with_lines(processing, input_layer, split_layer, split.get_output_file_path()) except ( \ C_Exceptions.DisplayHelpError, \ C_Exceptions.MissingArgumentsError, \ C_Exceptions.OptionsError): C_Help.display(script_name) except ( \ C_Exceptions.LoadVectorLayerError, \ C_Exceptions.LoadVectorLayerNotValidError, \ C_Exceptions.ProcessingError, \ C_Exceptions.UnexpectedError): pass except Exception as ex: C_Exceptions.UnexpectedError(ex)