Skip to content

Commit d4d3e22

Browse files
committed
use version specific postgis force2d function (#4803)
also adds a PROCESSING "FORCE2D=no" to avoid using force2d altogether (#4024)
1 parent 3a6fa42 commit d4d3e22

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

mappostgis.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ msPostGISLayerInfo *msPostGISCreateLayerInfo(void)
106106
layerinfo->rownum = 0;
107107
layerinfo->version = 0;
108108
layerinfo->paging = MS_TRUE;
109+
layerinfo->force2d = MS_TRUE;
109110
return layerinfo;
110111
}
111112

@@ -1651,13 +1652,20 @@ char *msPostGISBuildSQLItems(layerObj *layer)
16511652
** which includes a 2D force in it) removes ordinates we don't
16521653
** need, saving transfer and encode/decode time.
16531654
*/
1655+
char *force2d = "";
16541656
#if TRANSFER_ENCODING == 64
1655-
static char *strGeomTemplate = "encode(ST_AsBinary(ST_Force2D(\"%s\"),'%s'),'base64') as geom,\"%s\"";
1657+
static char *strGeomTemplate = "encode(ST_AsBinary(%s(\"%s\"),'%s'),'base64') as geom,\"%s\"";
16561658
#else
1657-
static char *strGeomTemplate = "encode(ST_AsBinary(ST_Force2D(\"%s\"),'%s'),'hex') as geom,\"%s\"";
1659+
static char *strGeomTemplate = "encode(ST_AsBinary(%s(\"%s\"),'%s'),'hex') as geom,\"%s\"";
16581660
#endif
1659-
strGeom = (char*)msSmallMalloc(strlen(strGeomTemplate) + strlen(strEndian) + strlen(layerinfo->geomcolumn) + strlen(layerinfo->uid));
1660-
sprintf(strGeom, strGeomTemplate, layerinfo->geomcolumn, strEndian, layerinfo->uid);
1661+
if( layerinfo->force2d ) {
1662+
if( layerinfo->version >= 20100 )
1663+
force2d = "ST_Force2D";
1664+
else
1665+
force2d = "ST_Force_2D";
1666+
}
1667+
strGeom = (char*)msSmallMalloc(strlen(strGeomTemplate) + strlen(force2d) + strlen(strEndian) + strlen(layerinfo->geomcolumn) + strlen(layerinfo->uid));
1668+
sprintf(strGeom, strGeomTemplate, force2d, layerinfo->geomcolumn, strEndian, layerinfo->uid);
16611669
}
16621670

16631671
if( layer->debug > 1 ) {
@@ -2220,6 +2228,7 @@ int msPostGISLayerOpen(layerObj *layer)
22202228
#ifdef USE_POSTGIS
22212229
msPostGISLayerInfo *layerinfo;
22222230
int order_test = 1;
2231+
const char* force2d_processing;
22232232

22242233
assert(layer != NULL);
22252234

@@ -2328,6 +2337,13 @@ int msPostGISLayerOpen(layerObj *layer)
23282337
if (layer->debug)
23292338
msDebug("msPostGISLayerOpen: Got PostGIS version %d.\n", layerinfo->version);
23302339

2340+
force2d_processing = msLayerGetProcessingKey( layer, "FORCE2D" );
2341+
if(force2d_processing && !strcasecmp(force2d_processing,"no")) {
2342+
layerinfo->force2d = MS_FALSE;
2343+
}
2344+
if (layer->debug)
2345+
msDebug("msPostGISLayerOpen: Forcing 2D geometries: %s.\n", (layerinfo->force2d)?"yes":"no");
2346+
23312347
/* Save the layerinfo in the layerObj. */
23322348
layer->layerinfo = (void*)layerinfo;
23332349

mappostgis.h

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ typedef struct {
6464
int endian; /* Endianness of the mapserver host */
6565
int version; /* PostGIS version of the database */
6666
int paging; /* Driver handling of pagination, enabled by default */
67+
int force2d; /* Pass geometry through ST_Force2D */
6768
}
6869
msPostGISLayerInfo;
6970

0 commit comments

Comments
 (0)