Beispiel #1
0
 def dissolve(self, field_name, output):
     """Dissolve shp by field name and store it in output"""
     try:
         params = {
             'INPUT': self.shp_path,
             'FIELD': [field_name],
             'OUTPUT': output
         }
         # return processing.run('native:dissolve', params, feedback=self.feedback)
         processing.run('native:dissolve', params, feedback=self.feedback)
         print(" dissolve works")
     except:
         print(" NO dissolve ")
     return False
 def reproject(self, layers_to_project_path):
     """Reproject all input layers to 3857 CRS"""
     try:
         for layer in layers_to_project_path:
             # the name for the new reproject file
             my_array = layer.split('/')
             name = my_array[len(my_array) - 1].split('.')[0]
             output = os.path.dirname(__file__) + r'/processing/' + name + '_re.shp'
             params = {'INPUT': layer, 'TARGET_CRS': 'EPSG:3857', 'OUTPUT': output}
             processing.run("native:reprojectlayer", params, feedback=self.feedback)
         print("reproject is success")
         return 0
     except:
         print("reproject is failed")
         return 1
 def find_sight_line(self):
     """Run native algorithm ( in C++) to find sight line)"""
     try:
         intersect = os.path.dirname(__file__) + r'/processing/buildings_0_re.shp'
         line_path = os.path.dirname(__file__) + r'/new_lines5.shp'
         params = {'INPUT': line_path, 'PREDICATE': [2], 'INTERSECT': intersect,
                   'OUTPUT': self.res_folder + '/sight_line.shp'}
         self.res = processing.run('native:extractbylocation', params, feedback=self.feedback)
         self.layers.append(self.upload_new_layer(self.res['OUTPUT'], "_sight_line"))
         return True
     except:
         return False
    def intersections_points(self):
        """Upload input data"""
        try:
            junc_loc_0 = os.path.dirname(__file__) + r'/processing/intersections_0.shp'

            # Find intersections points
            params = {'INPUT': self.network, 'INTERSECT': self.network, 'INPUT_FIELDS': [], 'INTERSECT_FIELDS': [],
                      'OUTPUT': junc_loc_0}

            self.res = processing.run('native:lineintersections', params, feedback=self.feedback)
            print("intersections_points is success")
        except:
            print("intersections_points is failed")
Beispiel #5
0
    provider_name = "ogr"
    layer = QgsVectorLayer(path, layer_name, provider_name)
    return layer


if __name__ == "__main__":
    app = QGuiApplication([])
    QgsApplication.setPrefixPath(r'C:\Program Files\QGIS 3.0\apps\qgis', True)
    QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
    QgsApplication.initQgis()
    feedback = QgsProcessingFeedback()
    # processing.run("native:dissolve",
    #                {'INPUT':'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax/'
    #                         'processing/highways_1.shp','FIELD':['group'],'OUTPUT':'memory:'},feedback )
    """Upload input data"""

    junc_loc_0 = os.path.dirname(__file__) + r'/processing/dissolve_0.shp'
    network = os.path.dirname(__file__) + r'/processing/highways_1.shp'
    # network = QgsVectorLayer(
    #     network,
    #     "test",
    #     "ogr")
    # Find intersections points
    params = {'INPUT': network, 'FIELD': 'group', 'OUTPUT': junc_loc_0}

    processing.run('native:dissolve', params, feedback=feedback)
    """For standalone application"""
    # Exit applications
    QgsApplication.exitQgis()
    app.exit()
Beispiel #6
0
sys.path.append(r'C:\Program Files\QGIS 3.0\apps\qgis\python\plugins')
# Reference the algorithm you want to run
from plugins import processing


def upload_new_layer(path, name):
    """Upload shp layers"""
    layer_name = "layer" + name
    provider_name = "ogr"
    layer = QgsVectorLayer(path, layer_name, provider_name)
    return layer


if __name__ == "__main__":
    app = QGuiApplication([])
    QgsApplication.setPrefixPath(r'C:\Program Files\QGIS 3.0\apps\qgis', True)
    QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
    QgsApplication.initQgis()
    feedback = QgsProcessingFeedback()
    """Upload input data"""

    input = os.path.dirname(os.path.dirname(__file__)) + r'/dissolve_0.shp'
    OUTPUT = os.path.dirname(__file__) + r'/single_part.shp'
    params = {'INPUT': input, 'OUTPUT': OUTPUT}

    processing.run('native:multiparttosingleparts', params, feedback=feedback)
    """For standalone application"""
    # Exit applications
    QgsApplication.exitQgis()
    app.exit()
