Skip to content

Commit 171bed7

Browse files
author
esseffe
committed
fixing several issues related to SpatiaLite 3D Geometries
git-svn-id: http://svn.osgeo.org/qgis/trunk@15814 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent f0ca2e3 commit 171bed7

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/core/qgsgeometry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ bool QgsGeometry::moveVertex( double x, double y, int atVertex )
14731473
ptr += 2 * sizeof( double ) * ( vertexnr - pointindex );
14741474
if ( hasZValue )
14751475
{
1476-
ptr += 3 * sizeof( double ) * ( vertexnr - pointindex );
1476+
ptr += sizeof( double ) * ( vertexnr - pointindex );
14771477
}
14781478
memcpy( ptr, &x, sizeof( double ) );
14791479
ptr += sizeof( double );

src/providers/spatialite/qgsspatialiteprovider.cpp

+25-10
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,16 @@ bool QgsSpatiaLiteProvider::featureAtId( int featureId, QgsFeature & feature, bo
402402
{
403403
if ( sqlite3_column_type( stmt, ic ) == SQLITE_BLOB )
404404
{
405+
unsigned char *featureGeom = NULL;
406+
size_t geom_size = 0;
405407
const void *blob = sqlite3_column_blob( stmt, ic );
406408
size_t blob_size = sqlite3_column_bytes( stmt, ic );
407-
unsigned char *featureGeom = new unsigned char[blob_size + 1];
408-
memset( featureGeom, '\0', blob_size + 1 );
409-
memcpy( featureGeom, blob, blob_size );
410-
feature.setGeometryAndOwnership( featureGeom, blob_size + 1 );
409+
convertToGeosWKB ( (const unsigned char *)blob, blob_size,
410+
&featureGeom, &geom_size );
411+
if ( featureGeom )
412+
feature.setGeometryAndOwnership( featureGeom, geom_size );
413+
else
414+
feature.setGeometryAndOwnership( 0, 0 );
411415
}
412416
else
413417
{
@@ -592,6 +596,7 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB2D( const unsigned char *blob,
592596
break;
593597
case GAIA_LINESTRING:
594598
points = gaiaImport32 ( p_in, little_endian, endian_arch );
599+
gsize += 4;
595600
switch ( nDims )
596601
{
597602
case GAIA_XY_Z_M:
@@ -609,10 +614,12 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB2D( const unsigned char *blob,
609614
case GAIA_POLYGON:
610615
rings = gaiaImport32 ( p_in, little_endian, endian_arch );
611616
p_in += 4;
617+
gsize += 4;
612618
for ( ib = 0; ib < rings; ib++ )
613619
{
614620
points = gaiaImport32 ( p_in, little_endian, endian_arch );
615621
p_in += 4;
622+
gsize += 4;
616623
switch ( nDims )
617624
{
618625
case GAIA_XY_Z_M:
@@ -761,6 +768,7 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB3D( const unsigned char *blob,
761768
break;
762769
case GEOS_3D_LINESTRING:
763770
points = gaiaImport32 ( p_in, little_endian, endian_arch );
771+
gsize += 4;
764772
switch ( nDims )
765773
{
766774
case GAIA_XY_Z_M:
@@ -778,10 +786,12 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB3D( const unsigned char *blob,
778786
case GEOS_3D_POLYGON:
779787
rings = gaiaImport32 ( p_in, little_endian, endian_arch );
780788
p_in += 4;
789+
gsize += 4;
781790
for ( ib = 0; ib < rings; ib++ )
782791
{
783792
points = gaiaImport32 ( p_in, little_endian, endian_arch );
784793
p_in += 4;
794+
gsize += 4;
785795
switch ( nDims )
786796
{
787797
case GAIA_XY_Z_M:
@@ -933,7 +943,7 @@ void QgsSpatiaLiteProvider::convertFromGeosWKB ( const unsigned char *blob,
933943
else
934944
return;
935945

936-
if ( gDims == 2 && nDims == 2 )
946+
if ( gDims == 2 && nDims == GAIA_XY )
937947
{
938948
// already 2D: simply copying is required
939949
unsigned char *wkbGeom = new unsigned char[blob_size + 1];
@@ -2148,27 +2158,32 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
21482158
case GAIA_LINESTRINGM:
21492159
case GAIA_LINESTRINGZM:
21502160
points = gaiaImport32 ( p_in, little_endian, endian_arch );
2161+
gsize += 4;
21512162
gsize += points * ( 3 * sizeof(double) );
21522163
break;
21532164
case GAIA_POLYGONZ:
21542165
case GAIA_POLYGONM:
21552166
rings = gaiaImport32 ( p_in, little_endian, endian_arch );
21562167
p_in += 4;
2168+
gsize += 4;
21572169
for ( ib = 0; ib < rings; ib++ )
21582170
{
21592171
points = gaiaImport32 ( p_in, little_endian, endian_arch );
21602172
p_in += 4;
2173+
gsize += 4;
21612174
gsize += points * ( 3 * sizeof(double) );
21622175
p_in += points * ( 3 * sizeof(double) );
21632176
}
21642177
break;
21652178
case GAIA_POLYGONZM:
21662179
rings = gaiaImport32 ( p_in, little_endian, endian_arch );
21672180
p_in += 4;
2181+
gsize += 4;
21682182
for ( ib = 0; ib < rings; ib++ )
21692183
{
21702184
points = gaiaImport32 ( p_in, little_endian, endian_arch );
21712185
p_in += 4;
2186+
gsize += 4;
21722187
gsize += points * ( 3 * sizeof(double) );
21732188
p_in += points * ( 4 * sizeof(double) );
21742189
}
@@ -2473,7 +2488,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
24732488
gaiaExport64 ( p_out, coord, 1, endian_arch ); // Z
24742489
p_in += sizeof(double);
24752490
p_out += sizeof(double);
2476-
if (type == GAIA_LINESTRINGZM)
2491+
if (type == GAIA_MULTILINESTRINGZM)
24772492
p_in += sizeof(double);
24782493
}
24792494
}
@@ -2552,7 +2567,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
25522567
gaiaExport64 ( p_out, coord, 1, endian_arch ); // Z
25532568
p_in += sizeof(double);
25542569
p_out += sizeof(double);
2555-
if (type == GAIA_POLYGONZM)
2570+
if (type == GAIA_MULTIPOLYGONZM)
25562571
p_in += sizeof(double);
25572572
}
25582573
}
@@ -2619,7 +2634,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
26192634
gaiaExport64 ( p_out, coord, 1, endian_arch ); // Z
26202635
p_in += sizeof(double);
26212636
p_out += sizeof(double);
2622-
if (type == GAIA_POINTZM)
2637+
if (type2 == GAIA_POINTZM)
26232638
p_in += sizeof(double);
26242639
break;
26252640
case GAIA_LINESTRINGM:
@@ -2662,7 +2677,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
26622677
gaiaExport64 ( p_out, coord, 1, endian_arch ); // Z
26632678
p_in += sizeof(double);
26642679
p_out += sizeof(double);
2665-
if (type == GAIA_LINESTRINGZM)
2680+
if (type2 == GAIA_LINESTRINGZM)
26662681
p_in += sizeof(double);
26672682
}
26682683
break;
@@ -2719,7 +2734,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
27192734
gaiaExport64 ( p_out, coord, 1, endian_arch ); // Z
27202735
p_in += sizeof(double);
27212736
p_out += sizeof(double);
2722-
if (type == GAIA_POLYGONZM)
2737+
if (type2 == GAIA_POLYGONZM)
27232738
p_in += sizeof(double);
27242739
}
27252740
}

0 commit comments

Comments
 (0)