Problem description
The SDO_GEOMETRY(WKT, SRID) constructor does not preserve the explicitly supplied OGC geometry type when the input is a MULTIPOLYGON containing one Polygon.
The constructor returns an SDO_GEOMETRY with SDO_GTYPE=2003. Its WKT and WKB representations are also Polygon rather than MultiPolygon.
Oracle’s documentation distinguishes Polygon (SDO_GTYPE=2003) from MultiPolygon (SDO_GTYPE=2007) and does not document this constructor normalization.
Reproduction
WITH test_geometry AS (
SELECT SDO_GEOMETRY(
'MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)))',
4326
) geom
FROM dual
)
SELECT
t.geom.SDO_GTYPE,
SDO_UTIL.GETNUMELEM(t.geom) AS element_count,
SDO_UTIL.TO_WKTGEOMETRY(t.geom) AS output_wkt,
RAWTOHEX(
DBMS_LOB.SUBSTR(
SDO_UTIL.TO_WKBGEOMETRY(t.geom),
5,
1
)
) AS wkb_header
FROM test_geometry t;
Expected result
SDO_GTYPE: 2007
Element count: 1
WKT: MULTIPOLYGON (((0.0 0.0, ...)))
WKB type: 6
Actual result
SDO_GTYPE: 2003
Element count: 1
WKT: POLYGON ((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0))
WKB header: 0000000003
Impact
- Failures when code retrieves the geometry and appends additional Polygon members.
We noticed this in the Django project with failing test suite against 23.9. We're trying to evaluate if we should provide a workaround.