Skip to content
Permalink
Browse files

Merge pull request #33976 from troopa81/backport_fix_from_33629_to_re…

…lease_310

[Backport 3.10] Fixes for Oracle curves and surfaces support
  • Loading branch information
rouault committed Mar 11, 2020
2 parents 4ed2c48 + f8cf040 commit 4e0a355981791983e4171a72be77416e0b6b5bcc
@@ -2409,10 +2409,10 @@ QOCISpatialCols::CurveParts QOCISpatialCols::getCurveParts( int &iElem, const QV
// CompoundCurve
baseType = WKBCompoundCurve;
int compoundParts = n;
iElem += 3;
CurveParts parts;
for ( int k = 0; k < compoundParts; k += 1, iElem += 3 )
for ( int k = 0; k < compoundParts; k += 1 )
{
iElem += 3;
if ( !getElemInfoElem( iElem, vElems, nOrds, startOffset, endOffset, etype, n ) )
{
qWarning() << "could not fetch element info" << iElem;
@@ -2960,11 +2960,11 @@ bool QOCISpatialCols::convertToWkb( QVariant &v, int index )
isCurved = true;
isCompoundCurve = true;
int compoundParts = n;
i += 3;
currentPartWkbType = WKBCurvePolygon;
currentPartWkbType = ( nDims == 2 ? WKBCurvePolygon : WKBCurvePolygonZ );
CurveParts parts;
for ( int k = 0; k < compoundParts; k += 1, i += 3 )
for ( int k = 0; k < compoundParts; k += 1 )
{
i += 3;
if ( !getElemInfoElem( i, elems, nOrds, startOffset, endOffset, etype, n ) )
{
qWarning() << "could not fetch element info" << i;
@@ -2973,7 +2973,9 @@ bool QOCISpatialCols::convertToWkb( QVariant &v, int index )

if ( etype == 2 && ( n == 1 || n == 2 ) )
{
WKBType partType = ( n == 1 ) ? WKBLineString : WKBCircularString;
WKBType partType = ( n == 1 ) ?
( nDims == 2 ? WKBLineString : WKBLineString25D ) :
( nDims == 2 ? WKBCircularString : WKBCircularStringZ );
PointSequence points;
points.reserve( 1 + ( endOffset - startOffset ) / nDims );
for ( int j = startOffset; j < endOffset; j += nDims )
@@ -3006,10 +3008,11 @@ bool QOCISpatialCols::convertToWkb( QVariant &v, int index )

int wkbSize = 1 + 2 * sizeof( int );
const int nPolygons = parts.size();
const bool isMultiPolygon = iType == GtMultiPolygon;
for ( int part = 0; part < nPolygons; ++part )
{
SurfaceRings &rings = parts[ part ].second;
if ( nPolygons > 1 )
if ( isMultiPolygon )
wkbSize += 1 + 2 * sizeof( int );
for ( int ringIdx = 0; ringIdx < rings.size(); ++ringIdx )
{
@@ -3039,7 +3042,8 @@ bool QOCISpatialCols::convertToWkb( QVariant &v, int index )

ptr.cPtr = ba.data();
*ptr.ucPtr++ = byteorder();
if ( nPolygons == 1 )

if ( !isMultiPolygon )
{
if ( isCurved )
*ptr.iPtr++ = nDims == 2 ? WKBCurvePolygon : WKBCurvePolygonZ;
@@ -3057,7 +3061,7 @@ bool QOCISpatialCols::convertToWkb( QVariant &v, int index )

for ( const QPair< WKBType, SurfaceRings > &rings : qAsConst( parts ) )
{
if ( nPolygons > 1 )
if ( isMultiPolygon )
{
*ptr.ucPtr++ = byteorder();
*ptr.iPtr++ = rings.first;
@@ -255,7 +255,7 @@ def testCurves(self):
self.assertTrue(
compareWkt(features[7].geometry().asWkt(), 'MultiCurve (CircularString (1 2, 5 4, 7 2.2, 10 0.1, 13 4),CircularString (-11 -3, 5 7, 10 -1))', 0.00001), features[7].geometry().asWkt())
self.assertTrue(
compareWkt(features[8].geometry().asWkt(), 'MultiCurve (CompoundCurve ((-1 -5, 1 2),CircularString (1 2, 5 4, 7 2.2, 10 0.1, 13 4),(13 4, 17 -6)),CompoundCurve (CircularString (1 2, 5 4, 7 2.2, 10 0.1, 13 4)),CompoundCurve ((-11 -3, 5 7, 10 -1)))', 0.00001), features[8].geometry().asWkt())
compareWkt(features[8].geometry().asWkt(), 'MultiCurve (CompoundCurve ((-1 -5, 1 2),CircularString (1 2, 5 4, 7 2.2, 10 0.1, 13 4),(13 4, 17 -6)),CompoundCurve (CircularString (1 3, 5 5, 7 3.2, 10 1.1, 13 5)),CompoundCurve ((-11 -3, 5 7, 10 -1)))', 0.00001), features[8].geometry().asWkt())

def testSurfaces(self):
vl = QgsVectorLayer('%s table="QGIS"."POLY_DATA" (GEOM) srid=4326 type=POLYGON sql=' %
@@ -285,6 +285,12 @@ def testSurfaces(self):
compareWkt(features[11].geometry().asWkt(), 'CurvePolygon(CompoundCurve ((-1 -5, 1 2),CircularString (1 2, 5 4, 7 2.20, 10 0.1, 13 4),(13 4, 17 -6),CircularString (17 -6, 5 -7, -1 -5)))', 0.00001), features[11].geometry().asWkt())
self.assertTrue(
compareWkt(features[12].geometry().asWkt(), 'MultiSurface (CurvePolygon (CircularString (1 3, 3 5, 4 7, 7 3, 1 3)),CurvePolygon (CircularString (11 3, 13 5, 14 7, 17 3, 11 3)))', 0.00001), features[12].geometry().asWkt())
self.assertTrue(
compareWkt(features[13].geometry().asWkt(), 'CurvePolygonZ(CompoundCurveZ (CircularStringZ (-1 -5 1, 5 -7 2, 17 -6 3), (17 -6 3, 13 4 4), CircularStringZ (13 4 4, 10 0.1 5, 7 2.20 6, 5 4 7, 1 2 8),(1 2 8, -1 -5 1)))', 0.00001), features[13].geometry().asWkt())
self.assertTrue(
compareWkt(features[14].geometry().asWkt(), 'MultiPolygon (((22 22, 28 22, 28 26, 22 26, 22 22)))', 0.00001), features[14].geometry().asWkt())
self.assertTrue(
compareWkt(features[15].geometry().asWkt(), 'MultiSurface (CurvePolygon(CompoundCurve (CircularString (-1 -5, 5 -7, 17 -6), (17 -6, -1 -5))), CurvePolygon (CircularString (1 3, 7 3, 4 7, 3 5, 1 3)))', 0.00001), features[15].geometry().asWkt())

def testNestedInsert(self):
tg = QgsTransactionGroup()
@@ -37,14 +37,14 @@ INSERT INTO QGIS.POINT_DATA ("pk", GEOM)

CREATE TABLE QGIS.LINE_DATA ( "pk" INTEGER PRIMARY KEY, GEOM SDO_GEOMETRY);
INSERT INTO QGIS.LINE_DATA ("pk", GEOM)
SELECT 1, SDO_GEOMETRY( 2002,4326,NULL, SDO_ELEM_INFO_ARRAY(1,2,1), SDO_ORDINATE_ARRAY(1,2,3,4,5,6)) from dual
UNION ALL SELECT 2, SDO_GEOMETRY(2002,4326,NULL, SDO_ELEM_INFO_ARRAY(1, 2, 2), SDO_ORDINATE_ARRAY(1, 2, 5, 4, 7, 2.2, 10, .1, 13, 4)) from dual
UNION ALL SELECT 3, SDO_GEOMETRY(2002,4326,NULL, SDO_ELEM_INFO_ARRAY(1,4,3, 1,2,1, 3,2,2, 11,2,1), SDO_ORDINATE_ARRAY(-1, -5, 1, 2, 5, 4, 7, 2.2, 10, 0.1, 13, 4, 17, -6.)) from dual
UNION ALL SELECT 4, SDO_GEOMETRY(3002,4326,NULL, SDO_ELEM_INFO_ARRAY(1,2,1), SDO_ORDINATE_ARRAY(1,2,3,4,5,6,7,8,9)) from dual
UNION ALL SELECT 5, SDO_GEOMETRY(2006,4326,NULL, SDO_ELEM_INFO_ARRAY(1,2,1, 5,2,1), SDO_ORDINATE_ARRAY(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) from dual
UNION ALL SELECT 6, SDO_GEOMETRY(3006,4326,NULL, SDO_ELEM_INFO_ARRAY(1,2,1, 7,2,1), SDO_ORDINATE_ARRAY(1, 2, 11, 3, 4, -11, 5, 6, 9, 7, 8, 1, 9, 10, -3)) from dual
UNION ALL SELECT 7, SDO_GEOMETRY(2006,4326,NULL, SDO_ELEM_INFO_ARRAY(1,2,2, 11,2,2), SDO_ORDINATE_ARRAY(1, 2, 5, 4, 7, 2.2, 10, .1, 13, 4, -11, -3, 5, 7, 10, -1)) from dual
UNION ALL SELECT 8, SDO_GEOMETRY(2006,4326,NULL, SDO_ELEM_INFO_ARRAY(1,4,3, 1,2,1, 3,2,2, 11,2,1, 15,4,1, 15,2,2, 25,4,1, 25,2,1), SDO_ORDINATE_ARRAY(-1, -5, 1, 2, 5, 4, 7, 2.2, 10, .1, 13, 4, 17, -6, 1, 2, 5, 4, 7, 2.2, 10, .1, 13, 4, -11, -3, 5, 7, 10, -1)) from dual;
SELECT 1, SDO_GEOMETRY( 2002,3857,NULL, SDO_ELEM_INFO_ARRAY(1,2,1), SDO_ORDINATE_ARRAY(1,2,3,4,5,6)) from dual
UNION ALL SELECT 2, SDO_GEOMETRY(2002,3857,NULL, SDO_ELEM_INFO_ARRAY(1, 2, 2), SDO_ORDINATE_ARRAY(1, 2, 5, 4, 7, 2.2, 10, .1, 13, 4)) from dual
UNION ALL SELECT 3, SDO_GEOMETRY(2002,3857,NULL, SDO_ELEM_INFO_ARRAY(1,4,3, 1,2,1, 3,2,2, 11,2,1), SDO_ORDINATE_ARRAY(-1, -5, 1, 2, 5, 4, 7, 2.2, 10, 0.1, 13, 4, 17, -6.)) from dual
UNION ALL SELECT 4, SDO_GEOMETRY(3002,3857,NULL, SDO_ELEM_INFO_ARRAY(1,2,1), SDO_ORDINATE_ARRAY(1,2,3,4,5,6,7,8,9)) from dual
UNION ALL SELECT 5, SDO_GEOMETRY(2006,3857,NULL, SDO_ELEM_INFO_ARRAY(1,2,1, 5,2,1), SDO_ORDINATE_ARRAY(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) from dual
UNION ALL SELECT 6, SDO_GEOMETRY(3006,3857,NULL, SDO_ELEM_INFO_ARRAY(1,2,1, 7,2,1), SDO_ORDINATE_ARRAY(1, 2, 11, 3, 4, -11, 5, 6, 9, 7, 8, 1, 9, 10, -3)) from dual
UNION ALL SELECT 7, SDO_GEOMETRY(2006,3857,NULL, SDO_ELEM_INFO_ARRAY(1,2,2, 11,2,2), SDO_ORDINATE_ARRAY(1, 2, 5, 4, 7, 2.2, 10, .1, 13, 4, -11, -3, 5, 7, 10, -1)) from dual
UNION ALL SELECT 8, SDO_GEOMETRY(2006,3857,NULL, SDO_ELEM_INFO_ARRAY(1,4,3, 1,2,1, 3,2,2, 11,2,1, 15,2,2, 25,2,1), SDO_ORDINATE_ARRAY(-1, -5, 1, 2, 5, 4, 7, 2.2, 10, .1, 13, 4, 17, -6, 1, 3, 5, 5, 7, 3.2, 10, 1.1, 13, 5, -11, -3, 5, 7, 10, -1)) from dual;

CREATE TABLE QGIS.POLY_DATA ( "pk" INTEGER PRIMARY KEY, GEOM SDO_GEOMETRY);
INSERT INTO QGIS.POLY_DATA ("pk", GEOM)
@@ -59,11 +59,13 @@ INSERT INTO QGIS.POLY_DATA ("pk", GEOM)
UNION ALL SELECT 9, SDO_GEOMETRY(2003,4326,NULL, SDO_ELEM_INFO_ARRAY(1,1003,2), SDO_ORDINATE_ARRAY(1, 3, 3, 5, 4, 7, 7, 3, 1, 3)) from dual
UNION ALL SELECT 10, SDO_GEOMETRY(2003, NULL, NULL, SDO_ELEM_INFO_ARRAY(1,1003,2, 11,2003,2), SDO_ORDINATE_ARRAY(1, 3, 3, 5, 4, 7, 7, 3, 1, 3, 3.1, 3.3, 3.3, 3.5, 3.4, 3.7, 3.7, 3.3, 3.1, 3.3)) from dual
UNION ALL SELECT 11, SDO_GEOMETRY(2003, NULL, NULL, SDO_ELEM_INFO_ARRAY(1,1005,4, 1,2,1, 3,2,2, 11,2,1, 13,2,2), SDO_ORDINATE_ARRAY(-1, -5, 1, 2, 5, 4, 7, 2.2, 10, .1, 13, 4, 17, -6, 5, -7, -1, -5)) from dual
UNION ALL SELECT 12, SDO_GEOMETRY(2007, NULL, NULL, SDO_ELEM_INFO_ARRAY(1,1003,2, 11,1003,2), SDO_ORDINATE_ARRAY(1, 3, 3, 5, 4, 7, 7, 3, 1, 3, 11, 3, 13, 5, 14, 7, 17, 3, 11, 3)) from dual;
UNION ALL SELECT 12, SDO_GEOMETRY(2007, NULL, NULL, SDO_ELEM_INFO_ARRAY(1,1003,2, 11,1003,2), SDO_ORDINATE_ARRAY(1, 3, 3, 5, 4, 7, 7, 3, 1, 3, 11, 3, 13, 5, 14, 7, 17, 3, 11, 3)) from dual
UNION ALL SELECT 13, SDO_GEOMETRY(3003, 5698, NULL, SDO_ELEM_INFO_ARRAY(1, 1005, 4, 1, 2, 2, 7, 2, 1, 10, 2, 2, 22, 2, 1), SDO_ORDINATE_ARRAY(-1, -5, 1, 5, -7, 2, 17, -6, 3, 13, 4, 4, 10, .1, 5, 7, 2.2, 6, 5, 4, 7, 1, 2, 8, -1, -5, 1)) from dual
UNION ALL SELECT 14, SDO_GEOMETRY(2007, 3857, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_ARRAY(22, 22, 28, 22, 28, 26, 22, 26, 22, 22)) from dual
UNION ALL SELECT 15, SDO_GEOMETRY(2007, 3857, NULL, SDO_ELEM_INFO_ARRAY(1, 1005, 2, 1, 2, 2, 5, 2, 1, 9, 1003, 2), SDO_ORDINATE_ARRAY(-1, -5, 5, -7, 17, -6, -1, -5, 1, 3, 7, 3, 4, 7, 3, 5, 1, 3)) from dual;

CREATE TABLE QGIS.DATE_TIMES ( "id" INTEGER PRIMARY KEY, "date_field" DATE, "datetime_field" TIMESTAMP );

INSERT INTO QGIS.DATE_TIMES ("id", "date_field", "datetime_field" ) VALUES (1, DATE '2004-03-04', TIMESTAMP '2004-03-04 13:41:52' );

COMMIT;

0 comments on commit 4e0a355

Please sign in to comment.
You can’t perform that action at this time.