This question is related to Rotating point feature symbols by intersect polyline in ArcGIS Desktop?, but my problem differs slightly.

I have a layer with polygons (nearly all rectangular) and a second one with points. The points are set in the middle of one of the sides of each polygon. I need to represent the points as arrows pointing directly into the polygon. So far I use an attribute of the point layer for rotation and fill the rotation in manually, but I was wondering, if I could derive the rotation value from the direction of the polygon segment automatically?

I use QGIS 2.18.16 on a Windows 7 PC.

  • Do they have common id fields which define point-polygon relationship? – Kazuhito Feb 2 '18 at 10:36
  • Yes they have a common unique ID. The relationship is also defined spatially, since the point is set (snapped) on the polygon edge. – akra-kachi Feb 2 '18 at 10:36

Sorry if I misunderstood your requirement; this is what I had by a Virtual Layer.

enter image description here

This query is:

SELECT make_line(testpoint.geometry, st_centroid(testpolygon.geometry))
FROM testpoint
INNER JOIN testpolygon
ON testpoint.id = testpolygon.id


You needed rotation value, rather than the arrow ... my apologies.

SELECT degrees(st_azimuth(testpoint.geometry, (st_centroid(testpolygon.geometry)))) 
       AS deg, 
       make_line(testpoint.geometry, st_centroid(testpolygon.geometry)) 
       AS geometry
FROM testpoint
INNER JOIN testpolygon
ON testpoint.id = testpolygon.id

enter image description here

Edit 2: To combine the azimuth data with the point layer, a syntax like below can be used. If other attribute fields from point layer are needed, add them to the SELECT, too.

SELECT testpoint.*,
       degrees(st_azimuth(testpoint.geometry, (st_centroid(testpolygon.geometry)))) AS deg
FROM testpoint
INNER JOIN testpolygon
ON testpoint.id = testpolygon.id

For this time, please explicitly set the geometry type to Point, as the previous layer was automatically set to line.

  • Thanks for the fast answer. It works in a way, but as soon as I hand it more than one pair of point and polygon, the virtual layer produces only one point nevertheless. Perhaps I made a mistake. Here is the Code I typed: SELECT degrees(st_azimuth(point.geometry, (st_centroid(poly.geometry)))) AS deg, make_line(point.geometry, st_centroid(poly.geometry)) AS geometry FROM point INNER JOIN poly ON point.code_schn = poly.code_schn – akra-kachi Feb 2 '18 at 13:41
  • @akra-kachi Your syntax looks good to me. Will you re-run the SQL after adding new pairs? Right-click the virtual layer ->> Edit virtual layer settings will call up the Virtual Layer window. Then click [OK] to re-run. – Kazuhito Feb 2 '18 at 13:50
  • No, I gave it my layers with about 40 points/polygons. Solved this issue, however. I had the geometry type of the virtual layer set to point, but if I set it on automatic it works. Now I am just wondering, how to transfer the data from the virtual layer into the attribute table of the original point layer. – akra-kachi Feb 2 '18 at 14:48
  • @akra-kachi Glad to hear you have solved it. As to the latter part, I will add another syntax to combine the azimuth data to a point layer. – Kazuhito Feb 2 '18 at 14:55
  • Works perfectly. In case anyone has (like me) problems copying the values from the deg-field into the original point layer attribute table see this tutorial qgistutorials.com/de/docs/performing_table_joins.html and then copy the attributes from the new virtual_layer_deg column into the original column using the field calculator. – akra-kachi Feb 4 '18 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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