0

I was wondering about the method/specification of choosing the first vertex in a polygon. Let's say that I have polygon that has 4 vertices, ([0 0] [10 0] [10 10] [0 10]). Which of them will be the first node when iterating through them (and why)?

My thought is that the vertex with minimal x-value is chosen (and if there are several vertices that share the same x-coord then the vertex with minimal y-value among them is chosen),also the nodes above would be represented this way in a GeoJSON:

[[[0 0]
  [10 0]
  [10 10]
  [0 10]
  [0 0]]]

I have not found any source that confirms or denies this.

I am using OSM data that is stored in PostGIS and the polygons will be examined by simple software that I wrote.

4
  • 1
    there is no reason for picking any one vertex over any other in most cases so I would not expect there to be a "good" answer to this in general. Which program/language/toolkit are you interested in
    – Ian Turton
    Apr 15, 2020 at 13:06
  • 3
    This is going to depend on a) the software that created the data set, b) the software that is reading the data set, and c) the format that the dataset is being stored. And apart from a brief mention of geoJSON you've given us no clues to go on! But in any case, all vertices are equivalent and any software that expects any special ordering will break.
    – Spacedman
    Apr 15, 2020 at 13:06
  • I have edited the question and added the requested information. Is there anything more that is unclear?
    – Bartors
    Apr 15, 2020 at 13:15
  • Too much information! I've zapped your supplementary question since we should concentrate on one question first.
    – Spacedman
    Apr 15, 2020 at 13:46

1 Answer 1

3

The first vertex is... the first recorded one. There is no need to re-order them. When someone creates a polygon, he starts with the 1st vertex, then the 2nd and so on, which is eventually saved in the same order and is later retrieved in the same order.

Let's not forget that several storage formats - if not most of them - requires that the 1st and last vertex of a polygon be the same.

4
  • They aren't always retrieved in the same order. Some applications will rewrite to correct for ring orientation and ring order and/or inversions.
    – Vince
    Apr 15, 2020 at 13:21
  • @Vince ok for geometry corrections, but what about any valid polygon?
    – JGH
    Apr 15, 2020 at 13:23
  • Functions may also re-order vertices because by definition the order of the vertices does not matter if the winding direction is correct. Therefore PostGIS returns "true" for SELECT ST_Equals(ST_GeomFromText('POLYGON (( 4 8, 4 7, 3 7, 3 8, 4 8 ))'),ST_GeomFromText('POLYGON (( 3 8, 4 8, 4 7, 3 7, 3 8 ))'))
    – user30184
    Apr 15, 2020 at 13:30
  • Well-constructed geometries will usually come back in the order specified, though in theory, if they're well-constructed, it shouldn't matter.
    – Vince
    Apr 15, 2020 at 16:02

Your Answer

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

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