[postgis-commits] svn - r3678 - spike/wktraster/rt_pg
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Tue Feb 10 03:25:51 PST 2009
Author: strk
Date: 2009-02-10 03:25:51 -0800 (Tue, 10 Feb 2009)
New Revision: 3678
Modified:
spike/wktraster/rt_pg/rt_pg.c
Log:
Implement rt_envelope (SQL)
Modified: spike/wktraster/rt_pg/rt_pg.c
===================================================================
--- spike/wktraster/rt_pg/rt_pg.c 2009-02-10 08:00:39 UTC (rev 3677)
+++ spike/wktraster/rt_pg/rt_pg.c 2009-02-10 11:25:51 UTC (rev 3678)
@@ -67,6 +67,7 @@
Datum RASTER_in(PG_FUNCTION_ARGS);
Datum RASTER_out(PG_FUNCTION_ARGS);
Datum RASTER_to_BOX2DFLOAT4(PG_FUNCTION_ARGS);
+Datum RASTER_envelope(PG_FUNCTION_ARGS);
Datum RASTER_makeEmpty(PG_FUNCTION_ARGS);
Datum RASTER_to_LWGEOM(PG_FUNCTION_ARGS);
@@ -272,6 +273,49 @@
}
/**
+ * Return the envelope of this raster as a 4-vertices POLYGON.
+ */
+PG_FUNCTION_INFO_V1(RASTER_envelope);
+Datum RASTER_envelope(PG_FUNCTION_ARGS)
+{
+ rt_pgraster *pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+ rt_raster raster;
+ rt_context ctx = get_rt_context(fcinfo);
+ LWPOLY* envelope;
+ uchar* pglwgeom;
+
+ { /* TODO: can be optimized to only detoast the header! */
+ raster = rt_raster_deserialize(ctx, pgraster);
+ if ( ! raster ) {
+ elog(ERROR, "Could not deserialize raster");
+ PG_RETURN_NULL();
+ }
+
+ /*elog(NOTICE, "rt_raster_deserialize returned %p", raster);*/
+
+ envelope = rt_raster_get_envelope(ctx, raster);
+ if ( ! envelope ) {
+ elog(ERROR, "Could not get raster's envelope");
+ PG_RETURN_NULL();
+ }
+ }
+
+ {
+ size_t sz = lwpoly_serialize_size(envelope);
+ pglwgeom = palloc(VARHDRSZ+sz);
+ lwpoly_serialize_buf(envelope, VARDATA(pglwgeom), &sz);
+ SET_VARSIZE(pglwgeom, VARHDRSZ+sz);
+ }
+
+ /* PG_FREE_IF_COPY(pgraster, 0); */
+ /* lwfree(envelope) */
+ /* ... more deallocs ... */
+
+
+ PG_RETURN_POINTER(pglwgeom);
+}
+
+/**
* Return the bounding box of this raster as a BOX2D.
*/
PG_FUNCTION_INFO_V1(RASTER_to_BOX2DFLOAT4);
More information about the postgis-commits
mailing list