Beispiel #7
0
if __name__ == "__main__":
    app = QGuiApplication([])
    QgsApplication.setPrefixPath(r'C:\Program Files\QGIS 3.0\apps\qgis', True)
    QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
    QgsApplication.initQgis()
    feedback = QgsProcessingFeedback()

    """Upload input data"""
    layer_2 = upload_new_layer(
        r'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax'
        r'/test\mean_close_point\mean_close_coor.shp','test1')
    layer_1 = upload_new_layer(
        r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
             r'\test\POI\results_file/extracted.shp','test2')
    layer_3 = upload_new_layer(
        r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
             r'\test\POI\results_file\off_pnts.shp','test3')
    layers = [layer_1, layer_2,layer_3]

    OUTPUT = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
             r'\test\POI\results_file\merge.shp'
    params = {'LAYERS': layers,'CRS': 'EPSG:3857', 'OUTPUT': OUTPUT}

    processing.run('native:mergevectorlayers', params, feedback=feedback)

    """For standalone application"""
    # Exit applications
    QgsApplication.exitQgis()
    app.exit()
Beispiel #8
0
def add_poi_to_intersections(use='plugin'):
    if use == "standalone":
        app = QGuiApplication([])
        QgsApplication.setPrefixPath(r'C:\Program Files\QGIS 3.0\apps\qgis',
                                     True)
        QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
        QgsApplication.initQgis()
    feedback = QgsProcessingFeedback()
    """ implement Clip """
    try:
        """Upload input data"""

        input = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                r'/processing/poi_re.shp'
        overlay = 'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax' \
                  '/processing/buildings_0_re.shp'
        output = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                 r'\test\POI\results_file/cliped.shp'
        params = {'INPUT': input, 'OVERLAY': overlay, 'OUTPUT': output}

        processing.run('native:clip', params, feedback=feedback)
        print("Clip success")

    except:
        print("Clip failed")
    """ implement Extract """
    try:
        """Upload input data"""

        input = 'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax/' \
                'processing/poi_re.shp'
        intersect = 'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax/' \
                    'processing/buildings_0_re.shp'
        output = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                 r'\test\POI\results_file/extracted.shp'
        params = {
            'INPUT': input,
            'PREDICATE': [2],
            'INTERSECT': intersect,
            'OUTPUT': output
        }

        processing.run('native:extractbylocation', params, feedback=feedback)
        print("Extract success")
    except:
        print("Extract failed")
    """ implement Point along geometry """
    try:
        input = 'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax' \
                '/processing/highways_0_re.shp'
        output = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                 r'\test\POI\results_file/points_along.shp'

        alg = PointsAlongGeometry()
        alg.initAlgorithm()
        context = QgsProcessingContext()
        params = {
            'INPUT': input,
            'DISTANCE': 10,
            'START_OFFSET': 0,
            'END_OFFSET': 0,
            'OUTPUT': output
        }
        res = alg.processAlgorithm(params, context, feedback=feedback)
        print("Point along geometry success")
    except:
        print("Point along geometry failed")
    """implement add ID"""
    try:
        hub_path = os.path.dirname(
            __file__) + r'/results_file/points_along.shp'
        junc = upload_new_layer(hub_path, "hub")
        if junc.fields()[len(junc.fields()) - 1].name() != "vis_id":
            junc.dataProvider().addAttributes(
                [QgsField("vis_id", QVariant.Int)])
            junc.updateFields()
        n = len(junc.fields())
        for i, feature in enumerate(junc.getFeatures()):
            junc.dataProvider().changeAttributeValues({i: {n - 1: i}})
        print("add ID success")

    except:
        print("add ID failed")
    """ implement Distance to nearest hub   """
    try:
        """Upload input data"""

        input_path = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                     r'\test\POI\results_file/cliped.shp'
        input = upload_new_layer(input_path, "test_input")
        hubs_path = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                    r'\test\POI\results_file/points_along.shp'
        hubs = upload_new_layer(hubs_path, "test_hubs_")
        output = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                 r'\test\POI\results_file/line_to_points.shp'

        alg = HubDistanceLines()
        alg.initAlgorithm()
        # Some preprocessing for context
        project = QgsProject.instance()

        target_crs = QgsCoordinateReferenceSystem()
        target_crs.createFromOgcWmsCrs(input.crs().authid())
        project.setCrs(target_crs)
        context = QgsProcessingContext()
        context.setProject(project)
        params = {
            'INPUT': input,
            'HUBS': hubs,
            'FIELD': 'vis_id',
            'UNIT': 4,
            'OUTPUT': output
        }
        alg.processAlgorithm(params, context, feedback=feedback)
        print("Distance to nearest hub success")
    except:
        print("Distance to nearest hub  failed")
    """ implement  Polygon to lines  """
    try:
        input = 'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax/' \
                'processing/buildings_0_re.shp'
        output = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                 r'\test\POI\results_file\poly_as_lines.shp'

        alg = PolygonsToLines()
        alg.initAlgorithm()
        context = QgsProcessingContext()
        params = {'INPUT': input, 'OUTPUT': output}
        res = alg.processAlgorithm(params, context, feedback=feedback)
        print(" Polygon to lines success")
    except:
        print(" Polygon to lines failed")
    """ implement Line intersections  """
    try:
        """Upload input data"""

        input_path = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                     r'\test\POI\results_file\line_to_points.shp'
        input = upload_new_layer(input_path, "test_input")
        intersect_path = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                         r'\test\POI\results_file\poly_as_lines.shp'
        intersect = upload_new_layer(intersect_path, "test_intersect")
        output = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                 r'\test\POI\results_file\off_pnts.shp'
        params = {
            'INPUT': input,
            'INTERSECT': intersect,
            'INPUT_FIELDS': [],
            'INTERSECT_FIELDS': [],
            'OUTPUT': output
        }

        processing.run('native:lineintersections', params, feedback=feedback)
        print("Line intersections success")
    except:
        print("Line intersections failed")
    """ implement Merge  """
    try:
        layer_2 = upload_new_layer(
            r'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax'
            r'/test\mean_close_point\mean_close_coor.shp', 'test1')
        layer_1 = upload_new_layer(
            r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
            r'\test\POI\results_file/extracted.shp', 'test2')
        layer_3 = upload_new_layer(
            r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
            r'\test\POI\results_file\off_pnts.shp', 'test3')
        layers = [layer_1, layer_2, layer_3]

        OUTPUT = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                 r'\test\POI\results_file\merge.shp'
        params = {'LAYERS': layers, 'CRS': 'EPSG:3857', 'OUTPUT': OUTPUT}

        processing.run('native:mergevectorlayers', params, feedback=feedback)
        print("Merge success")
    except:
        print("Merge failed")
    """ implement Delete Duplicate geometry """
    try:
        """Upload input data"""

        feedback = QgsProcessingFeedback()
        """Upload input data"""

        input = 'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax/test/POI' \
                '/results_file/merge.shp'

        OUTPUT = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\POI' \
                 r'\results_file\final.shp'

        alg = DeleteDuplicateGeometries()
        alg.initAlgorithm()
        context = QgsProcessingContext()
        params = {'INPUT': input, 'OUTPUT': OUTPUT}
        res = alg.processAlgorithm(params, context, feedback=feedback)

        print("Delete Duplicate geometry  success")
    except:
        print("Delete Duplicate geometry  failed")
    """For standalone application"""
    if use == 'standalone':
        QgsApplication.exitQgis()
        app.exit()
