JTS has a number of different equals methods for comparing Geometry objects. If you are doing a lot of comparisons with large, complex Geometry objects it’s important to understand the differences between these methods to get the best runtime performance in your application.
If this page looks long and scary, the important bit is to always avoid using Geometry.equals( Geometry g ) in your code. Use equalsExact or equalsTopo instead.
This method frees you from the vertex order problem mentioned above by normalizing the Geometry objects (ie. putting each into a standard or canonical form), before comparison. It is equivalent to:
geomA.normalize(); geomB.normalize(); boolean result = geomA.equalsExact( geomB );
Vertex order will is guaranteed to be the same, but the price is additional computation which, for complex Geometry objects, can be expensive.
This method is a synonym for Geometry.equalsTopo. It should really come with a health warning because its presence means that you can unknowingly be doing computationally expensive comparisons when quick cheap ones are all you need. For example:
Geometry geomA = ... Geometry geomB = ... // If geomA and geomB are complex, this will be slow: boolean result = geomA.equals( geomB ); // If you know that a structural comparison is all you need, do // this instead: result = geomA.equalsExact( geomB );
The best thing approach you can take with this method is vow never to use it.