Skip to content

Commit 3e7ecf7

Browse files
committed
Fix bounds calculation for the MSSQL driver (#5082)
1 parent 4770002 commit 3e7ecf7

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

mapmssql2008.c

+57-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,55 @@
4949
#include <string.h>
5050
#include <ctype.h> /* tolower() */
5151

52+
/* SqlGeometry serialization format
5253
54+
Simple Point (SerializationProps & IsSinglePoint)
55+
[SRID][0x01][SerializationProps][Point][z][m]
56+
57+
Simple Line Segment (SerializationProps & IsSingleLineSegment)
58+
[SRID][0x01][SerializationProps][Point1][Point2][z1][z2][m1][m2]
59+
60+
Complex Geometries
61+
[SRID][0x01][SerializationProps][NumPoints][Point1]..[PointN][z1]..[zN][m1]..[mN]
62+
[NumFigures][Figure]..[Figure][NumShapes][Shape]..[Shape]
63+
64+
SRID
65+
Spatial Reference Id (4 bytes)
66+
67+
SerializationProps (bitmask) 1 byte
68+
0x01 = HasZValues
69+
0x02 = HasMValues
70+
0x04 = IsValid
71+
0x08 = IsSinglePoint
72+
0x10 = IsSingleLineSegment
73+
0x20 = IsWholeGlobe
74+
75+
Point (2-4)x8 bytes, size depends on SerializationProps & HasZValues & HasMValues
76+
[x][y] - SqlGeometry
77+
[latitude][longitude] - SqlGeography
78+
79+
Figure
80+
[FigureAttribute][PointOffset]
81+
82+
FigureAttribute (1 byte)
83+
0x00 = Interior Ring
84+
0x01 = Stroke
85+
0x02 = Exterior Ring
86+
87+
Shape
88+
[ParentFigureOffset][FigureOffset][ShapeType]
89+
90+
ShapeType (1 byte)
91+
0x00 = Unknown
92+
0x01 = Point
93+
0x02 = LineString
94+
0x03 = Polygon
95+
0x04 = MultiPoint
96+
0x05 = MultiLineString
97+
0x06 = MultiPolygon
98+
0x07 = GeometryCollection
99+
100+
*/
53101

54102
/* Native geometry parser macros */
55103

@@ -118,6 +166,7 @@ typedef struct msGeometryParserInfo_t {
118166
int nPointSize;
119167
int nPointPos;
120168
int nNumPoints;
169+
int nNumPointsRead;
121170
/* figure array */
122171
int nFigurePos;
123172
int nNumFigures;
@@ -170,7 +219,7 @@ typedef struct ms_MSSQL2008_layer_info_t {
170219
"mapmssql2008.c - version of 2007/7/1.\n"
171220

172221
/* Native geometry parser code */
173-
void ReadPoint(msGeometryParserInfo* gpi, pointObj* p, int iPoint, int iOrder)
222+
void ReadPoint(msGeometryParserInfo* gpi, pointObj* p, int iPoint)
174223
{
175224
if (gpi->nColType == MSSQLCOLTYPE_GEOGRAPHY) {
176225
p->x = ReadY(iPoint);
@@ -180,7 +229,7 @@ void ReadPoint(msGeometryParserInfo* gpi, pointObj* p, int iPoint, int iOrder)
180229
p->y = ReadY(iPoint);
181230
}
182231
/* calculate bounds */
183-
if (iOrder == 0) {
232+
if (gpi->nNumPointsRead++ == 0) {
184233
gpi->minx = gpi->maxx = p->x;
185234
gpi->miny = gpi->maxy = p->y;
186235
} else {
@@ -202,6 +251,8 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape)
202251
{
203252
msGeometryParserInfo* gpi = &layerinfo->gpi;
204253

254+
gpi->nNumPointsRead = 0;
255+
205256
if (gpi->nLen < 10) {
206257
msDebug("ParseSqlGeometry NOT_ENOUGH_DATA\n");
207258
return NOT_ENOUGH_DATA;
@@ -239,7 +290,7 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape)
239290
shape->line[0].numpoints = 1;
240291
gpi->nPointPos = 6;
241292

242-
ReadPoint(gpi, &shape->line[0].point[0], 0, 0);
293+
ReadPoint(gpi, &shape->line[0].point[0], 0);
243294
} else if ( gpi->chProps & SP_ISSINGLELINESEGMENT ) {
244295
// single line segment with 2 points
245296
gpi->nNumPoints = 2;
@@ -255,8 +306,8 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape)
255306
shape->line[0].numpoints = 2;
256307
gpi->nPointPos = 6;
257308

258-
ReadPoint(gpi, &shape->line[0].point[0], 0, 0);
259-
ReadPoint(gpi, &shape->line[0].point[1], 1, 1);
309+
ReadPoint(gpi, &shape->line[0].point[0], 0);
310+
ReadPoint(gpi, &shape->line[0].point[1], 1);
260311
} else {
261312
int iShape, iFigure;
262313
// complex geometries
@@ -335,7 +386,7 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape)
335386

336387
i = 0;
337388
while (iPoint < iNextPoint) {
338-
ReadPoint(gpi, &shape->line[iFigure].point[i], iPoint, i);
389+
ReadPoint(gpi, &shape->line[iFigure].point[i], iPoint);
339390
++iPoint;
340391
++i;
341392
}

0 commit comments

Comments
 (0)