Beispiel #9
0
from plugins import processing


def upload_new_layer(path, name):
    """Upload shp layers"""
    layer_name = "layer" + name
    provider_name = "ogr"
    layer = QgsVectorLayer(path, layer_name, provider_name)
    return layer


if __name__ == "__main__":
    app = QGuiApplication([])
    QgsApplication.setPrefixPath(r'C:\Program Files\QGIS 3.0\apps\qgis', True)
    QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
    QgsApplication.initQgis()
    feedback = QgsProcessingFeedback()
    """Upload input data"""

    input = upload_new_layer(
        r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/cleaned.shp',
        'test')
    OUTPUT = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/mean_close_coor.shp'
    params = {'INPUT': input, 'UID': 'InputID', 'OUTPUT': OUTPUT}

    processing.run('native:meancoordinates', params, feedback=feedback)
    """For standalone application"""
    # Exit applications
    QgsApplication.exitQgis()
    app.exit()
Beispiel #10
0
    """Upload shp layers"""
    layer_name = "layer" + name
    provider_name = "ogr"
    layer = QgsVectorLayer(path, layer_name, provider_name)
    return layer


if __name__ == "__main__":
    app = QGuiApplication([])
    QgsApplication.setPrefixPath(r'C:\Program Files\QGIS 3.0\apps\qgis', True)
    QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
    QgsApplication.initQgis()
    feedback = QgsProcessingFeedback()
    """Upload input data"""

    input = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/distance_matrix.shp'
    OUTPUT = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/extracted.shp'
    params = {
        'INPUT': input,
        'FIELD': 'Distance',
        'OPERATOR': 4,
        'VALUE': '10',
        'OUTPUT': OUTPUT
    }

    processing.run('native:extractbyattribute', params, feedback=feedback)
    """For standalone application"""
    # Exit applications
    QgsApplication.exitQgis()
    app.exit()
    def __init__(self, use='plugin'):
        if use == "standalone":
            app = QGuiApplication([])
            QgsApplication.setPrefixPath(
                r'C:\Program Files\QGIS 3.0\apps\qgis', True)
            QgsApplication.processingRegistry().addProvider(
                QgsNativeAlgorithms())
            QgsApplication.initQgis()
        feedback = QgsProcessingFeedback()
        """implement add ID"""
        try:
            junc_path = os.path.dirname(
                os.path.dirname(os.path.dirname(
                    __file__))) + r'/processing/intersections.shp'
            junc = self.upload_new_layer(junc_path, "junc")
            if junc.fields()[len(junc.fields()) - 1].name() != "vis_id":
                junc.dataProvider().addAttributes(
                    [QgsField("vis_id", QVariant.Int)])
                junc.updateFields()
            n = len(junc.fields())
            for i, feature in enumerate(junc.getFeatures()):
                junc.dataProvider().changeAttributeValues({i: {n - 1: i}})
            print("add ID success")

        except:
            print("add ID failed")
        """ implement distance matrix"""
        try:
            input = os.path.dirname(os.path.dirname(
                os.path.dirname(__file__))) + r'/processing/intersections.shp'

            INPUT_FIELD = 'vis_id'
            TARGET = os.path.dirname(os.path.dirname(
                os.path.dirname(__file__))) + r'/processing/intersections.shp'
            TARGET_FIELD = 'vis_id'
            OUTPUT = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/distance_matrix.shp'
            params = {
                'INPUT': input,
                'INPUT_FIELD': INPUT_FIELD,
                'TARGET': TARGET,
                'TARGET_FIELD': TARGET_FIELD,
                'OUTPUT': OUTPUT,
                'MATRIX_TYPE': 0,
                'NEAREST_POINTS': 10,
                'OUTPUT': OUTPUT
            }

            alg = PointDistance()
            alg.initAlgorithm()

            # Some preprocessing for context
            project = QgsProject.instance()

            target_crs = QgsCoordinateReferenceSystem()
            layer_1 = self.upload_new_layer(input, "test")
            target_crs.createFromOgcWmsCrs(layer_1.crs().authid())
            project.setCrs(target_crs)
            context = QgsProcessingContext()
            context.setProject(project)
            alg.processAlgorithm(params, context, feedback=feedback)
            print("distance matrix success")

        except:
            print("distance matrix failed")
        """ implement extract"""
        try:
            input = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/distance_matrix.shp'
            OUTPUT = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/extracted.shp'
            params = {
                'INPUT': input,
                'FIELD': 'Distance',
                'OPERATOR': 4,
                'VALUE': '20',
                'OUTPUT': OUTPUT
            }

            processing.run('native:extractbyattribute',
                           params,
                           feedback=feedback)

            print("extract success")
        except:
            print("extract failed")
        """ implement Multipart to singleparts"""
        try:
            input = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/extracted.shp'
            OUTPUT = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/single_part.shp'
            params = {'INPUT': input, 'OUTPUT': OUTPUT}

            processing.run('native:multiparttosingleparts',
                           params,
                           feedback=feedback)

            print("Multipart to singleparts success")
        except:
            print("Multipart to singleparts failed")
        """ implement Delete duplicate geometries"""
        try:
            input = r'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax\test\mean_close_point/single_part.shp'

            OUTPUT = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/cleaned.shp'

            alg = DeleteDuplicateGeometries()
            alg.initAlgorithm()
            context = QgsProcessingContext()
            params = {'INPUT': input, 'OUTPUT': OUTPUT}
            res = alg.processAlgorithm(params, context, feedback=feedback)
            print("Delete duplicate geometries success")
        except:
            print("Delete duplicate geometries failed")
            """ implement Mean coordinates"""
        try:
            input = self.upload_new_layer(
                r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/cleaned.shp',
                'test')
            OUTPUT = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax\test\mean_close_point/mean_close_coor.shp'
            params = {'INPUT': input, 'UID': 'InputID', 'OUTPUT': OUTPUT}

            processing.run('native:meancoordinates', params, feedback=feedback)
            print("Mean coordinates success")
        except:
            print("Mean coordinates failed")
        """For standalone application"""
        # Exit applications
        if use == 'standalone':
            QgsApplication.exitQgis()
            app.exit()
