[Qgis-user] using difference on buffers
Chan Dolan
chandler.dolan51 at gmail.com
Tue Feb 2 14:58:51 PST 2021
Opening this thread back up
I've been trying to run this code, but get the following error messages
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS3~1.16\apps\Python37\lib\code.py", line 63, in
runsource
code = self.compile(source, filename, symbol)
File "C:\PROGRA~1\QGIS3~1.16\apps\Python37\lib\codeop.py", line 168, in
__call__
return _maybe_compile(self.compiler, source, filename, symbol)
File "C:\PROGRA~1\QGIS3~1.16\apps\Python37\lib\codeop.py", line 99, in
_maybe_compile
raise err1
File "C:\PROGRA~1\QGIS3~1.16\apps\Python37\lib\codeop.py", line 87, in
_maybe_compile
code1 = compiler(source + "\n", filename, symbol)
File "C:\PROGRA~1\QGIS3~1.16\apps\Python37\lib\codeop.py", line 133, in
__call__
codeob = compile(source, filename, symbol, self.flags, 1)
File "<input>", line 11
buf_layer.dataProvider().addFeatures(feats)
^
SyntaxError: invalid syntax
I'm not quite sure how to interpret it. I have experience coding with R,
but python is all new to me. Do you know what is causing this error?
-Chan
On Tue, Jan 19, 2021 at 10:49 AM Chan Dolan <chandler.dolan51 at gmail.com>
wrote:
> thank you thank you!
>
> Ill try it out and report how it goes.
>
> On Mon, Jan 18, 2021 at 9:56 PM <qgis-user at stripfamily.net> wrote:
>
>> Here's a script to buffer each feature, difference the original from the
>> buffered, and leave the difference in a new layer.
>> The script operates on the active layer and assumes it is a polygon
>> layer. The results will be unpredictable if it's not.
>> At the top of the script are two parameters, buf_dist and buf_segments.
>> These have the same meaning as the buffer operation in geoprocessing.
>> Remember that the buf_dist is in the units of the CRS. My test data was in
>> meters, so the buf_dist = 10000 is 10 kilometers.
>> All the attributes are copied to the new layer, which is called
>> buffer_diff. Attributes that are based on the geometry are NOT
>> recalculated, so areas or perimeters will be wrong.
>> If you run this from the python console, as each feature is processed
>> you'll get the message "Adding feature". After the last feature is added
>> there may be a noticeable pause before the canvas is repainted.
>>
>> I've only tried this on a couple of layer files and they were both in the
>> same CRS, so let me know if this fails for your data and I'll see what I
>> can do.
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210202/12ceb190/attachment.html>
More information about the Qgis-user
mailing list