[postgis-commits] svn - r3672 - spike/wktraster/rt_pg
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Mon Feb 9 07:54:54 PST 2009
Author: strk
Date: 2009-02-09 07:54:54 -0800 (Mon, 09 Feb 2009)
New Revision: 3672
Modified:
spike/wktraster/rt_pg/rt_pg.c
Log:
Implement rt_MakeEmptyRaster, useful for testing ops (part of this was the last commit for the sql enabler, sorry for commit split)
Modified: spike/wktraster/rt_pg/rt_pg.c
===================================================================
--- spike/wktraster/rt_pg/rt_pg.c 2009-02-09 15:53:33 UTC (rev 3671)
+++ spike/wktraster/rt_pg/rt_pg.c 2009-02-09 15:54:54 UTC (rev 3672)
@@ -42,8 +42,8 @@
#include "../wktraster_config.h"
-/* Define this to debug RASTER ops */
-//#define RT_DEBUG 1
+/* Define this to debug pgsql RASTER activity */
+#define RT_PG_DEBUG 1
//#define RT_PG_DEBUG_MEM 1
@@ -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_makeEmpty(PG_FUNCTION_ARGS);
Datum RASTER_to_LWGEOM(PG_FUNCTION_ARGS);
Datum RASTER_getSRID(PG_FUNCTION_ARGS);
@@ -307,6 +308,63 @@
PG_RETURN_POINTER(bbox);
}
+/**
+ * rt_MakeEmptyRaster( <width>, <height>, <ipx>, <ipy>,
+ * <scalex>, <scaley>,
+ * <skewx>, <skewy>,
+ * <srid>)
+ */
+PG_FUNCTION_INFO_V1(RASTER_makeEmpty);
+Datum RASTER_makeEmpty(PG_FUNCTION_ARGS)
+{
+ uint16 width, height;
+ double ipx, ipy, scalex, scaley, skewx, skewy;
+ int32 srid;
+ rt_pgraster *pgraster;
+ rt_raster raster;
+ rt_context ctx;
+
+ if ( PG_NARGS() < 9 )
+ {
+ elog(ERROR, "MakeEmptyRaster requires 9 args");
+ PG_RETURN_NULL();
+ }
+
+ width = PG_GETARG_UINT16(0);
+ height = PG_GETARG_UINT16(1);
+ ipx = PG_GETARG_FLOAT8(2);
+ ipy = PG_GETARG_FLOAT8(3);
+ scalex = PG_GETARG_FLOAT8(4);
+ scaley = PG_GETARG_FLOAT8(5);
+ skewx = PG_GETARG_FLOAT8(6);
+ skewy = PG_GETARG_FLOAT8(7);
+ srid = PG_GETARG_INT32(8);
+
+#ifdef RT_PG_DEBUG
+ elog(NOTICE, "%dx%d, ip:%g,%g, scale:%g,%g, skew:%g,%g srid:%d",
+ width, height, ipx, ipy, scalex, scaley,
+ skewx, skewy, srid);
+#endif
+
+ ctx = get_rt_context(fcinfo);
+
+ raster = rt_raster_new(ctx, width, height);
+ if ( ! raster ) {
+ PG_RETURN_NULL(); /* error was supposedly printed already */
+ }
+
+ rt_raster_set_pixel_sizes(ctx, raster, scalex, scaley);
+ rt_raster_set_offsets(ctx, raster, ipx, ipy);
+ rt_raster_set_rotations(ctx, raster, skewx, skewy);
+ rt_raster_set_srid(ctx, raster, srid);
+
+ pgraster = rt_raster_serialize(ctx, raster);
+ if ( ! pgraster ) PG_RETURN_NULL();
+
+ SET_VARSIZE(pgraster, pgraster->size);
+ PG_RETURN_POINTER(pgraster);
+}
+
/* ---------------------------------------------------------------- */
/* Memory allocation / error reporting hooks */
/* ---------------------------------------------------------------- */
More information about the postgis-commits
mailing list