MCPcopy Index your code
hub / github.com/MapServer/MapServer / msPostGISBuildSQLBox

Function msPostGISBuildSQLBox

mappostgis.c:1526–1570  ·  view source on GitHub ↗

** msPostGISBuildSQLBox() ** ** Returns malloc'ed char* that must be freed by caller. */

Source from the content-addressed store, hash-verified

1524** Returns malloc'ed char* that must be freed by caller.
1525*/
1526char *msPostGISBuildSQLBox(layerObj *layer, rectObj *rect, char *strSRID) {
1527
1528 char *strBox = NULL;
1529 size_t sz;
1530
1531 if (layer->debug) {
1532 msDebug("msPostGISBuildSQLBox called.\n");
1533 }
1534
1535 if ( strSRID ) {
1536 static char *strBoxTemplate = "ST_GeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))',%s)";
1537 /* 10 doubles + 1 integer + template characters */
1538 sz = 10 * 22 + strlen(strSRID) + strlen(strBoxTemplate);
1539 strBox = (char*)msSmallMalloc(sz+1); /* add space for terminating NULL */
1540 if ( sz <= snprintf(strBox, sz, strBoxTemplate,
1541 rect->minx, rect->miny,
1542 rect->minx, rect->maxy,
1543 rect->maxx, rect->maxy,
1544 rect->maxx, rect->miny,
1545 rect->minx, rect->miny,
1546 strSRID))
1547 {
1548 msSetError(MS_MISCERR,"Bounding box digits truncated.","msPostGISBuildSQLBox");
1549 return NULL;
1550 }
1551 } else {
1552 static char *strBoxTemplate = "ST_GeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))')";
1553 /* 10 doubles + template characters */
1554 sz = 10 * 22 + strlen(strBoxTemplate);
1555 strBox = (char*)msSmallMalloc(sz+1); /* add space for terminating NULL */
1556 if ( sz <= snprintf(strBox, sz, strBoxTemplate,
1557 rect->minx, rect->miny,
1558 rect->minx, rect->maxy,
1559 rect->maxx, rect->maxy,
1560 rect->maxx, rect->miny,
1561 rect->minx, rect->miny) )
1562 {
1563 msSetError(MS_MISCERR,"Bounding box digits truncated.","msPostGISBuildSQLBox");
1564 return NULL;
1565 }
1566 }
1567
1568 return strBox;
1569
1570}
1571
1572
1573/*

Callers 2

msPostGISReplaceBoxTokenFunction · 0.85
msPostGISBuildSQLWhereFunction · 0.85

Calls 3

msDebugFunction · 0.85
msSmallMallocFunction · 0.85
msSetErrorFunction · 0.85

Tested by

no test coverage detected