Hello everyone,

It has come to my attention that Apache Sedona currently supports creating
geometry collections of any kind (Geometry Collection, MultiPolygon,
MultiPoint, MultiLineString) that has underlying geometries of different
dimensions.
For example, it is possible to create a MultiPolygon that has an empty
polygon, a 2D and a 3D polygon.

This can lead to bugs in ST functions that assume the geometry to be 2D/3D
depending on availability of z ordinate in the first coordinate (accessed
by geometry.getCoordinate()).
For example, consider the implementation of ST_GeometricMedian, which uses
a function `extractCoordinates()` to retrieve all coordinates of the
geometry. Here is the implementation of `extractCoordinates()`:

private static Coordinate[] extractCoordinates(Geometry geometry) {
    Coordinate[] points = geometry.getCoordinates();
    if(points.length == 0)
        return points;

    Coordinate[] coordinates = new Coordinate[points.length];
    for(int i = 0; i < points.length; i++) {
        boolean is3d = !Double.isNaN(points[i].z);
        coordinates[i] = points[i].copy();
        if(!is3d)
            coordinates[i].z = 0.0;
    }
    return coordinates;
}



This code assumes the dimension of geometry based on its first
coordinate, and if the geometry is deemed to be 2D, it forces all z
ordinates of all coordinates to be 0.
Hence if a geometry collection with a 2D geometry at the first
position is provided, all z ordinates of any following 3D geometry is
coerced to be 0.

On the contrary, PostGIS does not allow creation of such hybrid
geometries and stops this flow in the geometry constructor itself,
which seems like something Apache Sedona should have too.
I have created a JIRA
<https://issues.apache.org/jira/browse/SEDONA-305> tracking this,
please feel free to use this email thread to discuss how this solution
should be implemented.

[image: Screenshot 2023-06-20 at 12.21.38 PM.png]
^^ P.S. This is how PostGIS behaves for such a construction.


Best,
Nilesh Gajwani

Reply via email to