Permalink
Browse files

use version specific postgis force2d function (#4803)

also adds a PROCESSING "FORCE2D=no" to avoid using force2d altogether (#4024)
  • Loading branch information...
1 parent 3a6fa42 commit d4d3e2205eeadd3f4b2ad60d803aa7c1836d8dee @tbonfort tbonfort committed Nov 5, 2013
Showing with 21 additions and 4 deletions.
  1. +20 −4 mappostgis.c
  2. +1 −0 mappostgis.h
View
@@ -106,6 +106,7 @@ msPostGISLayerInfo *msPostGISCreateLayerInfo(void)
layerinfo->rownum = 0;
layerinfo->version = 0;
layerinfo->paging = MS_TRUE;
+ layerinfo->force2d = MS_TRUE;
return layerinfo;
}
@@ -1651,13 +1652,20 @@ char *msPostGISBuildSQLItems(layerObj *layer)
** which includes a 2D force in it) removes ordinates we don't
** need, saving transfer and encode/decode time.
*/
+ char *force2d = "";
#if TRANSFER_ENCODING == 64
- static char *strGeomTemplate = "encode(ST_AsBinary(ST_Force2D(\"%s\"),'%s'),'base64') as geom,\"%s\"";
+ static char *strGeomTemplate = "encode(ST_AsBinary(%s(\"%s\"),'%s'),'base64') as geom,\"%s\"";
#else
- static char *strGeomTemplate = "encode(ST_AsBinary(ST_Force2D(\"%s\"),'%s'),'hex') as geom,\"%s\"";
+ static char *strGeomTemplate = "encode(ST_AsBinary(%s(\"%s\"),'%s'),'hex') as geom,\"%s\"";
#endif
- strGeom = (char*)msSmallMalloc(strlen(strGeomTemplate) + strlen(strEndian) + strlen(layerinfo->geomcolumn) + strlen(layerinfo->uid));
- sprintf(strGeom, strGeomTemplate, layerinfo->geomcolumn, strEndian, layerinfo->uid);
+ if( layerinfo->force2d ) {
+ if( layerinfo->version >= 20100 )
+ force2d = "ST_Force2D";
+ else
+ force2d = "ST_Force_2D";
+ }
+ strGeom = (char*)msSmallMalloc(strlen(strGeomTemplate) + strlen(force2d) + strlen(strEndian) + strlen(layerinfo->geomcolumn) + strlen(layerinfo->uid));
+ sprintf(strGeom, strGeomTemplate, force2d, layerinfo->geomcolumn, strEndian, layerinfo->uid);
}
if( layer->debug > 1 ) {
@@ -2220,6 +2228,7 @@ int msPostGISLayerOpen(layerObj *layer)
#ifdef USE_POSTGIS
msPostGISLayerInfo *layerinfo;
int order_test = 1;
+ const char* force2d_processing;
assert(layer != NULL);
@@ -2328,6 +2337,13 @@ int msPostGISLayerOpen(layerObj *layer)
if (layer->debug)
msDebug("msPostGISLayerOpen: Got PostGIS version %d.\n", layerinfo->version);
+ force2d_processing = msLayerGetProcessingKey( layer, "FORCE2D" );
+ if(force2d_processing && !strcasecmp(force2d_processing,"no")) {
+ layerinfo->force2d = MS_FALSE;
+ }
+ if (layer->debug)
+ msDebug("msPostGISLayerOpen: Forcing 2D geometries: %s.\n", (layerinfo->force2d)?"yes":"no");
+
/* Save the layerinfo in the layerObj. */
layer->layerinfo = (void*)layerinfo;
View
@@ -64,6 +64,7 @@ typedef struct {
int endian; /* Endianness of the mapserver host */
int version; /* PostGIS version of the database */
int paging; /* Driver handling of pagination, enabled by default */
+ int force2d; /* Pass geometry through ST_Force2D */
}
msPostGISLayerInfo;

0 comments on commit d4d3e22

Please sign in to comment.