PG_RETURN_INT64(fileSize);
}
+#define VALUES_LENGTH 8
+
/**
* Get raster bands' meta data
*/
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 8;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = UInt32GetDatum(bmd2[call_cntr].bandnum);
values[1] = CStringGetTextDatum(bmd2[call_cntr].pixeltype);
PG_RETURN_POINTER(result);
}
+#define VALUES_LENGTH 6
+
/**
* Returns available GDAL drivers
*/
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 6;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Int32GetDatum(drv_set2[call_cntr].idx);
values[1] = CStringGetTextDatum(drv_set2[call_cntr].short_name);
PG_RETURN_POINTER(gser);
}
+#define VALUES_LENGTH 2
+
PG_FUNCTION_INFO_V1(RASTER_dumpAsPolygons);
Datum RASTER_dumpAsPolygons(PG_FUNCTION_ARGS) {
FuncCallContext *funcctx;
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "call number %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* convert LWGEOM to GSERIALIZED */
gser = gserialized_from_lwgeom(lwpoly_as_lwgeom(geomval2[call_cntr].geom), &gser_size);
}
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 4
+
/**
* Return the geographical shape of all pixels
*/
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 4;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "call number %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* convert LWGEOM to GSERIALIZED */
gser = gserialized_from_lwgeom(pix2[call_cntr].geom, &gser_size);
PG_RETURN_POINTER(pgrtn);
}
+#define ARGKWCOUNT 8
+
/**
* Two raster MapAlgebra
*/
SPIPlanPtr spi_plan[3] = {NULL};
uint16_t spi_empty = 0;
Oid *argtype = NULL;
- const uint32_t argkwcount = 8;
uint8_t argpos[3][8] = {{0}};
char *argkw[] = {"[rast1.x]", "[rast1.y]", "[rast1.val]", "[rast1]", "[rast2.x]", "[rast2.y]", "[rast2.val]", "[rast2]"};
- Datum values[argkwcount];
- char nulls[argkwcount];
+ Datum values[ARGKWCOUNT];
+ char nulls[ARGKWCOUNT];
TupleDesc tupdesc;
SPITupleTable *tuptable = NULL;
HeapTuple tuple;
expr = text_to_cstring(PG_GETARG_TEXT_P(spi_exprpos[i]));
POSTGIS_RT_DEBUGF(3, "raw expr #%d: %s", i, expr);
- for (j = 0, k = 1; j < argkwcount; j++) {
+ for (j = 0, k = 1; j < ARGKWCOUNT; j++) {
/* attempt to replace keyword with placeholder */
len = 0;
tmp = rtpg_strreplace(expr, argkw[j], place, &len);
}
/* specify datatypes of parameters */
- for (j = 0, k = 0; j < argkwcount; j++) {
+ for (j = 0, k = 0; j < ARGKWCOUNT; j++) {
if (argpos[i][j] < 1) continue;
/* positions are INT4 */
POSTGIS_RT_DEBUGF(4, "Using prepared plan: %d", i);
/* reset values to (Datum) NULL */
- memset(values, (Datum) NULL, sizeof(Datum) * argkwcount);
+ memset(values, (Datum) NULL, sizeof(Datum) * ARGKWCOUNT);
/* reset nulls to FALSE */
- memset(nulls, FALSE, sizeof(char) * argkwcount);
+ memset(nulls, FALSE, sizeof(char) * ARGKWCOUNT);
/* expression has argument(s) */
if (spi_argcount[i]) {
/* set values and nulls */
- for (j = 0; j < argkwcount; j++) {
+ for (j = 0; j < ARGKWCOUNT; j++) {
idx = argpos[i][j];
if (idx < 1) continue;
idx--; /* 1-based becomes 0-based */
pfree(arg);
}
+#define VALUES_LENGTH 2
+
PG_FUNCTION_INFO_V1(RASTER_dumpValues);
Datum RASTER_dumpValues(PG_FUNCTION_ARGS)
{
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
ArrayType *mdValues = NULL;
POSTGIS_RT_DEBUGF(3, "call number %d", call_cntr);
POSTGIS_RT_DEBUGF(4, "dim = %d, %d", dim[0], dim[1]);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Int32GetDatum(arg2->nbands[call_cntr] + 1);
PG_RETURN_POINTER(pgrtn);
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 3
+
/**
* Get pixels of value
*/
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 3;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* 0-based to 1-based */
pixels2[call_cntr].x += 1;
PG_RETURN_FLOAT8(pheight);
}
+#define VALUES_LENGTH 6
+
/**
* Calculates the physically relevant parameters of the supplied raster's
* geotransform. Returns them as a set.
*/
TupleDesc result_tuple; /* for returning a composite */
- int values_length = 6;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple heap_tuple ; /* instance of the tuple to return */
Datum result;
values[4] = Float8GetDatum(rt_raster_get_x_offset(raster));
values[5] = Float8GetDatum(rt_raster_get_y_offset(raster));
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* stick em on the heap */
heap_tuple = heap_form_tuple(result_tuple, values, nulls);
PG_RETURN_BOOL(hasnoband);
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 10
+
/**
* Get raster's meta data
*/
uint32_t height;
TupleDesc tupdesc;
- int values_length = 10;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
values[8] = Int32GetDatum(srid);
values[9] = UInt32GetDatum(numBands);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* build a tuple */
tuple = heap_form_tuple(tupdesc, values, nulls);
PG_RETURN_DATUM(result);
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 2
+
PG_FUNCTION_INFO_V1(RASTER_rasterToWorldCoord);
Datum RASTER_rasterToWorldCoord(PG_FUNCTION_ARGS)
{
double cw[2] = {0};
TupleDesc tupdesc;
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
values[0] = Float8GetDatum(cw[0]);
values[1] = Float8GetDatum(cw[1]);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* build a tuple */
tuple = heap_form_tuple(tupdesc, values, nulls);
bool skewed = false;
TupleDesc tupdesc;
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
values[0] = Int32GetDatum(cr[0]);
values[1] = Int32GetDatum(cr[1]);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* build a tuple */
tuple = heap_form_tuple(tupdesc, values, nulls);
Datum RASTER_valueCount(PG_FUNCTION_ARGS);
Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS);
+#define VALUES_LENGTH 6
+
/**
* Get summary stats of a band
*/
rt_bandstats stats = NULL;
TupleDesc tupdesc;
- int values_length = 6;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
BlessTupleDesc(tupdesc);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Int64GetDatum(stats->count);
if (stats->count > 0) {
rt_bandstats stats = NULL;
rt_bandstats rtn = NULL;
- int values_length = 6;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
Datum result;
/* tablename is null, return null */
BlessTupleDesc(tupdesc);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Int64GetDatum(rtn->count);
if (rtn->count > 0) {
TupleDesc tupdesc;
HeapTuple tuple;
- int values_length = 6;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
Datum result;
POSTGIS_RT_DEBUG(3, "Starting...");
BlessTupleDesc(tupdesc);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Int64GetDatum(state->stats->count);
if (state->stats->count > 0) {
PG_RETURN_DATUM(result);
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 4
+
/**
* Returns histogram for a band
*/
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 4;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(hist2[call_cntr].min);
values[1] = Float8GetDatum(hist2[call_cntr].max);
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 4;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(covhist2[call_cntr].min);
values[1] = Float8GetDatum(covhist2[call_cntr].max);
}
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 2
+
/**
* Returns quantiles for a band
*/
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(quant2[call_cntr].quantile);
values[1] = Float8GetDatum(quant2[call_cntr].value);
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(covquant2[call_cntr].quantile);
if (covquant2[call_cntr].has_value)
}
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 3
+
/* get counts of values */
PG_FUNCTION_INFO_V1(RASTER_valueCount);
Datum RASTER_valueCount(PG_FUNCTION_ARGS) {
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 3;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(vcnts2[call_cntr].value);
values[1] = UInt32GetDatum(vcnts2[call_cntr].count);
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 3;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(covvcnts2[call_cntr].value);
values[1] = UInt32GetDatum(covvcnts2[call_cntr].count);