Skip to content
Permalink
Browse files
MSSQL: Fix for reading 3D geometries (#6733)
  • Loading branch information
szekerest committed Feb 28, 2013
1 parent f5d81ae commit 9dbd21a813f474c31fc1225ac7d454c99977ac9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
@@ -23,13 +23,13 @@
/* SqlGeometry serialization format
Simple Point (SerializationProps & IsSinglePoint)
[SRID][0x01][SerializationProps][Point]
[SRID][0x01][SerializationProps][Point][z][m]
Simple Line Segment (SerializationProps & IsSingleLineSegment)
[SRID][0x01][SerializationProps][Point][Point]
[SRID][0x01][SerializationProps][Point1][Point2][z1][z2][m1][m2]
Complex Geometries
[SRID][0x01][SerializationProps][NumPoints][Point]..[Point]
[SRID][0x01][SerializationProps][NumPoints][Point1]..[PointN][z1]..[zN][m1]..[mN]
[NumFigures][Figure]..[Figure][NumShapes][Shape]..[Shape]
SRID
@@ -44,8 +44,8 @@ SerializationProps (bitmask) 1 byte
0x20 = IsWholeGlobe
Point (2-4)x8 bytes, size depends on SerializationProps & HasZValues & HasMValues
[x][y][z][m] - SqlGeometry
[latitude][longitude][z][m] - SqlGeography
[x][y] - SqlGeometry
[latitude][longitude] - SqlGeography
Figure
[FigureAttribute][PointOffset]
@@ -107,9 +107,10 @@ ShapeType (1 byte)
#define PointOffset(iFigure) (ReadInt32(nFigurePos + (iFigure) * 5 + 1))
#define NextPointOffset(iFigure) (iFigure + 1 < nNumFigures? PointOffset((iFigure) +1) : nNumPoints)

#define ReadX(iPoint) (ReadDouble(nPointPos + nPointSize * (iPoint)))
#define ReadY(iPoint) (ReadDouble(nPointPos + nPointSize * (iPoint) + 8))
#define ReadZ(iPoint) (ReadDouble(nPointPos + nPointSize * (iPoint) + 16))
#define ReadX(iPoint) (ReadDouble(nPointPos + 16 * (iPoint)))
#define ReadY(iPoint) (ReadDouble(nPointPos + 16 * (iPoint) + 8))
#define ReadZ(iPoint) (ReadDouble(nPointPos + 16 * nNumPoints + 8 * (iPoint)))
#define ReadM(iPoint) (ReadDouble(nPointPos + 24 * nNumPoints + 8 * (iPoint)))

/************************************************************************/
/* QgsMssqlGeometryParser() */
@@ -175,16 +176,19 @@ void QgsMssqlGeometryParser::CopyBytes( void* src, int len )
/* CopyCoordinates() */
/************************************************************************/

void QgsMssqlGeometryParser::CopyCoordinates( unsigned char* src )
void QgsMssqlGeometryParser::CopyCoordinates( int iPoint )
{
if ( IsGeography )
{
CopyBytes( src + 8, 8 ); // longitude
CopyBytes( src, 8 ); // latitude
CopyBytes(pszData + nPointPos + 16 * iPoint + 8, 8); // longitude
CopyBytes(pszData + nPointPos + 16 * iPoint, 8); // latitude
}
else
// copy geometry coords
CopyBytes( src, nPointSize );
CopyBytes(pszData + nPointPos + 16 * iPoint, 16);

if ( chProps & SP_HASZVALUES )
CopyBytes(pszData + nPointPos + 16 * nNumPoints + 8 * iPoint, 8); // copy z value
}

/************************************************************************/
@@ -203,7 +207,7 @@ void QgsMssqlGeometryParser::CopyPoint( int iPoint )
wkbType = QGis::WKBPoint;
CopyBytes( &wkbType, 4 );
// copy coordinates
CopyCoordinates( pszData + nPointPos + nPointSize * iPoint );
CopyCoordinates( iPoint );
}

/************************************************************************/
@@ -284,7 +288,7 @@ void QgsMssqlGeometryParser::ReadLineString( int iShape )
i = 0;
while ( iPoint < iNextPoint )
{
CopyCoordinates( pszData + nPointPos + nPointSize * iPoint );
CopyCoordinates( iPoint );
++iPoint;
++i;
}
@@ -358,7 +362,7 @@ void QgsMssqlGeometryParser::ReadPolygon( int iShape )
i = 0;
while ( iPoint < iNextPoint )
{
CopyCoordinates( pszData + nPointPos + nPointSize * iPoint );
CopyCoordinates( iPoint );
++iPoint;
++i;
}
@@ -490,6 +494,7 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput
if ( chProps & SP_ISSINGLEPOINT )
{
// single point geometry
nNumPoints = 1;
nPointPos = 6;

if ( nLen < 6 + nPointSize )
@@ -505,6 +510,7 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput
else if ( chProps & SP_ISSINGLELINESEGMENT )
{
// single line segment with 2 points
nNumPoints = 2;
nPointPos = 6;

if ( nLen < 6 + 2 * nPointSize )
@@ -528,8 +534,8 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput
int iCount = 2;
CopyBytes( &iCount, 4 );
// copy points
CopyCoordinates( pszData + nPointPos );
CopyCoordinates( pszData + nPointPos + nPointSize );
CopyCoordinates( 0 );
CopyCoordinates( 1 );
}
else
{
@@ -71,7 +71,7 @@ class QgsMssqlGeometryParser

protected:
void CopyBytes( void* src, int len );
void CopyCoordinates( unsigned char* src );
void CopyCoordinates( int iPoint );
void CopyPoint( int iPoint );
void ReadPoint( int iShape );
void ReadMultiPoint( int iShape );

0 comments on commit 9dbd21a

Please sign in to comment.