Friday, 2 March 2018

geometry - What is the PostGIS 2.x equivalent of the pre-PostGIS 1.5 ~= operator?


Stemming from my other question: When would a PostGIS geometry compare using ~= return true when ST_Equals returns false?, what is the PostGIS 2.x equivalent of the pre-PostGIS 1.5 ~= operator?


It appears that from 1.4 to 1.5, the ~= operator changed from an "exactly equal" to an "bnd equal":


For example, in v1.3:
http://postgis.net/docs/manual-1.3/ch06.html#id439812
The "~=" operator is the "same as" operator. It tests actual geometric equality of two features. So if A and B are the same feature, vertex-by-vertex, the operator returns true.


and in 1.5 and later:
http://postgis.net/docs/manual-1.5/ST_Geometry_Same.html
Returns TRUE if A's bounding box is the same as B's.


I'm mostly interested in PostGIS2.0, but I'm not tagging a specific version and leaving it open.




Answer



It does seem that the "[test] for actual geometric equality of the two features" is missing from later versions, but according to this article from Boundless (formerly OpenGeo), the function ST_Equals can be thought of as testing for "exact equality" even though, according to the documentation, it does not make this comparison vertex-to-vertex.


For instance, in this example, from the PostGIS 2.0 documentation, these linestrings are considered equal even though there is one vertex not shared between them. Presumably, in any case where such vertices fall on the same, shared boundary, the geometries are considered equal.


SELECT ST_Equals(ST_GeomFromText('LINESTRING(0 0, 10 10)'),
ST_GeomFromText('LINESTRING(0 0, 5 5, 10 10)'));
st_equals
-----------
t
(1 row)


ST_OrderingEquals provides the same result with the same example, but this function is actually more constrained: it tests both for "equal geometry" and that the "points are in the same directional order." The article on Equality from Boundless is recommended.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...