2

I am using QGIS 2.18 and I am wondering how to find the NW corner of a polygon and create an attribute of that point number. See the attached image.

enter image description here

For example, please node 8 is the NW corner for Grid #1, 13 is the NW corner for Grid 5 and so on. any help with this would be wonderful. The two files I am working with is

Grid = 'grid'

and

Vertex = 'nodes'
2

QGIS 2.18.20

(Latest QGIS versions have issues with Virtual Layer)

Add a Virtual Layer with below syntax:

SELECT grid.*, nodes.id
FROM   grid, nodes
WHERE  st_touches(grid.geometry, nodes.geometry) = 1                  -- (1)
       AND
       st_x(nodes.geometry)-st_x(st_centroid(grid.geometry)) < 0      -- (2)
       AND
       st_y(nodes.geometry)-st_y(st_centroid(grid.geometry)) > 0      -- (3)

Footnotes:

The idea is really simple. As you need northwest corner, the x coordinate at the vertex is less, while the y is greater, than the centroid of the polygon.

(1) This helps to choose touching four corner points around each polygon.

(2) x-difference (dx) between the anticipated node and the centroid becomes negative.

(3) y-difference (dy) between the anticipated node and the centroid becomes positive.

enter image description here

So, if you want to find NE corner, (2) should be >0.

  • what are the needed attributes in each layer to make this work? worked but not sure how it did it and would like to work my way through understanding it. – lowsparked Sep 22 '18 at 2:03
  • i get this error when adding the virtual layerLayer is not valid: The layer ?query=SELECT%20grid.*,%20nodes.id%0AFROM%20%20%20grid,%20nodes%0AWHERE%20%20st_touches(grid.geometry,%20nodes.geometry)%20%3D%201%20%0A%20%20%20%20%20%20%20AND%0A%20%20%20%20%20%20%20st_x(nodes.geometry)-st_x(st_centroid(grid.geometry))%20%3C%200%20%0A%20%20%20%20%20%20%20AND%0A%20%20%20%20%20%20%20st_y(nodes.geometry)-st_y(st_centroid(grid.geometry))%20%3E%200 is not a valid layer and can not be added to the map – lowsparked Sep 22 '18 at 2:19
  • to claify in the nodes layer i have a attribute of "Node_Id" and in the grid layer i have a attribute of "Grid_ID" – lowsparked Sep 22 '18 at 2:23
  • @lowsparked Added some explanation with picture. If your nodes layer has "Node_ID", then the first line would be SELECT grid.*, nodes.Node_Id. – Kazuhito Sep 22 '18 at 2:23
  • that settles that .. I owe you a beer! Thank you so much for helping me understand how it all came about! – lowsparked Sep 22 '18 at 2:31

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.