Skip to content

Commit

Permalink
PostGIS: fix ST_Intersects() with bounding box that is a point (follo…
Browse files Browse the repository at this point in the history
…w-up of fixes #6181, fixes #6230) (fixes #6347 (comment))
  • Loading branch information
rouault committed Jun 29, 2021
1 parent 1ff7812 commit 44d5d9c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions mappostgis.c
Expand Up @@ -1666,37 +1666,44 @@ char *msPostGISBuildSQLBox(layerObj *layer, rectObj *rect, char *strSRID)

char *strBox = NULL;
size_t sz;
const int bIsPoint = rect->minx == rect->maxx && rect->miny == rect->maxy;

if (layer->debug) {
msDebug("msPostGISBuildSQLBox called.\n");
}

if ( strSRID ) {
static char *strBoxTemplate = "ST_GeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))',%s)";
static const char *strBoxTemplate = "ST_GeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))',%s)";
static const char *strBoxTemplatePoint = "ST_GeomFromText('POINT(%.15g %.15g)',%s)";
/* 10 doubles + 1 integer + template characters */
sz = 10 * 22 + strlen(strSRID) + strlen(strBoxTemplate);
strBox = (char*)msSmallMalloc(sz+1); /* add space for terminating NULL */
if ( sz <= snprintf(strBox, sz, strBoxTemplate,
if ( (bIsPoint && sz <= (size_t)(snprintf(strBox, sz, strBoxTemplatePoint,
rect->minx, rect->miny, strSRID))) ||
(!bIsPoint && sz <= (size_t)(snprintf(strBox, sz, strBoxTemplate,
rect->minx, rect->miny,
rect->minx, rect->maxy,
rect->maxx, rect->maxy,
rect->maxx, rect->miny,
rect->minx, rect->miny,
strSRID)) {
strSRID))) ) {
msSetError(MS_MISCERR,"Bounding box digits truncated.","msPostGISBuildSQLBox");
return NULL;
}
} else {
static char *strBoxTemplate = "ST_GeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))')";
static const char *strBoxTemplate = "ST_GeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))')";
static const char *strBoxTemplatePoint = "ST_GeomFromText('POINT(%.15g %.15g)')";
/* 10 doubles + template characters */
sz = 10 * 22 + strlen(strBoxTemplate);
strBox = (char*)msSmallMalloc(sz+1); /* add space for terminating NULL */
if ( sz <= snprintf(strBox, sz, strBoxTemplate,
if ( (bIsPoint && sz <= (size_t)(snprintf(strBox, sz, strBoxTemplatePoint,
rect->minx, rect->miny))) ||
(!bIsPoint && sz <= (size_t)(snprintf(strBox, sz, strBoxTemplate,
rect->minx, rect->miny,
rect->minx, rect->maxy,
rect->maxx, rect->maxy,
rect->maxx, rect->miny,
rect->minx, rect->miny) ) {
rect->minx, rect->miny))) ) {
msSetError(MS_MISCERR,"Bounding box digits truncated.","msPostGISBuildSQLBox");
return NULL;
}
Expand Down

0 comments on commit 44d5d9c

Please sign in to comment.