@@ -402,12 +402,16 @@ bool QgsSpatiaLiteProvider::featureAtId( int featureId, QgsFeature & feature, bo
402
402
{
403
403
if ( sqlite3_column_type ( stmt, ic ) == SQLITE_BLOB )
404
404
{
405
+ unsigned char *featureGeom = NULL ;
406
+ size_t geom_size = 0 ;
405
407
const void *blob = sqlite3_column_blob ( stmt, ic );
406
408
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 );
411
415
}
412
416
else
413
417
{
@@ -592,6 +596,7 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB2D( const unsigned char *blob,
592
596
break ;
593
597
case GAIA_LINESTRING:
594
598
points = gaiaImport32 ( p_in, little_endian, endian_arch );
599
+ gsize += 4 ;
595
600
switch ( nDims )
596
601
{
597
602
case GAIA_XY_Z_M:
@@ -609,10 +614,12 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB2D( const unsigned char *blob,
609
614
case GAIA_POLYGON:
610
615
rings = gaiaImport32 ( p_in, little_endian, endian_arch );
611
616
p_in += 4 ;
617
+ gsize += 4 ;
612
618
for ( ib = 0 ; ib < rings; ib++ )
613
619
{
614
620
points = gaiaImport32 ( p_in, little_endian, endian_arch );
615
621
p_in += 4 ;
622
+ gsize += 4 ;
616
623
switch ( nDims )
617
624
{
618
625
case GAIA_XY_Z_M:
@@ -761,6 +768,7 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB3D( const unsigned char *blob,
761
768
break ;
762
769
case GEOS_3D_LINESTRING:
763
770
points = gaiaImport32 ( p_in, little_endian, endian_arch );
771
+ gsize += 4 ;
764
772
switch ( nDims )
765
773
{
766
774
case GAIA_XY_Z_M:
@@ -778,10 +786,12 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB3D( const unsigned char *blob,
778
786
case GEOS_3D_POLYGON:
779
787
rings = gaiaImport32 ( p_in, little_endian, endian_arch );
780
788
p_in += 4 ;
789
+ gsize += 4 ;
781
790
for ( ib = 0 ; ib < rings; ib++ )
782
791
{
783
792
points = gaiaImport32 ( p_in, little_endian, endian_arch );
784
793
p_in += 4 ;
794
+ gsize += 4 ;
785
795
switch ( nDims )
786
796
{
787
797
case GAIA_XY_Z_M:
@@ -933,7 +943,7 @@ void QgsSpatiaLiteProvider::convertFromGeosWKB ( const unsigned char *blob,
933
943
else
934
944
return ;
935
945
936
- if ( gDims == 2 && nDims == 2 )
946
+ if ( gDims == 2 && nDims == GAIA_XY )
937
947
{
938
948
// already 2D: simply copying is required
939
949
unsigned char *wkbGeom = new unsigned char [blob_size + 1 ];
@@ -2148,27 +2158,32 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
2148
2158
case GAIA_LINESTRINGM:
2149
2159
case GAIA_LINESTRINGZM:
2150
2160
points = gaiaImport32 ( p_in, little_endian, endian_arch );
2161
+ gsize += 4 ;
2151
2162
gsize += points * ( 3 * sizeof (double ) );
2152
2163
break ;
2153
2164
case GAIA_POLYGONZ:
2154
2165
case GAIA_POLYGONM:
2155
2166
rings = gaiaImport32 ( p_in, little_endian, endian_arch );
2156
2167
p_in += 4 ;
2168
+ gsize += 4 ;
2157
2169
for ( ib = 0 ; ib < rings; ib++ )
2158
2170
{
2159
2171
points = gaiaImport32 ( p_in, little_endian, endian_arch );
2160
2172
p_in += 4 ;
2173
+ gsize += 4 ;
2161
2174
gsize += points * ( 3 * sizeof (double ) );
2162
2175
p_in += points * ( 3 * sizeof (double ) );
2163
2176
}
2164
2177
break ;
2165
2178
case GAIA_POLYGONZM:
2166
2179
rings = gaiaImport32 ( p_in, little_endian, endian_arch );
2167
2180
p_in += 4 ;
2181
+ gsize += 4 ;
2168
2182
for ( ib = 0 ; ib < rings; ib++ )
2169
2183
{
2170
2184
points = gaiaImport32 ( p_in, little_endian, endian_arch );
2171
2185
p_in += 4 ;
2186
+ gsize += 4 ;
2172
2187
gsize += points * ( 3 * sizeof (double ) );
2173
2188
p_in += points * ( 4 * sizeof (double ) );
2174
2189
}
@@ -2473,7 +2488,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
2473
2488
gaiaExport64 ( p_out, coord, 1 , endian_arch ); // Z
2474
2489
p_in += sizeof (double );
2475
2490
p_out += sizeof (double );
2476
- if (type == GAIA_LINESTRINGZM )
2491
+ if (type == GAIA_MULTILINESTRINGZM )
2477
2492
p_in += sizeof (double );
2478
2493
}
2479
2494
}
@@ -2552,7 +2567,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
2552
2567
gaiaExport64 ( p_out, coord, 1 , endian_arch ); // Z
2553
2568
p_in += sizeof (double );
2554
2569
p_out += sizeof (double );
2555
- if (type == GAIA_POLYGONZM )
2570
+ if (type == GAIA_MULTIPOLYGONZM )
2556
2571
p_in += sizeof (double );
2557
2572
}
2558
2573
}
@@ -2619,7 +2634,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
2619
2634
gaiaExport64 ( p_out, coord, 1 , endian_arch ); // Z
2620
2635
p_in += sizeof (double );
2621
2636
p_out += sizeof (double );
2622
- if (type == GAIA_POINTZM)
2637
+ if (type2 == GAIA_POINTZM)
2623
2638
p_in += sizeof (double );
2624
2639
break ;
2625
2640
case GAIA_LINESTRINGM:
@@ -2662,7 +2677,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
2662
2677
gaiaExport64 ( p_out, coord, 1 , endian_arch ); // Z
2663
2678
p_in += sizeof (double );
2664
2679
p_out += sizeof (double );
2665
- if (type == GAIA_LINESTRINGZM)
2680
+ if (type2 == GAIA_LINESTRINGZM)
2666
2681
p_in += sizeof (double );
2667
2682
}
2668
2683
break ;
@@ -2719,7 +2734,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
2719
2734
gaiaExport64 ( p_out, coord, 1 , endian_arch ); // Z
2720
2735
p_in += sizeof (double );
2721
2736
p_out += sizeof (double );
2722
- if (type == GAIA_POLYGONZM)
2737
+ if (type2 == GAIA_POLYGONZM)
2723
2738
p_in += sizeof (double );
2724
2739
}
2725
2740
}
0 commit comments