Beispiel #12
0

def upload_new_layer(path, name):
    """Upload shp layers"""
    layer_name = "layer" + name
    provider_name = "ogr"
    layer = QgsVectorLayer(path, layer_name, provider_name)
    return layer


if __name__ == "__main__":
    app = QGuiApplication([])
    QgsApplication.setPrefixPath(r'C:\Program Files\QGIS 3.0\apps\qgis', True)
    QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
    QgsApplication.initQgis()
    feedback = QgsProcessingFeedback()
    """Upload input data"""

    input = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
            r'\test\POI\poi_osm_r.shp'
    overlay = 'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax' \
              '/processing/buildings_1.shp'
    output = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
             r'\test\POI\results_file/cliped.shp'
    params = {'INPUT': input, 'OVERLAY': overlay, 'OUTPUT': output}

    processing.run('native:clip', params, feedback=feedback)
    """For standalone application"""
    # Exit applications
    QgsApplication.exitQgis()
    app.exit()
    layer = QgsVectorLayer(path, layer_name, provider_name)
    return layer


if __name__ == "__main__":
    app = QGuiApplication([])
    QgsApplication.setPrefixPath(r'C:\Program Files\QGIS 3.0\apps\qgis', True)
    QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
    QgsApplication.initQgis()
    feedback = QgsProcessingFeedback()
    """Upload input data"""

    input = 'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax/' \
            'test/POI/poi_osm_r.shp'
    intersect = 'C:/Users/achituv/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/visibilitysyntax/' \
                'processing/buildings_1.shp'
    output = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
             r'\test\POI\results_file/extracted.shp'
    params = {
        'INPUT': input,
        'PREDICATE': [2],
        'INTERSECT': intersect,
        'OUTPUT': output
    }

    processing.run('native:extractbylocation', params, feedback=feedback)
    """For standalone application"""
    # Exit applications
    QgsApplication.exitQgis()
    app.exit()
