#40 Geometry.equals ignore Z value

v1.0 (example)
equals (1) 3d (1)

JTS version 1.13

Do you expect this test to be true ?

WKTReader wktReader = new WKTReader();
Geometry poly2D = wktReader.read("POLYGON ((67 13 , 67 18, 59 18, 59 13, 67 13 ))");
Geometry poly3d = wktReader.read("POLYGON ((67 13 , 67 18 5, 59 18, 59 13, 67 13 ))");
poly2D.equals(poly3D) == True

Even with a Z value in poly 3d JTS says it is the same object..

Discussion about this here also:

Thanks for support

-Nicolas Fortin
Atelier SIG


  • Dr JTS

    Dr JTS - 2013-08-20

    Yes, it should be true.

    As stated in various places in the docs, JTS is essentially a 2D library. It ignores Z ordinates for the most part.

    The other thing you should be aware of is that equals() is performing a topological equality check, as per the SFS specification. This is NOT what you should use if you want to check if two geometries are pointwise equal (which seems to be your use case). There are various other methods which do this - look at equalsExact or equalsNorm. However, these also do not check for Z values. You may need to write something custom to check this.

  • Noel Grandin

    Noel Grandin - 2013-08-26

    H2 Developer here: Writing something custom is exactly what I don't want to do.

    I really don't want to have to dig into your class hierarchy using instanceof checks and the like in order to implement an equals method.

    It's just very fragile, and means that any change or re-factoring of your hierachy will potentially break our code.


  • CuMu

    CuMu - 2013-10-09

    Ok Thank you, h2 do a WKB binary comparison now, in order to not store duplicate Geometries inside the database (cache system). The ticket can be closed as "not an issue"

    May be update http://tsusiatsoftware.net/jts/jts-links.html#systems in order to add H2 Database, as it now support Geometry type with usage of JTS 1.13


Log in to post a comment.