Skip to content

Instantly share code, notes, and snippets.

@mcenirm
Last active November 19, 2015 14:27
Show Gist options
  • Save mcenirm/37567dd6a728ff00d371 to your computer and use it in GitHub Desktop.
Save mcenirm/37567dd6a728ff00d371 to your computer and use it in GitHub Desktop.
Mapserver 6.0.4 + PostGIS geography workaround for "function st_force_2d(geography) does not exist" error
CREATE OR REPLACE FUNCTION ST_Force_2D(GEOGRAPHY)
RETURNS GEOGRAPHY
AS 'SELECT ST_Force_2D($1::geometry)::GEOGRAPHY'
LANGUAGE SQL IMMUTABLE STRICT;
MAP
NAME "example"
PROJECTION
"init=epsg:4326" ##required
END
WEB
METADATA
"wms_title" "gis" ##required
"wms_onlineresource" "http://localhost/mapserv.cgi?map=example.map&" ##required
"wms_srs" "EPSG:4326 EPSG:3857" ##recommended
"wms_enable_request" "*" ##necessary
END
END # Web
#
# Start of layer definitions
#
LAYER
NAME "example"
PROJECTION
"init=epsg:4326" ##recommended
END
METADATA
"wms_title" "Example" ##required
END
STATUS OFF
TYPE POINT
CONNECTIONTYPE POSTGIS
CONNECTION "host=localhost port=5432 dbname=example user=example"
DATA "the_geog from example using srid=4326"
END # Layer
END # Map File

Workaround from http://d.hatena.ne.jp/yellow_73/20120221

Mapserver 6.0.4, when using CONNECTIONTYPE POSTGIS with a geography column results in the following error:

msPostGISLayerWhichShapes(): Query error. Error executing query: ERROR:  function st_force_2d(geography) does not exist
LINE 1: select encode(ST_AsBinary(ST_Force_2D("the_geog"),'NDR'),'he...
                                  ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Function ST_Force2D (also aliased as deprecated ST_Force_2D) supports only geometry parameters. After adding the st_force_2d(geography) function, mapserver no longer shows that error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment