]> granicus.if.org Git - postgis/commitdiff
Add geometry(geography) case per #257
authorPaul Ramsey <pramsey@cleverelephant.ca>
Sat, 10 Oct 2009 03:18:28 +0000 (03:18 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Sat, 10 Oct 2009 03:18:28 +0000 (03:18 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@4637 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/geography.sql.in.c
postgis/geography_inout.c

index e40f4601f010d44701b6c8a8d3657fe71c9b8f21..ca4417c17fa396adc69c4b8d48f229e9d3a2dfdb 100644 (file)
@@ -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
 -- ---------- ---------- ---------- ---------- ---------- ---------- ----------
index de28a26b585e6b41a11402f2932ee002a775c2c0..95bd39e595bf352234503f7e0744d017d0e87d81 100644 (file)
@@ -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); 
+}
+