OtterMind/Chat2DB · info · IllegalArgumentException

EWKB collection contains mixed coordinate dimensions

Error message

EWKB collection contains mixed coordinate dimensions

What it means

Thrown by PostgreSQLGeometryProcessor.inspectChildren when a child geometry's coordinate dimension flags (hasZ, hasMeasure) differ from the parent collection's. All children in a collection must share the same Z and M dimensionality as the parent. The check at line 285 compares child.hasZ() to parent.hasZ() and child.hasMeasure() to parent.hasMeasure(). The exception is caught by convertJDBCValueByType at line 80 and the raw hex value is returned gracefully.

Source

Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/value/sub/PostgreSQLGeometryProcessor.java:286

            coordinate[i] = cursor.readDouble(byteOrder);
            if (!Double.isFinite(coordinate[i])) {
                throw new IllegalArgumentException("EWKB coordinate is not finite");
            }
        }
        return coordinate;
    }

    private void inspectChildren(WkbCursor cursor, ByteOrder byteOrder, WkbHeader parent,
                                 Integer inheritedSrid, int expectedType, int depth) {
        int childCount = readCount(cursor, byteOrder);
        Integer effectiveSrid = parent.srid() != null ? parent.srid() : inheritedSrid;
        for (int i = 0; i < childCount; i++) {
            WkbHeader child = inspectGeometry(cursor, effectiveSrid, false, depth + 1);
            if (expectedType != 0 && child.baseType() != expectedType) {
                throw new IllegalArgumentException("EWKB collection contains an unexpected geometry type");
            }
            if (child.hasZ() != parent.hasZ() || child.hasMeasure() != parent.hasMeasure()) {
                throw new IllegalArgumentException("EWKB collection contains mixed coordinate dimensions");
            }
        }
    }

    private int readCount(WkbCursor cursor, ByteOrder byteOrder) {
        int count = cursor.readInt(byteOrder);
        if (count < 0) {
            throw new IllegalArgumentException("EWKB contains a negative element count");
        }
        return count;
    }

    private ByteOrder readByteOrder(WkbCursor cursor) {
        int byteOrder = cursor.readUnsignedByte();
        if (byteOrder == 0) {
            return ByteOrder.BIG_ENDIAN;
        }
        if (byteOrder == 1) {

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. No action required in production — convertJDBCValueByType catches this and returns the raw hex value
  2. Rebuild the collection so all children share the parent's Z and M flags
  3. Use ST_Force3D or ST_Force2D in PostgreSQL to normalize all children to the same dimensionality

Example fix

-- before: MULTILINESTRING mixing 2D and 3D children (invalid)
-- after: consistent Z across all children
SELECT ST_GeomFromEWKT('MULTILINESTRING((0 0 1, 1 1 2), (2 2 3, 3 3 4))');
Defensive patterns

Strategy: try-catch

Validate before calling

// Already caught in convertJDBCValueByType. For data-level validation:
// Use ST_Force3D / ST_Force2D to normalize all children to consistent dimensions.
// SELECT ST_AsEWKT(ST_Force3D(geom)) FROM my_table;

Try / catch

try {
    inspectChildren(cursor, byteOrder, header, srid, expectedType, depth);
} catch (IllegalArgumentException e) {
    log.debug("EWKB mixed dimensions", e);
    return value;
}

Prevention

When it happens

Trigger: Converting a collection geometry (baseType 4-7) where one or more children declare different Z or M dimension flags than the parent. For example, a MULTILINESTRING with hasZ=true containing a child LINESTRING with hasZ=false.

Common situations: Collections assembled from geometries created with different dimension settings; data produced by a tool that does not enforce consistent dimensionality across collection members; EWKB from mixed PostGIS versions.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/10f154f67a9bab50. Report an issue: GitHub.