I’ve been working on a standalone Python application using the QGIS Processing Framework. For my application, I am supposed to determine average values of a field from a polygonal vector layer along lines in another vector layer.
To accomplish this, I have been using the "qgis:joinattributesbylocation" algorithm with general.runalg()
as follows:
newLayerp = general.runalg("qgis:joinattributesbylocation", line_layer, polygon_region, u'intersects', 2, 1, "mean,max", 1, None)
newLayer = processing.getObject(newLayerp['OUTPUT'])
When I visualize this layer in QGIS, some lines have been assigned NULL
values. I am not having this issue when using Vector->Data Management Tools->Join Attributes by Location.
How can I get the same results from the standalone application as I seem to be getting from the QGIS GUI?
EDIT
I have tried performing an intersection operation between the line layer and the polygon layer, and then performing the same join attributes by location with the intersection layer and the line layer. I don't get any NULL
values anymore, but I'm getting strange values (it is saying the average field value along the length of the line is in the thousands, when all values are less than ten).
Background Information:
The polygonal vector layer’s field consists of values between 0 and 9. The following is the vector layer, colour-coded according to the field I’m using:
The following are the arguments I’m using for the Join Attributes by Location tool in the QGIS GUI:
The following is the result that I get from running the algorithm through the tool in the QGIS GUI, colour-coded by the value of the field I’m using. This is the result that I want to replicate.
I get the following vector layer from my Python code. The lines with NULL
values are marked in black, and these are what I’m hoping to resolve.
-
Which QGIS version are you using?Joseph– Joseph2017年02月10日 15:30:12 +00:00Commented Feb 10, 2017 at 15:30
-
I'm using version 2.14.8. I've also managed to figure out a workaround, but it essentially involves implementing a join attributes by location method (which I've managed to do).Benjamin– Benjamin2017年02月10日 22:59:14 +00:00Commented Feb 10, 2017 at 22:59
-
Did you test it using the latest version of QGIS (as of now QGIS 2.18.3)?Joseph– Joseph2017年02月13日 10:19:05 +00:00Commented Feb 13, 2017 at 10:19
-
I haven't. The reason I downloaded 2.14.8 was that it was saying it was the latest stable release for PyQGIS development.Benjamin– Benjamin2017年02月13日 11:37:15 +00:00Commented Feb 13, 2017 at 11:37
-
The latest LTR version is 2.14.11, but can't confirm if it is the most stable version. I still have 2.14.3 :)Joseph– Joseph2017年02月13日 11:39:57 +00:00Commented Feb 13, 2017 at 11:39
1 Answer 1
Your code seems ok, but there is still some problem with the spatial operation (that's because you however get a result, even if wrong).
Please, can you try to use ['intersects']
when you call the algorithm? I mean, using this line:
newLayerp = general.runalg("qgis:joinattributesbylocation", line_layer, polygon_region, ['intersects'], 2, 1, "mean,max", 1, None)
instead of what you have provided?
-
With the change you suggested, I still seem to be getting
NULL
values along the same sections of road.Benjamin– Benjamin2017年01月03日 16:09:16 +00:00Commented Jan 3, 2017 at 16:09
Explore related questions
See similar questions with these tags.