1

I need to extract the vertices coordinates of the four corners of each rectangle of a layer made up of 729 polygons (= map sheets). I began using Vector/Geometry Tools/Extract Vertices function to create a vertices layer but each rectangle contains 7 vertices - the first and the last are superimposed, I suppose - so I want to eliminate the median vertices and one of the two (the first or the last) vertices superimposed. Moreover the 4 vertices of each rectangle coincide with the vertices of the adjacent rectangles having the same coordinates but different attributes related to the different map sheets. enter image description here

Now I do not know how to delete the unwanted vertices (I can not use the Processing / Vector General / Delete Duplicate Geometries function because it would also delete the vertices of adjacent rectangles). How to solve this problem?

  • How would you like the final output? Is it XY coordinates in the attribute table, or do you need extracted geometry of four points for each grid? – Kazuhito Dec 10 '18 at 10:08
  • The initial problem was this: gis.stackexchange.com/questions/301387/… – Andrew-63 Dec 10 '18 at 10:49
  • Ah, I see. Then can I say the NW corner is the first/last node? And the polygon is made clockwise / anti-clockwise? – Kazuhito Dec 10 '18 at 10:54
  • Sorry, how can i verify this? – Andrew-63 Dec 10 '18 at 11:13
  • Test Extract Vertices (see Ed Rollason's answer) on one of the polygon, and check vertex_index while clicking on each nodes. If you know the order it helps to distinguish which node corresponds to which corner. – Kazuhito Dec 10 '18 at 11:20
1

As your polygons are essentially square then running Processing -> Simplify on them using default tolerance (1.00) should be enough to remove the extraneous vertices and leave you only with corners (4 per polygon).

You can then use Processing -> Extract Vertices to create a point file of all vertices (albeit I don't know if this extracts the underlying polygon attributes). You can add geometry information using Processing -> Add Geometry Outputs.

EDIT

The original answer above works on small-scale cartographic coordinate systems such as British National Grid because generated grids are actually square/simple and therefore can be represented by only 4 vertices. In this case the data is in UTM 32N and closer inspection of the data reveals that the polygons are not regular due to the distortion from the projection. This appears to be the reason that standard methods such as simplification don't work. Because there is no standard pattern to vertex order, ramping up simplification tolerances ends up destroying a lot of the polygons rather than extracting corners.

The method outlined below does appear to work for the purposes laid out in the original question. It could be relatively easily automated as it isn't the most elegant:

  1. Add a unique identifier to your polygon layer if they don't already have one
  2. From Processing -> SAGA -> Vector General run the Feature Extents tool, using Each Shape as the creation option. This creates a new polygon layer which is essentially identical to the original but intervening nodes are trimmed out. Because of this there is a small degree of offset between the corners of each polygon (see image). Some spot testing suggests this is <50m.

Step 2 result showing polygon corner offset

  1. If you add a new field to the attribute table of these new polygons and run num_points($geometry) you'll see that for some reason each polygon still has 5 vertices. Two of these per shape are identical, although where they occur and their index value is not standard. Testing indicates that Remove duplicate vertices doesn't seem to work regardless of tolerances; this may be a geometry error. Instead, to remove the duplicates run Processing -> Vector General -> Vector Geometry -> Extract Vertices to get the vertices of these new polygons.
  2. Finally run Processing Processing -> Vector General -> Remove Duplicate Geometries to delete the duplicates.

You should be left with a point file where each group of four points represents the corners of a polygon grid square. There will be slight offset between the corners of each polygon but given the scale of your map you should be able to round this out when displaying the values (as per your original question linked in the comments). You will be able to identify each group of four using the unique ID you added in step 1.

  • Using 'simplify' (tolerance=1.00) the number of vertices, unfortunately, only goes from 7 to 6 for each polygon – Andrew-63 Dec 10 '18 at 11:00
  • That's interesting. This question explains a little more about how simplification works (gis.stackexchange.com/questions/148585/…). You could trying setting the tolerance to just over half the length of your polygon sides? Worth having a play about with it. – Ed Rollason Dec 10 '18 at 11:26
  • I tried to enter different tolerance values but unfortunately without result. The 'Simplify' algorithm seems to eliminate segments that are shorter than the tolerance value by changing the shape of the polygon – Andrew-63 Dec 10 '18 at 17:19
  • Ed and @Andrew-63; I am in favor of this approach. If QGIS Simplify is not satisfactory, how about GRASS v.generalize.simplify algorithm? There is a douglas-reduction method, for which you can set Percentage of vertices you want to keep (in this case 4 of 6-7 nodes, so 60-80% would be good threshold). – Kazuhito Dec 10 '18 at 19:00
  • I tried with v.generalize setting the percentage to 70% or 60% and leaving the other parameters as default, but unfortunately the number of vertices is reduced only from 7 to 6. – Andrew-63 Dec 11 '18 at 9:06
0

You can use point_n() function to extract geometry of each vertex.

For instance, geom_to_wkt( point_n( $geometry, 1)) will return the first node of the polygon.

enter image description here

Please note that in this function vertex number starts from 1. So the required four corners are represented by node-1, node-2, node-4, and node-6. (node-3 and node-5 are mid-points and node-7 is the duplicated last node).

If you have information at which corner your polygon ring starts, you can easily assign your field name to NW, NE, SE, SW.

Anyway, let us try to find node-1, -2, -4, -6.

enter image description here

(Nothing special... just calculating geom_to_wkt(point_n($geometry, 1)), geom_to_wkt(point_n($geometry, 2)), geom_to_wkt(point_n($geometry, 4)), geom_to_wkt(point_n($geometry, 6)) for each field...)

Each field has XY coordinate in WKT point format, and you can change format or create new rectangle geometry from these fields if you like.


EDIT

To understand which vertex is located at which corner, use Extract Vertices Tool and visually check the nodes against the attribute table. In this example it starts at NW corner and drawn clockwise. (NB: Extract Vertices records the index starting from 0).

enter image description here

  • It seems that polygons are counter-clockwise oriented but do not all have the same position as the starting point. Does the expression you propose apply automatically to all polygons if the vertices are ordered in the same way and start from the same position? – Andrew-63 Dec 10 '18 at 12:53
  • @Andrew-63 Yes, it works for all polygons at once...but it is troublesome if the starting point is located differently on each polygon. Maybe this is not a good answer. – Kazuhito Dec 10 '18 at 13:03
  • I replaced the image in the initial question to better clarify the problem. As you can see each polygon has a different arrangement of the vertices and this does not allow to have a single expression for all the polygons, if I understand correctly the solution You suggest. – Andrew-63 Dec 10 '18 at 17:15
  • @Andrew-63 Thanks. Now it is clear to me, too. And it seems number of nodes are different in some polygons. I really recommend Ed's approach, to simplify vertices. – Kazuhito Dec 10 '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.