Skip to content

Commit d001ac6

Browse files
Don't use CIRCULARSTRING when fetching geography data from SQL Server.
1 parent 1231c31 commit d001ac6

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

mapmssql2008.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,9 +1341,15 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string)
13411341
/*
13421342
"Geometry::STGeomFromText('POLYGON(())',)" + terminator = 40 chars
13431343
Plus 10 formatted doubles (15 digits of precision, a decimal point, a space/comma delimiter each = 17 chars each)
1344+
Plus SRID + comma - if SRID is a long...we'll be safe with 10 chars
1345+
1346+
or for geography columns
1347+
1348+
"Geography::STGeomFromText('CURVEPOLYGON(())',)" + terminator = 46 chars
1349+
Plus 18 formatted doubles (15 digits of precision, a decimal point, a space/comma delimiter each = 17 chars each)
13441350
Plus SRID + comma - if SRID is a long...we'll be safe with 10 chars
13451351
*/
1346-
char box3d[40 + 10 * 22 + 11];
1352+
char box3d[46 + 18 * 22 + 11];
13471353
int t;
13481354

13491355
char *pos_from, *pos_ftab, *pos_space, *pos_paren;
@@ -1399,10 +1405,25 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string)
13991405
/* create point shape for rectangles with zero area */
14001406
sprintf(box3d, "%s::STGeomFromText('POINT(%.15g %.15g)',%s)", /* %s.STSrid)", */
14011407
layerinfo->geom_column_type, rect.minx, rect.miny, layerinfo->user_srid);
1402-
}
1403-
else {
1404-
sprintf(box3d, "%s::STGeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))',%s)", /* %s.STSrid)", */
1405-
layerinfo->geom_column_type,
1408+
} else if (strcasecmp(layerinfo->geom_column_type, "geography") == 0) {
1409+
/* SQL Server has a problem when x is -180 or 180 */
1410+
double minx = rect.minx <= -180? -179.999: rect.minx;
1411+
double maxx = rect.maxx >= 180? 179.999: rect.maxx;
1412+
double miny = rect.miny < -90? -90: rect.miny;
1413+
double maxy = rect.maxy > 90? 90: rect.maxy;
1414+
sprintf(box3d, "Geography::STGeomFromText('CURVEPOLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))',%s)", /* %s.STSrid)", */
1415+
minx, miny,
1416+
minx + (maxx - minx) / 2, miny,
1417+
maxx, miny,
1418+
maxx, miny + (maxy - miny) / 2,
1419+
maxx, maxy,
1420+
minx + (maxx - minx) / 2, maxy,
1421+
minx, maxy,
1422+
minx, miny + (maxy - miny) / 2,
1423+
minx, miny,
1424+
layerinfo->user_srid);
1425+
} else {
1426+
sprintf(box3d, "Geometry::STGeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))',%s)", /* %s.STSrid)", */
14061427
rect.minx, rect.miny,
14071428
rect.maxx, rect.miny,
14081429
rect.maxx, rect.maxy,

0 commit comments

Comments
 (0)