Skip to content

Commit

Permalink
[spatialite provider] further zm support fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Dec 11, 2017
1 parent e0aa5e1 commit 8302fc3
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 106 deletions.
230 changes: 125 additions & 105 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -1122,7 +1122,7 @@ QgsFeatureIterator QgsSpatiaLiteProvider::getFeatures( const QgsFeatureRequest &




int QgsSpatiaLiteProvider::computeSizeFromGeosWKB2D( const unsigned char *blob, int QgsSpatiaLiteProvider::computeSizeFromGeosWKB2D( const unsigned char *blob,
int size, int type, int nDims, int size, QgsWkbTypes::Type type, int nDims,
int little_endian, int endian_arch ) int little_endian, int endian_arch )
{ {
Q_UNUSED( size ); Q_UNUSED( size );
Expand All @@ -1133,49 +1133,33 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB2D( const unsigned char *blob,
const unsigned char *p_in = blob + 5; const unsigned char *p_in = blob + 5;
int gsize = 5; int gsize = 5;


switch ( type ) if ( QgsWkbTypes::isMultiType( type ) )
{ {
// compunting the required size gsize += computeSizeFromMultiWKB2D( p_in, nDims, little_endian,
case GAIA_POINT: endian_arch );
switch ( nDims ) }
{ else
case GAIA_XY_Z_M: {
gsize += 4 * sizeof( double ); switch ( QgsWkbTypes::geometryType( type ) )
break; {
case GAIA_XY_M: // compunting the required size
case GAIA_XY_Z: case QgsWkbTypes::PointGeometry:
gsize += 3 * sizeof( double ); switch ( nDims )
break; {
default: case GAIA_XY_Z_M:
gsize += 2 * sizeof( double ); gsize += 4 * sizeof( double );
break; break;
} case GAIA_XY_M:
break; case GAIA_XY_Z:
case GAIA_LINESTRING: gsize += 3 * sizeof( double );
points = gaiaImport32( p_in, little_endian, endian_arch ); break;
gsize += 4; default:
switch ( nDims ) gsize += 2 * sizeof( double );
{ break;
case GAIA_XY_Z_M: }
gsize += points * ( 4 * sizeof( double ) ); break;
break; case QgsWkbTypes::LineGeometry:
case GAIA_XY_M:
case GAIA_XY_Z:
gsize += points * ( 3 * sizeof( double ) );
break;
default:
gsize += points * ( 2 * sizeof( double ) );
break;
}
break;
case GAIA_POLYGON:
rings = gaiaImport32( p_in, little_endian, endian_arch );
p_in += 4;
gsize += 4;
for ( ib = 0; ib < rings; ib++ )
{
points = gaiaImport32( p_in, little_endian, endian_arch ); points = gaiaImport32( p_in, little_endian, endian_arch );
p_in += 4;
gsize += 4; gsize += 4;
switch ( nDims ) switch ( nDims )
{ {
Expand All @@ -1190,13 +1174,33 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB2D( const unsigned char *blob,
gsize += points * ( 2 * sizeof( double ) ); gsize += points * ( 2 * sizeof( double ) );
break; break;
} }
p_in += points * ( 2 * sizeof( double ) ); break;
} case QgsWkbTypes::PolygonGeometry:
break; rings = gaiaImport32( p_in, little_endian, endian_arch );
default: p_in += 4;
gsize += computeSizeFromMultiWKB2D( p_in, nDims, little_endian, gsize += 4;
endian_arch ); for ( ib = 0; ib < rings; ib++ )
break; {
points = gaiaImport32( p_in, little_endian, endian_arch );
p_in += 4;
gsize += 4;
switch ( nDims )
{
case GAIA_XY_Z_M:
gsize += points * ( 4 * sizeof( double ) );
break;
case GAIA_XY_M:
case GAIA_XY_Z:
gsize += points * ( 3 * sizeof( double ) );
break;
default:
gsize += points * ( 2 * sizeof( double ) );
break;
}
p_in += points * ( 2 * sizeof( double ) );
}
break;
}
} }


return gsize; return gsize;
Expand Down Expand Up @@ -1232,16 +1236,18 @@ int QgsSpatiaLiteProvider::computeSizeFromMultiWKB2D( const unsigned char *p_in,
{ {
case GAIA_XY_Z_M: case GAIA_XY_Z_M:
size += 4 * sizeof( double ); size += 4 * sizeof( double );
p_in += 4 * sizeof( double );
break; break;
case GAIA_XY_Z: case GAIA_XY_Z:
case GAIA_XY_M: case GAIA_XY_M:
size += 3 * sizeof( double ); size += 3 * sizeof( double );
p_in += 3 * sizeof( double );
break; break;
default: default:
size += 2 * sizeof( double ); size += 2 * sizeof( double );
p_in += 2 * sizeof( double );
break; break;
} }
p_in += 2 * sizeof( double );
break; break;
case GAIA_LINESTRING: case GAIA_LINESTRING:
points = gaiaImport32( p_in, little_endian, endian_arch ); points = gaiaImport32( p_in, little_endian, endian_arch );
Expand All @@ -1251,16 +1257,18 @@ int QgsSpatiaLiteProvider::computeSizeFromMultiWKB2D( const unsigned char *p_in,
{ {
case GAIA_XY_Z_M: case GAIA_XY_Z_M:
size += points * ( 4 * sizeof( double ) ); size += points * ( 4 * sizeof( double ) );
p_in += points * ( 4 * sizeof( double ) );
break; break;
case GAIA_XY_Z: case GAIA_XY_Z:
case GAIA_XY_M: case GAIA_XY_M:
size += points * ( 3 * sizeof( double ) ); size += points * ( 3 * sizeof( double ) );
p_in += points * ( 3 * sizeof( double ) );
break; break;
default: default:
size += points * ( 2 * sizeof( double ) ); size += points * ( 2 * sizeof( double ) );
p_in += points * ( 2 * sizeof( double ) );
break; break;
} }
p_in += points * ( 2 * sizeof( double ) );
break; break;
case GAIA_POLYGON: case GAIA_POLYGON:
rings = gaiaImport32( p_in, little_endian, endian_arch ); rings = gaiaImport32( p_in, little_endian, endian_arch );
Expand All @@ -1275,16 +1283,18 @@ int QgsSpatiaLiteProvider::computeSizeFromMultiWKB2D( const unsigned char *p_in,
{ {
case GAIA_XY_Z_M: case GAIA_XY_Z_M:
size += points * ( 4 * sizeof( double ) ); size += points * ( 4 * sizeof( double ) );
p_in += points * ( 4 * sizeof( double ) );
break; break;
case GAIA_XY_Z: case GAIA_XY_Z:
case GAIA_XY_M: case GAIA_XY_M:
size += points * ( 3 * sizeof( double ) ); size += points * ( 3 * sizeof( double ) );
p_in += points * ( 3 * sizeof( double ) );
break; break;
default: default:
size += points * ( 2 * sizeof( double ) ); size += points * ( 2 * sizeof( double ) );
p_in += points * ( 2 * sizeof( double ) );
break; break;
} }
p_in += points * ( 2 * sizeof( double ) );
} }
break; break;
} }
Expand All @@ -1305,49 +1315,33 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB3D( const unsigned char *blob,
const unsigned char *p_in = blob + 5; const unsigned char *p_in = blob + 5;
int gsize = 5; int gsize = 5;


switch ( QgsWkbTypes::geometryType( type ) ) if ( QgsWkbTypes::isMultiType( type ) )
{ {
// compunting the required size gsize += computeSizeFromMultiWKB3D( p_in, nDims, little_endian,
case QgsWkbTypes::PointGeometry: endian_arch );
switch ( nDims ) }
{ else
case GAIA_XY_Z_M: {
gsize += 4 * sizeof( double ); switch ( QgsWkbTypes::geometryType( type ) )
break; {
case GAIA_XY_M: // compunting the required size
case GAIA_XY_Z: case QgsWkbTypes::PointGeometry:
gsize += 3 * sizeof( double ); switch ( nDims )
break; {
default: case GAIA_XY_Z_M:
gsize += 2 * sizeof( double ); gsize += 4 * sizeof( double );
break; break;
} case GAIA_XY_M:
break; case GAIA_XY_Z:
case QgsWkbTypes::LineGeometry: gsize += 3 * sizeof( double );
points = gaiaImport32( p_in, little_endian, endian_arch ); break;
gsize += 4; default:
switch ( nDims ) gsize += 2 * sizeof( double );
{ break;
case GAIA_XY_Z_M: }
gsize += points * ( 4 * sizeof( double ) ); break;
break; case QgsWkbTypes::LineGeometry:
case GAIA_XY_M:
case GAIA_XY_Z:
gsize += points * ( 3 * sizeof( double ) );
break;
default:
gsize += points * ( 2 * sizeof( double ) );
break;
}
break;
case QgsWkbTypes::PolygonGeometry:
rings = gaiaImport32( p_in, little_endian, endian_arch );
p_in += 4;
gsize += 4;
for ( ib = 0; ib < rings; ib++ )
{
points = gaiaImport32( p_in, little_endian, endian_arch ); points = gaiaImport32( p_in, little_endian, endian_arch );
p_in += 4;
gsize += 4; gsize += 4;
switch ( nDims ) switch ( nDims )
{ {
Expand All @@ -1362,13 +1356,33 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB3D( const unsigned char *blob,
gsize += points * ( 2 * sizeof( double ) ); gsize += points * ( 2 * sizeof( double ) );
break; break;
} }
p_in += points * ( 3 * sizeof( double ) ); break;
} case QgsWkbTypes::PolygonGeometry:
break; rings = gaiaImport32( p_in, little_endian, endian_arch );
default: p_in += 4;
gsize += computeSizeFromMultiWKB3D( p_in, nDims, little_endian, gsize += 4;
endian_arch ); for ( ib = 0; ib < rings; ib++ )
break; {
points = gaiaImport32( p_in, little_endian, endian_arch );
p_in += 4;
gsize += 4;
switch ( nDims )
{
case GAIA_XY_Z_M:
gsize += points * ( 4 * sizeof( double ) );
break;
case GAIA_XY_M:
case GAIA_XY_Z:
gsize += points * ( 3 * sizeof( double ) );
break;
default:
gsize += points * ( 2 * sizeof( double ) );
break;
}
p_in += points * ( 3 * sizeof( double ) );
}
break;
}
} }


return gsize; return gsize;
Expand Down Expand Up @@ -1404,16 +1418,18 @@ int QgsSpatiaLiteProvider::computeSizeFromMultiWKB3D( const unsigned char *p_in,
{ {
case GAIA_XY_Z_M: case GAIA_XY_Z_M:
size += 4 * sizeof( double ); size += 4 * sizeof( double );
p_in += 4 * sizeof( double );
break; break;
case GAIA_XY_Z: case GAIA_XY_Z:
case GAIA_XY_M: case GAIA_XY_M:
size += 3 * sizeof( double ); size += 3 * sizeof( double );
p_in += 3 * sizeof( double );
break; break;
default: default:
size += 2 * sizeof( double ); size += 2 * sizeof( double );
p_in += 2 * sizeof( double );
break; break;
} }
p_in += 3 * sizeof( double );
break; break;
case QgsWkbTypes::LineGeometry: case QgsWkbTypes::LineGeometry:
points = gaiaImport32( p_in, little_endian, endian_arch ); points = gaiaImport32( p_in, little_endian, endian_arch );
Expand All @@ -1423,16 +1439,18 @@ int QgsSpatiaLiteProvider::computeSizeFromMultiWKB3D( const unsigned char *p_in,
{ {
case GAIA_XY_Z_M: case GAIA_XY_Z_M:
size += points * ( 4 * sizeof( double ) ); size += points * ( 4 * sizeof( double ) );
p_in += points * ( 4 * sizeof( double ) );
break; break;
case GAIA_XY_Z: case GAIA_XY_Z:
case GAIA_XY_M: case GAIA_XY_M:
size += points * ( 3 * sizeof( double ) ); size += points * ( 3 * sizeof( double ) );
p_in += points * ( 3 * sizeof( double ) );
break; break;
default: default:
size += points * ( 2 * sizeof( double ) ); size += points * ( 2 * sizeof( double ) );
p_in += points * ( 2 * sizeof( double ) );
break; break;
} }
p_in += points * ( 3 * sizeof( double ) );
break; break;
case QgsWkbTypes::PolygonGeometry: case QgsWkbTypes::PolygonGeometry:
rings = gaiaImport32( p_in, little_endian, endian_arch ); rings = gaiaImport32( p_in, little_endian, endian_arch );
Expand All @@ -1447,16 +1465,18 @@ int QgsSpatiaLiteProvider::computeSizeFromMultiWKB3D( const unsigned char *p_in,
{ {
case GAIA_XY_Z_M: case GAIA_XY_Z_M:
size += points * ( 4 * sizeof( double ) ); size += points * ( 4 * sizeof( double ) );
p_in += points * ( 4 * sizeof( double ) );
break; break;
case GAIA_XY_Z: case GAIA_XY_Z:
case GAIA_XY_M: case GAIA_XY_M:
size += points * ( 3 * sizeof( double ) ); size += points * ( 3 * sizeof( double ) );
p_in += points * ( 3 * sizeof( double ) );
break; break;
default: default:
size += points * ( 2 * sizeof( double ) ); size += points * ( 2 * sizeof( double ) );
p_in += points * ( 2 * sizeof( double ) );
break; break;
} }
p_in += points * ( 3 * sizeof( double ) );
} }
break; break;
} }
Expand Down Expand Up @@ -1505,7 +1525,7 @@ void QgsSpatiaLiteProvider::convertFromGeosWKB( const unsigned char *blob,
return; return;
} }


// we need creating a GAIA WKB // we need creating a GAIA WKB
if ( gDims == 3 ) if ( gDims == 3 )
gsize = computeSizeFromGeosWKB3D( blob, blob_size, type, nDims, gsize = computeSizeFromGeosWKB3D( blob, blob_size, type, nDims,
little_endian, endian_arch ); little_endian, endian_arch );
Expand Down Expand Up @@ -3183,7 +3203,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB( const unsigned char *blob,
{ {
p_in += 5; p_in += 5;
*p_out++ = 0x01; *p_out++ = 0x01;
gaiaExport32( p_out, type == GAIA_MULTIPOLYGONZ ? QgsWkbTypes::Polygon25D : QgsWkbTypes::PolygonZM, 1, endian_arch ); gaiaExport32( p_out, type == GAIA_MULTIPOLYGONZ ? QgsWkbTypes::Polygon25D : QgsWkbTypes::PolygonM, 1, endian_arch );
p_out += 4; p_out += 4;
rings = gaiaImport32( p_in, little_endian, endian_arch ); rings = gaiaImport32( p_in, little_endian, endian_arch );
p_in += 4; p_in += 4;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/spatialite/qgsspatialiteprovider.h
Expand Up @@ -361,7 +361,7 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider
QgsWkbTypes::Type type, int nDims, int little_endian, QgsWkbTypes::Type type, int nDims, int little_endian,
int endian_arch ); int endian_arch );
int computeSizeFromGeosWKB2D( const unsigned char *blob, int size, int computeSizeFromGeosWKB2D( const unsigned char *blob, int size,
int type, int nDims, int little_endian, QgsWkbTypes::Type type, int nDims, int little_endian,
int endian_arch ); int endian_arch );


void fetchConstraints(); void fetchConstraints();
Expand Down

0 comments on commit 8302fc3

Please sign in to comment.