0

I am using Python for my postgraduate studies and I am having trouble running my code when I try to use processing in Qgis using the command-line interface.

I think the error is really easy to fix it but right now I do not know how to fix it. When I run my code I have this

Traceback (most recent call last):
  File "urban_canopy_element.py", line 100, in <module>
    output=general.run('qgis:clip',{'INPUT': input_layer, \
NameError: name 'run' is not defined

I do not know where the error is. Attach the source code

import os
import sys
#from os import path
from qgis.core import *
from qgis.core import (QgsApplication,
QgsDataSourceUri,QgsCategorizedSymbolRenderer, 
QgsClassificationRange, QgsPointXY,
QgsProject,QgsExpression,QgsField,QgsFields,QgsFeature,
QgsFeatureRequest,QgsFeatureRenderer,QgsGeometry,QgsGraduatedSymbolRenderer,
QgsMarkerSymbol,QgsMessageLog,QgsRectangle,QgsRendererCategory,
QgsRendererRange,QgsSymbol,QgsVectorDataProvider,QgsVectorLayer,
QgsVectorFileWriter,QgsWkbTypes,QgsSpatialIndex)
####################################33
QgsApplication.setPrefixPath("/usr", False)
#import processing


sys.path.append('~/.local/share/QGIS/QGIS3/profiles/default/python/')
#################################################
os.chdir("~/rsync/avaliar_umep/")
input_file="~/rsync/avaliar_umep/Height-rec-wg.shp"
clip_polygons_file="~rsync/avaliar_umep/grilla01.shp"
output_folder="~lixo/"
input_layer = QgsVectorLayer(input_file, "input file", "ogr")
QgsProject.instance().addMapLayer(input_layer)
tile_layer  = QgsVectorLayer(clip_polygons_file, "clip_polys", "ogr")
QgsProject.instance().addMapLayer(tile_layer)
tile_layer_dp=input_layer.dataProvider()
print(tile_layer_dp)
EPSG_code=int(tile_layer_dp.crs().authid().split(":")[1])
tile_no=0
clipping_polygons = tile_layer.getFeatures()
heightshapes=[]

for clipping_polygon in clipping_polygons:
    print("Tile no: "+str(tile_no))
    tile_no+=1
    geom = clipping_polygon.geometry()
    area=geom.area()
    print(area)
        
    clip_layer=QgsVectorLayer("Polygon?crs=epsg:"+str(EPSG_code)+\
    "&field=id:integer&index=yes","clip_polygon"+str(tile_no), "memory")
    clip_layer_dp = clip_layer.dataProvider()
    clip_layer.startEditing()
    clip_layer_feature = QgsFeature()
    clip_layer_feature.setGeometry(geom)
    (res, outFeats) = clip_layer_dp.addFeatures([clip_layer_feature])
    clip_layer.commitChanges()
    
    #print(clip_layer.extent())# linha desnecessaria neste momento



    clip_file = os.path.join(output_folder,"tile_"+str(tile_no)+".shp")
    output=processing.run('qgis:clip',{'INPUT': input_layer, \
    'OVERLAY': clip_layer, 'OUTPUT': "memory:"})
    outputlayer=output['OUTPUT']
    
    

Thanks. I am looking foward for your help.

Regards

  • QGIS version 3.12.3-BucureČ™ti – miguelr Jul 3 at 15:44

Browse other questions tagged or ask your own question.