Beispiel #14
0
qgs.initQgis()
prefix = QgsApplication.prefixPath()
print(prefix)

# 在这里编写代码,加载一些图层,使用处理算法等
sys.path.append(os.path.join(prefix, "python", "plugins"))
from plugins.processing.core.Processing import Processing
from plugins import processing

Processing.initialize()

for alg in QgsApplication.processingRegistry().algorithms():
    alg: QgsProcessingAlgorithm
    print(alg.group(), alg.provider().name(), alg.name())

result = processing.run('gdal:gdalinfo',
                        {
                            'EXTRA': '',
                            'INPUT': '../data/test.tif',
                            'MIN_MAX': False,
                            'NOGCP': False,
                            'NO_METADATA': False,
                            # 'OUTPUT': 'TEMPORARY_OUTPUT',
                            'OUTPUT': '../data/test.html',
                            'STATS': False
                        }
                        )
print(result)
# 脚本完成后,调用exitQgis()从内存中删除提供者和图层注册
qgs.exitQgis()
Beispiel #15
0
if __name__ == "__main__":
    app = QGuiApplication([])
    QgsApplication.setPrefixPath(r'C:\Program Files\QGIS 3.0\apps\qgis', True)
    QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
    QgsApplication.initQgis()
    feedback = QgsProcessingFeedback()
    """Upload input data"""

    input_path = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                 r'\test\POI\results_file\line_to_points.shp'
    input = upload_new_layer(input_path, "test_input")
    intersect_path = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
                     r'\test\POI\results_file\poly_as_lines.shp'
    intersect = upload_new_layer(intersect_path, "test_intersect")
    output = r'C:\Users\achituv\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\visibilitysyntax' \
             r'\test\POI\results_file\off_pnts.shp'
    params = {
        'INPUT': input,
        'INTERSECT': intersect,
        'INPUT_FIELDS': [],
        'INTERSECT_FIELDS': [],
        'OUTPUT': output
    }

    processing.run('native:lineintersections', params, feedback=feedback)
    """For standalone application"""
    # Exit applications
    QgsApplication.exitQgis()
    app.exit()