From: Paul Ramsey Date: Sat, 10 Oct 2009 03:18:28 +0000 (+0000) Subject: Add geometry(geography) case per #257 X-Git-Tag: 1.5.0b1~378 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb2d7d7f741d78934ffa6644a9839721b8523177;p=postgis Add geometry(geography) case per #257 git-svn-id: http://svn.osgeo.org/postgis/trunk@4637 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/geography.sql.in.c b/postgis/geography.sql.in.c index e40f4601f..ca4417c17 100644 --- a/postgis/geography.sql.in.c +++ b/postgis/geography.sql.in.c @@ -173,6 +173,15 @@ CREATE OR REPLACE FUNCTION geography(geometry) -- Availability: 1.5.0 CREATE CAST (geometry AS geography) WITH FUNCTION geography(geometry) AS IMPLICIT; +-- Availability: 1.5.0 +CREATE OR REPLACE FUNCTION geometry(geography) + RETURNS geometry + AS 'MODULE_PATHNAME','geometry_from_geography' + LANGUAGE 'C' IMMUTABLE STRICT; + +-- Availability: 1.5.0 +CREATE CAST (geography AS geometry) WITH FUNCTION geometry(geography) AS IMPLICIT; + -- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -- GiST Support Functions -- ---------- ---------- ---------- ---------- ---------- ---------- ---------- diff --git a/postgis/geography_inout.c b/postgis/geography_inout.c index de28a26b5..95bd39e59 100644 --- a/postgis/geography_inout.c +++ b/postgis/geography_inout.c @@ -48,6 +48,7 @@ Datum geography_as_svg(PG_FUNCTION_ARGS); Datum geography_as_binary(PG_FUNCTION_ARGS); Datum geography_from_binary(PG_FUNCTION_ARGS); Datum geography_from_geometry(PG_FUNCTION_ARGS); +Datum geometry_from_geography(PG_FUNCTION_ARGS); /* Datum geography_gist_selectivity(PG_FUNCTION_ARGS); TBD */ /* Datum geography_gist_join_selectivity(PG_FUNCTION_ARGS); TBD */ @@ -932,3 +933,22 @@ Datum geography_from_geometry(PG_FUNCTION_ARGS) } +PG_FUNCTION_INFO_V1(geometry_from_geography); +Datum geometry_from_geography(PG_FUNCTION_ARGS) +{ + LWGEOM *lwgeom = NULL; + PG_LWGEOM *ret = NULL; + GSERIALIZED *g_ser = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + + lwgeom = lwgeom_from_gserialized(g_ser); + ret = pglwgeom_serialize(lwgeom); + lwgeom_release(lwgeom); + + if ( is_worth_caching_pglwgeom_bbox(ret) ) + { + ret = (PG_LWGEOM *)DatumGetPointer(DirectFunctionCall1(LWGEOM_addBBOX, PointerGetDatum(ret))); + } + + PG_RETURN_POINTER(ret); +} +