# SpatiaLite Equals function vs the standard ‘=‘ operator

When using SQLite with SpatiaLite, what is the difference between ‘=‘ and `Equals`?

As far as I understand from the documentation:

1. Equals(geometry1,geometry2) may return TRUE when geometry1 = geometry2 return FALSE .

2. Is there any case where Equals return FALSE and the operator ‘=‘ return TRUE? (Ignore NULL)

ST_Equals checks if the two geometries are topologically equivalent, so "occupy the same space".

The equals operator checks if the geometries are exactly the same.

Some practical examples of differences are that e.g.

• the order of coordinates can be different for ST_Equals, but they need be exactly the same for the equals operator.
• for a polygon, for ST_Equals it is OK that there are extra collinear points in the boundary, as this doesn't change the space occupied.

I'm not aware of cases where the equals operator will return True while ST_Equals doesn't.

Sample script (in python, but that doesn't matter) that shows that ST_Equals gives different results than the equals operator:

``````import geopandas as gpd

wkt1 = "POLYGON((0 5, 5 5, 5 0, 0 0, 0 5))"
wkt2 = "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))"
wkt3 = "POLYGON((0 0, 0 5, 4 5, 5 5, 5 0, 0 0))"
sql = f"""
SELECT GeomFromText('{wkt1}') = GeomFromText('{wkt1}') AS same_operator
,ST_Equals(GeomFromText('{wkt1}'), GeomFromText('{wkt1}')) AS same_st_equals
,GeomFromText('{wkt1}') = GeomFromText('{wkt2}') AS pointorder_operator
,ST_Equals(GeomFromText('{wkt1}'), GeomFromText('{wkt2}')) AS pointorder_st_equals
,GeomFromText('{wkt1}') = GeomFromText('{wkt3}') AS extrapoint_operator
,ST_Equals(GeomFromText('{wkt1}'), GeomFromText('{wkt3}')) AS extrapoint_st_equals
"""  # noqa: E501
``````

Result:

``````                      0
same_operator         1
same_st_equals        1
pointorder_operator   0
pointorder_st_equals  1
extrapoint_operator   0
extrapoint_st_equals  1
``````
• Suggestion: use `path = ":memory:"` for a more generic example that's runnable on any OS. Commented May 1 at 22:16
• "The equals operator checks if the geometries are exactly the same.": out of curiosity, is there a reference or have you found this via deduction?
– JGH
Commented May 1 at 23:24
• There is a PostGIS reference postgis.net/docs/ST_Geometry_EQ.html but there is an OGC standard only for postgis.net/docs/ST_Equals.html. Therefore how `=` deals with geometries may vary in different libraries and databases. Commented May 2 at 5:46
• @user2856 That's indeed a lot more elegant! Thanks! Commented May 2 at 7:29
• @JGH `"The equals operator checks if the geometries are exactly the same.": out of curiosity, is there a reference or have you found this via deduction?` Deduction... Commented May 2 at 7:30