1

I call using processing.alghelp("grass:r.to.vect")

I looked input:

 <ParameterRaster>
feature <ParameterSelection>
-s <ParameterBoolean>
GRASS_REGION_PARAMETER <ParameterExtent>
GRASS_OUTPUT_TYPE_PARAMETER <ParameterSelection>
output <OutputVector>


feature(Feature type)
    0 - line
    1 - point
    2 - area
GRASS_OUTPUT_TYPE_PARAMETER(v.out.ogr output type)
    0 - auto
    1 - point
    2 - line
    3 - area

then I try to do , processing.runalg("grass:r.to.vect" , iface.activeLayer,2, True, None,3,r"C:\Users\user2\Desktop\1\temp\drfsg\zhopa.shp")") but it returns an error, what I did wrong? the project is only one raster layer

6
  • You should use correct path-notation in strings: r"C:\Users\user2\Desktop\1\temp\drfsg" or "C:/Users/user2/Desktop/1/temp/drfsg" or "C:\\Users\\user2\\Desktop\\1\\temp\\drfsg" Don't know if thats the issue.. Commented Feb 9, 2017 at 9:42
  • that is not the way, it gives another error , 'int' object has no attribute 'split'
    – frontend33
    Commented Feb 9, 2017 at 9:44
  • 1
    I think your GRASS_REGION_PARAMETER needs no int (your value is 2) but should be a string like it was used here: gis.stackexchange.com/questions/75666/… Commented Feb 9, 2017 at 9:58
  • processing.runalg("grass:r.to.vect" , iface.activeLayer,2, True, None,3,r"C:\Users\user2\Desktop\1\temp\drfsg\zhopa.shp") writing does not issue error, but nothing happens, does not work
    – frontend33
    Commented Feb 9, 2017 at 10:05
  • if the code runs without an error than it is likely a problem with the dataset used. Data values, data size, for example. So please give more information about what you trying to achieve. Commented Feb 9, 2017 at 10:14

1 Answer 1

1

The recent QGIS versions have implemented GRASS7 into its processing framework as default so you may need to use grass7:r.to.vect instead of grass:r.to.vect. I have also experienced issues when trying to set the GRASS_REGION_PARAMETER to blank, instead I use the extents of the input layer as that's usually what I am interested in.

So you could try the following code into the python console:

from PyQt4.QtCore import QFileInfo
import processing

# Identify raster layer
raster = iface.activeLayer()
fileName = raster.source()
fileInfo = QFileInfo(fileName)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(fileName, baseName)

# Define the extent of the region
extent = rlayer.extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()

processing.runalg("grass7:r.to.vect",rlayer,2,True,"%f,%f,%f,%f"% (xmin, xmax, ymin, ymax),3,"C:/Users/user2/Desktop/1/temp/drfsg/zhopa.shp")
8
  • thank you very much it works on both the version Qgis 12.8 and 12.2 as ))) Is it possible in this vector layer to make more transparent the fill?
    – frontend33
    Commented Feb 9, 2017 at 10:38
  • @АзаматВалиев - Most welcome, glad it worked! You can make it transparent by changing its style properties by right-clicking the layer and going to Properties > Style :)
    – Joseph
    Commented Feb 9, 2017 at 10:47
  • and whether it is an important question, Grass gis 7 coverage of the region, select the coverage on the map instead of coordinates?
    – frontend33
    Commented Feb 9, 2017 at 10:48
  • and about transparency, I'm doing a module, so that would not have to manually change namely through the console
    – frontend33
    Commented Feb 9, 2017 at 10:49
  • @АзаматВалиев - You can define your own coordinates by replacing "%f,%f,%f,%f"% (xmin, xmax, ymin, ymax) with "0.0, 1.0, 2.0, 3.0" (note they are inside a string). If you want to change the transparency of the layer, there are a number of posts asked here on GIS:SE such as this one: How do I set layer transparency in QGIS 2.0 with Python?
    – Joseph
    Commented Feb 9, 2017 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.