-- 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
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
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 */
}
+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);
+}
+