Skip to content
Permalink
Browse files

fixing several issues related to SpatiaLite 3D Geometries

git-svn-id: http://svn.osgeo.org/qgis/trunk@15814 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
esseffe
esseffe committed Apr 23, 2011
1 parent f0ca2e3 commit 171bed7988f040632e61faa7de1a0cec719401aa
Showing with 26 additions and 11 deletions.
  1. +1 −1 src/core/qgsgeometry.cpp
  2. +25 −10 src/providers/spatialite/qgsspatialiteprovider.cpp
@@ -1473,7 +1473,7 @@ bool QgsGeometry::moveVertex( double x, double y, int atVertex )
ptr += 2 * sizeof( double ) * ( vertexnr - pointindex );
if ( hasZValue )
{
ptr += 3 * sizeof( double ) * ( vertexnr - pointindex );
ptr += sizeof( double ) * ( vertexnr - pointindex );
}
memcpy( ptr, &x, sizeof( double ) );
ptr += sizeof( double );
@@ -402,12 +402,16 @@ bool QgsSpatiaLiteProvider::featureAtId( int featureId, QgsFeature & feature, bo
{
if ( sqlite3_column_type( stmt, ic ) == SQLITE_BLOB )
{
unsigned char *featureGeom = NULL;
size_t geom_size = 0;
const void *blob = sqlite3_column_blob( stmt, ic );
size_t blob_size = sqlite3_column_bytes( stmt, ic );
unsigned char *featureGeom = new unsigned char[blob_size + 1];
memset( featureGeom, '\0', blob_size + 1 );
memcpy( featureGeom, blob, blob_size );
feature.setGeometryAndOwnership( featureGeom, blob_size + 1 );
convertToGeosWKB ( (const unsigned char *)blob, blob_size,
&featureGeom, &geom_size );
if ( featureGeom )
feature.setGeometryAndOwnership( featureGeom, geom_size );
else
feature.setGeometryAndOwnership( 0, 0 );
}
else
{
@@ -592,6 +596,7 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB2D( const unsigned char *blob,
break;
case GAIA_LINESTRING:
points = gaiaImport32 ( p_in, little_endian, endian_arch );
gsize += 4;
switch ( nDims )
{
case GAIA_XY_Z_M:
@@ -609,10 +614,12 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB2D( const unsigned char *blob,
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 );
p_in += 4;
gsize += 4;
switch ( nDims )
{
case GAIA_XY_Z_M:
@@ -761,6 +768,7 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB3D( const unsigned char *blob,
break;
case GEOS_3D_LINESTRING:
points = gaiaImport32 ( p_in, little_endian, endian_arch );
gsize += 4;
switch ( nDims )
{
case GAIA_XY_Z_M:
@@ -778,10 +786,12 @@ int QgsSpatiaLiteProvider::computeSizeFromGeosWKB3D( const unsigned char *blob,
case GEOS_3D_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 );
p_in += 4;
gsize += 4;
switch ( nDims )
{
case GAIA_XY_Z_M:
@@ -933,7 +943,7 @@ void QgsSpatiaLiteProvider::convertFromGeosWKB ( const unsigned char *blob,
else
return;

if ( gDims == 2 && nDims == 2 )
if ( gDims == 2 && nDims == GAIA_XY )
{
// already 2D: simply copying is required
unsigned char *wkbGeom = new unsigned char[blob_size + 1];
@@ -2148,27 +2158,32 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
case GAIA_LINESTRINGM:
case GAIA_LINESTRINGZM:
points = gaiaImport32 ( p_in, little_endian, endian_arch );
gsize += 4;
gsize += points * ( 3 * sizeof(double) );
break;
case GAIA_POLYGONZ:
case GAIA_POLYGONM:
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 );
p_in += 4;
gsize += 4;
gsize += points * ( 3 * sizeof(double) );
p_in += points * ( 3 * sizeof(double) );
}
break;
case GAIA_POLYGONZM:
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 );
p_in += 4;
gsize += 4;
gsize += points * ( 3 * sizeof(double) );
p_in += points * ( 4 * sizeof(double) );
}
@@ -2473,7 +2488,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
gaiaExport64 ( p_out, coord, 1, endian_arch ); // Z
p_in += sizeof(double);
p_out += sizeof(double);
if (type == GAIA_LINESTRINGZM)
if (type == GAIA_MULTILINESTRINGZM)
p_in += sizeof(double);
}
}
@@ -2552,7 +2567,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
gaiaExport64 ( p_out, coord, 1, endian_arch ); // Z
p_in += sizeof(double);
p_out += sizeof(double);
if (type == GAIA_POLYGONZM)
if (type == GAIA_MULTIPOLYGONZM)
p_in += sizeof(double);
}
}
@@ -2619,7 +2634,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
gaiaExport64 ( p_out, coord, 1, endian_arch ); // Z
p_in += sizeof(double);
p_out += sizeof(double);
if (type == GAIA_POINTZM)
if (type2 == GAIA_POINTZM)
p_in += sizeof(double);
break;
case GAIA_LINESTRINGM:
@@ -2662,7 +2677,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
gaiaExport64 ( p_out, coord, 1, endian_arch ); // Z
p_in += sizeof(double);
p_out += sizeof(double);
if (type == GAIA_LINESTRINGZM)
if (type2 == GAIA_LINESTRINGZM)
p_in += sizeof(double);
}
break;
@@ -2719,7 +2734,7 @@ void QgsSpatiaLiteProvider::convertToGeosWKB ( const unsigned char *blob,
gaiaExport64 ( p_out, coord, 1, endian_arch ); // Z
p_in += sizeof(double);
p_out += sizeof(double);
if (type == GAIA_POLYGONZM)
if (type2 == GAIA_POLYGONZM)
p_in += sizeof(double);
}
}

0 comments on commit 171bed7

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