1

I'm having issues with drawing line(s) from point layer at azimuth value and given distance (using layer "float" field with azimuth). I'm trying to do this using Geometry Generator display for geopackage layer (created using Python/geopandas), and azimuth field 'azi1' might have "float" value in degrees (or NULL if there is nothing to draw). I keep getting "Eval Error: Cannot convert 'azi1' to double" (despite the value is always numerical or NULL in the table). GG code looks like this:

CASE WHEN 'azi1' IS NULL THEN make_line(@geometry,@geometry) ELSE collect_geometries( make_line(@geometry, make_point( x(@geometry)+20*cos(radians('azi1')), y(@geometry)+20*sin(radians('azi1'))))) END 

"make_line(@geometry,@geometry)" is temporary, is there anything like Pythonic "pass" in GG syntax? (there should be just a point, but probably it can't be displayed in line-based GG)

Am I doing something wrong with NULL check (in GeoPandas dataframe that was NaN, but in QGIS table it shows as NULL), conversions from decimal degrees to radians is done wrong or is it something else (maybe I should use shapefile etc.)?

I'm using QGIS 3.32.2.

2
  • 1
    Change 'azi1' to "azi1". Single quotes are for strings, double quotes for fields Commented Oct 11, 2023 at 13:30
  • 1
    Thanks! It works! I'm just so used to Python syntax (also used in QGIS Python Console) that I'm missing quite obvious things like that... Commented Oct 11, 2023 at 14:32

2 Answers 2

2

The problem was rather simple, I should use double quotes for fields (single quotes are for strings). Beside I switched cos with sin...

Posting right code, maybe it'll be useful for others:

CASE WHEN "azi1" is null THEN make_line(@geometry,@geometry) ELSE collect_geometries( make_line(@geometry, make_point( x(@geometry)+20*sin(radians("azi1")), y(@geometry)+20*cos(radians("azi1")))) ) END 

I'm open to suggestions, if anyone has ideas to add/upgrade anything (collect_geometries is to add links for other azimuth fields, but whole CASE should look different, etc.).

1
  • hi, it seems safe to me if you return a null geometry if azimut is null, at least safest than return a non-valid geometry. Commented Oct 12, 2023 at 0:17
1

As another update, here's the code for up to 4 (can be extended any other fixed number) external links, with assumption that every node has at least one link (else you should add NULL check for 1st). The distance to draw lines from nodes is set to 20, but (obviously) can be changed to another "field name".

collect_geometries( make_line(@geometry, make_point( x(@geometry)+20*sin(radians("azi1")), y(@geometry)+20*cos(radians("azi1")))), make_line(@geometry, if ("azi2" is NOT NULL, make_point( x(@geometry)+20*sin(radians("azi2")), y(@geometry)+20*cos(radians("azi2"))),@geometry)), make_line(@geometry, if ("azi3" is NOT NULL, make_point( x(@geometry)+20*sin(radians("azi3")), y(@geometry)+20*cos(radians("azi3"))),@geometry)), make_line(@geometry, if ("azi4" is NOT NULL, make_point( x(@geometry)+20*sin(radians("azi4")), y(@geometry)+20*cos(radians("azi4"))),@geometry)) ) 

I was hoping to add some Python-style loop using field name pattern (for i in [1,2,3,4] using field name as f'azi{i}'), but... maybe I need more experience in GG coding ;-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.