13

EDIT I edited the question because the OP specified that he is working with point shapefiles (the approach will be similar to the original one, though). I propose an approach which only recurs to a geometry generator and a custom function. Context Let's assume to start from this point vector layer representing the stones: The layer stores the class ids ...


12

I propose an approach that only recurs to a geometry generator and a custom function. Before starting, I want to underline that I will focus the attention on the explanation of the minimal things to do for reproducing the desired result: this means that some other minor parameters (like sizes, widths and so on) should be easily adjusted by you for better ...


11

Do not call the function azimuth as there is already an existing Math function called this. Instead give it another name like azi(): And now you should be able to call it:


11

Not a perfect solution but you could make use of the Geometry Generator which adds a visualised line to represent the intersection. You could then set this to overlap the original line feature. Add a new symbol layer by clicking the plus sign and select the Geometry generator as symbol layer type. Set the geoemtry type to LineString / MultiLineString and ...


10

EDIT: I edited the answer according to some comments by JWes. You may run a simple script from the Python Console. Firstly, open the Python Console from Plugins > Python Console and activate the button for the Editor: Then, load the object (a vector, a table, etc.) where your data are stored. Once you have done this, copy the following code in the Editor: ...


9

Try this if you want to Select by Expression GetUtmZone() = '40N' If you just need to get the return value from the function you can just do GetUtmZone() The $ prefix used to be used for functions that took no arguments however that is no longer used in later versions, the version in the tutorial is a older QGIS version that still supported that format.


9

I propose an approach that only recurs to a geometry generator and a custom function. Context Let's assume to start from this situation (hopefully very close to yours), where the several parking restrictions are stored in the "Condition" field: I also assume that you know how the QGIS custom functions work, otherwise this post might be helpful: How to ...


8

Here's a somewhat approximate (but hopefully effective) way to do it. First some math. We need to figure out how many characters at a certain font-size a feature can contain. Here things / assumptions to know: assuming metric units, (added slight change below which may make this work for us foot crs.) font size is a measure of font height. Most font's are ...


8

What you are doing is the correct way to document your custom function. The error you are encountering is because by default when you write a function in the Function Editor, the indentation before the return statement is that of 4 spaces characters and not 'tab space'. Just check if that is the case. The indentation should be consistent (either only spaces ...


8

If you right-click your layer and go to Properties > Fields then click the Text Edit, you can set Default values (either by typing in a value or using an expression) which will appear in the attribute table automatically. Unfortunately, using an expression like $rownum (which should get you unique ids for your features) does not work (my guess is because ...


7

I finally solved the problem! It was really a type-problem, as input values are defined as QVariant inside @qgsfunction. So, to get my code work I had to convert them into integers first. Apparently, QGIS takes care of type conversions itself... Function looks like this now: @qgsfunction(args="auto", group='Python') def bitwise_and(value1, value2, feature,...


7

Yes, it's possible, using the new Python function editor in 2.8 or later. For a good tutorial check out this youtube video Your existing expression will always show the value of field "LAENGE" for all features, this is working as expected. What you really want is an $is_selected() function which evaluates to True if the feature is selected, or False if it ...


6

This is not a very efficient method but is one I used before. Make sure Field2 and Field3 exist then use something like the following: from qgis.core import * from qgis.gui import * import re @qgsfunction(args='auto', group='Custom') def func(field, feature, parent): # Get active layer layer = qgis.utils.iface.activeLayer() # Get field indices ...


6

Interesting, this also worked for me before (I used it several times) but it also fails for me on QGIS 2.18.2. Anyway, an alternative is to instead create a field which contains the zones for each feature and then use this field in your select expression. You can do this by creating a script which you can add by going to: Processing Toolbox > Scripts &...


6

New versions of QGIS ship with an azimuth function out of the box:


6

Instead of defining a custom function, you can simply use regexp_substr() in the field calculator with the following regex: regexp_substr( "YourField" , '-(?!.*-)(.*)$' ) This will return the substring after the last -. If you need to change the delimitor, just replace - with the proper character in the regex. Edit: a short explanation of the syntax: - ...


6

There are two things worth noting in this tutorial with respect to QGIS 2.18: The code that is written in this exercise is a function (and not a variable). Functions are called with brackets (and parameters where applicable), so one needs to write GetUtmZone(). Do not reference it as a variable with a $ prefix. This expression requires the geometry of the ...


6

You can use the plugin "AutoFields" for Automatic attribute updates when creating or modifying vector features


5

Yes you can. The problem is, that there is no method trim available. But there is a method strip() available on every string. You probably want to do s = value1 + value2 # Concat s = s.strip() # Trim In general, you need to import functions. So if you did not import the function trim, it will not be available.


5

You need to specify that this function requires the geometry with the kwarg usesgeometry=True. If you don't, you may get a geometry but there is no guarantee (as you realized). This works starting from QGIS 2.4 from qgis.utils import qgsfunction from qgis.core import QGis @qgsfunction(0, "Python", usesgeometry=True) def test(values, feature, parent): ...


5

Use None instead of Null ... or don't use it at all but specify the value must be set. You can read more about identifying the nulls v = [ x for x in vals if x is not None] or tell it to return items that are set, implicitly that are not-null v = [ x for x in vals if x] EDIT Ok, it seems the issue is not the handling of the nulls within the function, ...


4

This is fairly easy to do using the Field calculator and a simple custom function. The result is a string, which you can coerce to a proper time/date class later (e.g. for some proper date/time calculations), or extend the script to do that for you. Open Field calculator and click the Function editor tab. You can create a new New file or extend an existing ...


4

Have you thought of styling the data as a heatmap. This way areas of concentration will show up as more intense colors. I am not sure what program you are using but this can be done quite simply using QGIS. A good tutorial explaining the process can be found at http://www.qgistutorials.com/en/docs/creating_heatmaps.html.


4

Perhaps a look at http://pyqt.sourceforge.net/Docs/PyQt4/qfontmetrics.html might help. You can obtain pixel dimensions of a string for a given font as follows: from PyQt4 import QtGui f = QtGui.QFont("times", 24) fm = QtGui.QFontMetrics(f) >>> fm.width("My test text") 149 >>> fm.height() 36 Since this function doesn't seem to take line ...


4

You can use HTML and/or CSS in the function's DocString.


4

You can't run the built-in expressions as they are defined in the Field Calculator framework. This means that any expression like azimuth, @geometry, centroid and so on won't work if you try to use them when building a custom function. Instead, you need to use the common PyQGIS syntax as you were writing a script from the Python Console or the Processing ...


4

Your syntax in last line isn't good... You need to use list comprehension. Try with something like below, it will return a string which is a list of the selected features's id. from qgis.core import * from qgis.gui import * from qgis.utils import * @qgsfunction(args=0, group='Python') def is_selected(values,feature,parent): layer = qgis.utils.iface....


3

Duplicate the layer, one with no symbology, and set different zoom levels/obstacle settings for the labels for each.


3

It looks like this has been done successfully in Python. Have a look at this post on Stack Overflow. In order to replicate this in QGIS, you'll need to create a function to use in the Field Calculator. Your custom function will look similar to this: from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def serbian(n): ...


3

Your uniqueList = [] statement needs to be outside the function. Because every time your function is called, the uniqueList variable would be initialized as empty again. Try the below code, it should work - from qgis.core import * from qgis.gui import * uniqueList = [] @qgsfunction(args='auto', group='Custom') def FindDublicate(IDfield, feature, ...


Only top voted, non community-wiki answers of a minimum length are eligible