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

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


8

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,...


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 ...


8

You can ship them in your plugin. Create a Python file called, for example, qgis_expression.py: from qgis.utils import qgsfunction @qgsfunction( args='auto', group='Your group', usesGeometry=False, referencedColumns=[], helpText='Define the help string here') def your_expression(params, feature, parent): # UPDATE the qgsfunction above # ADD ...


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

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

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

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


6

You can add your custom functions to your plugin. The main file of plugin should be like this: from qgis.utils import iface, qgsfunction from qgis.core import QgsExpression #### YOUR CUSTOM FUNCTION #### @qgsfunction(args='auto', group='customFunctions', register = False) def custom_function1(values, feature, parent): # # CODE # # return ##...


6

In the end I ended up combining Kadir's and etrimaille's answers and adding one crucial part. I used etrimaille's idea of having the function in its own file and importing that into my plugin, as that fits better with the structure of the existing plugin. To have this to work, I needed to put the import statements into the file with the function in it. ...


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, ...


5

You could make use of the Function editor in the Field Calculator which allows you to create a function. This can return the value from the COST column when specifying the ITEM. In your Field Calculator, click the Function Editor tab, either create a new file or edit an existing one and enter the following code: from qgis.core import * from qgis.gui import ...


4

You can use function editor tab in the field calculator and make your azimuth function like this: from qgis.core import * from qgis.gui import * @qgsfunction(args="auto", group='Custom') def azimuth(x1,y1,x2,y2,feature,parent): p1 = QgsPoint(x1,y1) p2 = QgsPoint(x2,y2) a = p1.azimuth(p2) if a < 0: a += 360 return a Once ...


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

I'm pretty new to QGIS thing (API especialy), but it seems that there is no easy way how to obtain reference to layer from feature. Maybe you should pass layer name (or ID) as another argument to function. Then you can get CRS the same way as for polygon layer. In expression editor, you can then pass @layer_name (or @layer_id) variable as parameter to your ...


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 ...


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