4

I'm very new with QGIS and currently stuck with such problem in my work. Maybe some one knows how to help me?

I have made two separate layers.

  1. Database layer with sites and antennas, containing site center points and azimuths with antennas. So I have created symbols representing such antennas by creating an offset from y points by the size of the symbol in a direction of azimuth data. It looks like this:

    enter image description here

  2. I need to analyse traffic between these antennas, which has enormous amount of data, so in order to not overload the system with data I import some data of wanted object (a new layer in QGIS) containing traffic destination with latitudes of source antenna and target antenna coordinates. together with that I import the azimuth info of both points.

So I create the lines using the function:

enter image description here

It looks like that when I enable both layers on the map:

enter image description here

So where is the problem?

If you look at this lines I cannot see from which sectors to which sectors of another object the line goes to because they all are drown from the centres. How can I make some offsets in the direction of known azimuth in the source point and target point?

In another words:
have lines like this: point1xy....point2xy
I want:
point1xy+y offset (-10) in direction (azimuth1).....point2xy+y offset (-10) in direction (azimuth2)

4
  • Couldn't you make wedge buffers instead of symbols for your antennas, then use the Clip tool to cut the lines with your buffers? Or does it need to absolutely be symbology?
    – Gabriel
    Feb 13, 2020 at 15:25
  • I don't fully understand the situation, but is this what you need?: make_line(make_point("source_longitude"+10*sin(radians("azimuth1")),"source_latitude"+10*cos(radians("azimuth1"))),make_point("target_longitude"+10*sin(radians("azimuth2")),"target_latitude"+10*cos(radians("azimuth2")))). Feb 13, 2020 at 15:37
  • 2
    I think the project(point,distance,bearing) function could also be used effectively in the geometry generator to create the points from which the lines are created.
    – Gabriel
    Feb 13, 2020 at 15:44
  • Gabriel i tried your formula with cos and sin now... make_line(make_point("source_longitude"+10*sin(radians("azimuth1")),"source_latitude"+10*cos(radians("azimuth1"))),make_point("target_longitude"+10*sin(radians("azimuth2")),"target_latitude"+10*cos(radians("azimuth2")))) but this moved my coordinates to another country.. :)) i think i expressed myself wrong with this offset value -10... i tried to match this with symbol offset i use for displaying sectors and its 10mm... not coordinate -10...
    – arturssi
    Feb 14, 2020 at 7:25

1 Answer 1

3

You could forgo your latitude and longitude fields, making your tables lighter. Instead you could have a simple int field with your target fid.

Of course, my answer assumes working with projected data, as far as distances are concerned, where map units are meters.

Here's a quick mockup of the required table for the lines to work:

enter image description here

I added an fid column for clarity, but it is not needed nor used. It's only to be able to see what the feature ID is at a glance.

The geometry generator expression, using projected points from the source and target geometries:

make_line(
   project($geometry,100,azimuth($geometry,geometry(get_feature_by_id('Points',attribute('target_fid'))))),
   project(geometry(get_feature_by_id('Points',attribute('target_fid'))),100,azimuth(geometry(get_feature_by_id('Points',attribute('target_fid'))),$geometry))
)

To explain the different functions:

  • project(point,distance,direction) makes a new point from a starting point's position at a set distance, in a set direction (in radians)
  • azimuth(point1,point2) simply returns the azimuth between the points in radians
  • $geometry returns the geometry of the current feature so any function using this as a parameter will use the current feature's position
  • geometry(feature) will return the geometry of a specified feature, which can also be used in other functions
  • get_feature_by_id(layer,feature id) simply returns a certain feature by using its ID, in a specified layer

Adding everything up, the expression:

  • Finds the azimuth between the source and the target
  • Uses that azimuth to project a new point from the source towards the target (the target feature is found using the target_id field) at a specified distance
  • Repeats the two first steps but in reverse, from the target towards the source
  • Makes a line between the two projected points

If you'd like the distance to always remain the same regardless of zoom level, it's only a matter of using variables in the expression. For example, if your symbol measures 10mm, replace the 100 in my expression by 10*@map_scale/1000. This will multiply the 10mm by the map's current scale denominator, then put it in meters. Of course, this only works if the data is projected to meters.

So now, even if you move a point, the symbology will update without even having to edit any field in your table. The distance between the line and its originating point will also always be 10mm on-screen/on-print.

Here's my result with additional directional arrow on the lines and more points:

enter image description here

8
  • Thanks. Its hard at this moment for me to fully understand this formula and adjust it for my case so i started to use from simple ones...make_line( project($geometry,0.01,radians("source_azimuth")), project(make_point( "target_longitude", "target_latitude" ),0.01,radians("target_azimuth"))) Now i got some improvement with some gap between centroids of the sites. But faced a new problem. 1) how the distance is measured ? can i change it ? why in your formula 100 means 100 meters and in my 100 will go outside the world. Basically 0.01 is like 100 meters...
    – arturssi
    Feb 14, 2020 at 8:16
  • 2) when i zoom in and out the gaps from sectors are different now... When i zoom in and out the symbols of the sectors have the same size on the screen. Any ideas how to adapt lines like that too ?
    – arturssi
    Feb 14, 2020 at 8:19
  • @arturssi 1) the distance is measured in map units. If your data is in a geographic CRS like EPSG:4326, your units are in degrees while mine are in meters, using a projected system. 2) The geometry generator uses map units, not paper units (i.e. millimeters, like symbology), so the distance will scale when you zoom in and out.
    – Gabriel
    Feb 14, 2020 at 14:39
  • @arturssi I added some clarifications, addressed the distance to the points. Hope it helps!
    – Gabriel
    Feb 14, 2020 at 15:21
  • 1
    yeah, thank you so much. :) i got what i wanted in the end and im happy now! Im new didn't know need to mark the answer... :D marked that!
    – arturssi
    Feb 18, 2020 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.