@@ -106,6 +106,7 @@ msPostGISLayerInfo *msPostGISCreateLayerInfo(void)
106
106
layerinfo -> rownum = 0 ;
107
107
layerinfo -> version = 0 ;
108
108
layerinfo -> paging = MS_TRUE ;
109
+ layerinfo -> force2d = MS_TRUE ;
109
110
return layerinfo ;
110
111
}
111
112
@@ -1651,13 +1652,20 @@ char *msPostGISBuildSQLItems(layerObj *layer)
1651
1652
** which includes a 2D force in it) removes ordinates we don't
1652
1653
** need, saving transfer and encode/decode time.
1653
1654
*/
1655
+ char * force2d = "" ;
1654
1656
#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\"" ;
1656
1658
#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\"" ;
1658
1660
#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 );
1661
1669
}
1662
1670
1663
1671
if ( layer -> debug > 1 ) {
@@ -2220,6 +2228,7 @@ int msPostGISLayerOpen(layerObj *layer)
2220
2228
#ifdef USE_POSTGIS
2221
2229
msPostGISLayerInfo * layerinfo ;
2222
2230
int order_test = 1 ;
2231
+ const char * force2d_processing ;
2223
2232
2224
2233
assert (layer != NULL );
2225
2234
@@ -2328,6 +2337,13 @@ int msPostGISLayerOpen(layerObj *layer)
2328
2337
if (layer -> debug )
2329
2338
msDebug ("msPostGISLayerOpen: Got PostGIS version %d.\n" , layerinfo -> version );
2330
2339
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
+
2331
2347
/* Save the layerinfo in the layerObj. */
2332
2348
layer -> layerinfo = (void * )layerinfo ;
2333
2349
0 commit comments