1

Is the line LINESTRING(1 1, 2 2) the same as LINESTRING(2 2, 1 1) ? I would think the answer is not, if there is some directionality implied -- for example, a flight-route from Los Angeles to New York would be different than going from New York to Los Angeles, even though (in this example) it would go along the same path in both ways. Or does a GEO data type not involve anything like a direction and as long as two geography/geometries have all the same points (regardless of order) they are considered the same?

David542
  • 104,438
  • 178
  • 489
  • 842

2 Answers2

2

the answer depends on one's definition of "same".

for ST_Equals they are same, as ST_Equals only cares with topological equivalence and DE-9IM model (https://en.wikipedia.org/wiki/DE-9IM).

but you can still inspect their details, e.g. call ST_StartPoint on both objects, and that returns different values for these geometries.

Michael Entin
  • 7,189
  • 3
  • 21
  • 26
2

The equality really depends with your point of view or usage scenario. If you think the line strings LINESTRING(1 1, 2 2) and LINESTRING(2 2, 1 1) as pure features then you may say that they are equal since they consist of exactly the same points. But if the direction or network analysis matters then they are certainly not equal as you have pointed out. Assume you store a Road table in PostGIS. You may use it to display the roads or may calculate the shortest paths in a navigation application. In the latter scenario the direction matters; even it is important for a road to be one-way or two way. The distinction is much like the difference between the undirected and directed graphs.

Another point of view to evaluate the equality is to look at the PostGIS docs. It describes the LineString as:

A linestring is a path between locations. It takes the form of an ordered series of two or more points.

With that perspective, since it is an ordered set of points you may say LINESTRING(1 1, 2 2) and LINESTRING(2 2, 1 1) are not the same. They have different ST_StartPoint() and ST_EndPoint() values, for instance.

Mustafa Özçetin
  • 1,893
  • 1
  • 14
  • 16