49
49
#include <string.h>
50
50
#include <ctype.h> /* tolower() */
51
51
52
+ /* SqlGeometry serialization format
52
53
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
+ */
53
101
54
102
/* Native geometry parser macros */
55
103
@@ -118,6 +166,7 @@ typedef struct msGeometryParserInfo_t {
118
166
int nPointSize ;
119
167
int nPointPos ;
120
168
int nNumPoints ;
169
+ int nNumPointsRead ;
121
170
/* figure array */
122
171
int nFigurePos ;
123
172
int nNumFigures ;
@@ -170,7 +219,7 @@ typedef struct ms_MSSQL2008_layer_info_t {
170
219
"mapmssql2008.c - version of 2007/7/1.\n"
171
220
172
221
/* Native geometry parser code */
173
- void ReadPoint (msGeometryParserInfo * gpi , pointObj * p , int iPoint , int iOrder )
222
+ void ReadPoint (msGeometryParserInfo * gpi , pointObj * p , int iPoint )
174
223
{
175
224
if (gpi -> nColType == MSSQLCOLTYPE_GEOGRAPHY ) {
176
225
p -> x = ReadY (iPoint );
@@ -180,7 +229,7 @@ void ReadPoint(msGeometryParserInfo* gpi, pointObj* p, int iPoint, int iOrder)
180
229
p -> y = ReadY (iPoint );
181
230
}
182
231
/* calculate bounds */
183
- if (iOrder == 0 ) {
232
+ if (gpi -> nNumPointsRead ++ == 0 ) {
184
233
gpi -> minx = gpi -> maxx = p -> x ;
185
234
gpi -> miny = gpi -> maxy = p -> y ;
186
235
} else {
@@ -202,6 +251,8 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape)
202
251
{
203
252
msGeometryParserInfo * gpi = & layerinfo -> gpi ;
204
253
254
+ gpi -> nNumPointsRead = 0 ;
255
+
205
256
if (gpi -> nLen < 10 ) {
206
257
msDebug ("ParseSqlGeometry NOT_ENOUGH_DATA\n" );
207
258
return NOT_ENOUGH_DATA ;
@@ -239,7 +290,7 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape)
239
290
shape -> line [0 ].numpoints = 1 ;
240
291
gpi -> nPointPos = 6 ;
241
292
242
- ReadPoint (gpi , & shape -> line [0 ].point [0 ], 0 , 0 );
293
+ ReadPoint (gpi , & shape -> line [0 ].point [0 ], 0 );
243
294
} else if ( gpi -> chProps & SP_ISSINGLELINESEGMENT ) {
244
295
// single line segment with 2 points
245
296
gpi -> nNumPoints = 2 ;
@@ -255,8 +306,8 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape)
255
306
shape -> line [0 ].numpoints = 2 ;
256
307
gpi -> nPointPos = 6 ;
257
308
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 );
260
311
} else {
261
312
int iShape , iFigure ;
262
313
// complex geometries
@@ -335,7 +386,7 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape)
335
386
336
387
i = 0 ;
337
388
while (iPoint < iNextPoint ) {
338
- ReadPoint (gpi , & shape -> line [iFigure ].point [i ], iPoint , i );
389
+ ReadPoint (gpi , & shape -> line [iFigure ].point [i ], iPoint );
339
390
++ iPoint ;
340
391
++ i ;
341
392
}
0 commit comments