Skip to content

Commit

Permalink
fixing several issues related to SpatiaLite 3D Geometries
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15814 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
esseffe committed Apr 23, 2011
1 parent f0ca2e3 commit 171bed7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsgeometry.cpp
Expand Up @@ -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 );
Expand Down
35 changes: 25 additions & 10 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -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
{
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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) );
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 171bed7

Please sign in to comment.