return TRUE;
}
-struct rt_bandstats_t {
- double sample;
- uint32_t count;
-
- double min;
- double max;
- double sum;
- double mean;
- double stddev;
-
- double *values;
- int sorted; /* flag indicating that values is sorted ascending by value */
-};
-
/**
* Compute summary statistics for a band
*
return stats;
}
-struct rt_histogram_t {
- uint32_t count;
- double percent;
-
- double min;
- double max;
-
- int inc_min;
- int inc_max;
-};
-
/**
* Count the distribution of data
*
return bins;
}
-struct rt_quantile_t {
- double quantile;
- double value;
-};
-
/**
* Compute the default set of or requested quantiles for a set of data
* the quantile formula used is same as Excel and R default method
/* symmetrical rounding */
#define ROUND(x, y) (((x > 0.0) ? floor((x * pow(10, y) + 0.5)) : ceil((x * pow(10, y) - 0.5))) / pow(10, y));
-struct rt_valuecount_t {
- double value;
- uint32_t count;
- double percent;
-};
-
/**
* Count the number of times provided value(s) occur in
* the band
return vcnts;
}
-struct rt_reclassexpr_t {
- struct rt_reclassrange {
- double min;
- double max;
- int inc_min; /* include min */
- int inc_max; /* include max */
- int exc_min; /* exceed min */
- int exc_max; /* exceed max */
- } src, dst;
-};
-
/**
* Returns new band with values reclassified
*
/*- rt_raster --------------------------------------------------------*/
-struct rt_raster_serialized_t {
- /*---[ 8 byte boundary ]---{ */
- uint32_t size; /* required by postgresql: 4 bytes */
- uint16_t version; /* format version (this is version 0): 2 bytes */
- uint16_t numBands; /* Number of bands: 2 bytes */
-
- /* }---[ 8 byte boundary ]---{ */
- double scaleX; /* pixel width: 8 bytes */
-
- /* }---[ 8 byte boundary ]---{ */
- double scaleY; /* pixel height: 8 bytes */
-
- /* }---[ 8 byte boundary ]---{ */
- double ipX; /* insertion point X: 8 bytes */
-
- /* }---[ 8 byte boundary ]---{ */
- double ipY; /* insertion point Y: 8 bytes */
-
- /* }---[ 8 byte boundary ]---{ */
- double skewX; /* skew about the X axis: 8 bytes */
-
- /* }---[ 8 byte boundary ]---{ */
- double skewY; /* skew about the Y axis: 8 bytes */
-
- /* }---[ 8 byte boundary ]--- */
- int32_t srid; /* Spatial reference id: 4 bytes */
- uint16_t width; /* pixel columns: 2 bytes */
- uint16_t height; /* pixel rows: 2 bytes */
-};
-
-/* NOTE: the initial part of this structure matches the layout
- * of data in the serialized form version 0, starting
- * from the numBands element
- */
-struct rt_raster_t {
- uint32_t size;
- uint16_t version;
-
- /* Number of bands, all share the same dimension
- * and georeference */
- uint16_t numBands;
-
- /* Georeference (in projection units) */
- double scaleX; /* pixel width */
- double scaleY; /* pixel height */
- double ipX; /* geo x ordinate of the corner of upper-left pixel */
- double ipY; /* geo y ordinate of the corner of bottom-right pixel */
- double skewX; /* skew about the X axis*/
- double skewY; /* skew about the Y axis */
-
- int32_t srid; /* spatial reference id */
- uint16_t width; /* pixel columns - max 65535 */
- uint16_t height; /* pixel rows - max 65535 */
- rt_band *bands; /* actual bands */
-
-};
-
rt_raster
rt_raster_new(uint16_t width, uint16_t height) {
rt_raster ret = NULL;
}
-/* WKT string representing each polygon in WKT format acompagned by its
-correspoding value */
-struct rt_geomval_t {
- int srid;
- double val;
- char * geom;
-};
-
rt_geomval
rt_raster_dump_as_wktpolygons(rt_raster raster, int nband, int * pnElements)
{
return rtn;
}
-struct rt_gdaldriver_t {
- int idx;
- char *short_name;
- char *long_name;
- char *create_options;
-};
-
/**
* Returns a set of available GDAL drivers
*
*
**/
-
/**
* Types definitions
*/
typedef struct rt_raster_t* rt_raster;
typedef struct rt_band_t* rt_band;
typedef struct rt_geomval_t* rt_geomval;
+typedef struct rt_bandstats_t* rt_bandstats;
+typedef struct rt_histogram_t* rt_histogram;
+typedef struct rt_quantile_t* rt_quantile;
+typedef struct rt_valuecount_t* rt_valuecount;
+typedef struct rt_gdaldriver_t* rt_gdaldriver;
+typedef struct rt_reclassexpr_t* rt_reclassexpr;
+
+
+/**
+ * Struct definitions
+ *
+ * These structs are defined here as they are needed elsewhere
+ * including rt_pg/rt_pg.c and reduce duplicative declarations
+ *
+ */
+struct rt_raster_serialized_t {
+ /*---[ 8 byte boundary ]---{ */
+ uint32_t size; /* required by postgresql: 4 bytes */
+ uint16_t version; /* format version (this is version 0): 2 bytes */
+ uint16_t numBands; /* Number of bands: 2 bytes */
+
+ /* }---[ 8 byte boundary ]---{ */
+ double scaleX; /* pixel width: 8 bytes */
+
+ /* }---[ 8 byte boundary ]---{ */
+ double scaleY; /* pixel height: 8 bytes */
+
+ /* }---[ 8 byte boundary ]---{ */
+ double ipX; /* insertion point X: 8 bytes */
+
+ /* }---[ 8 byte boundary ]---{ */
+ double ipY; /* insertion point Y: 8 bytes */
+
+ /* }---[ 8 byte boundary ]---{ */
+ double skewX; /* skew about the X axis: 8 bytes */
+
+ /* }---[ 8 byte boundary ]---{ */
+ double skewY; /* skew about the Y axis: 8 bytes */
+
+ /* }---[ 8 byte boundary ]--- */
+ int32_t srid; /* Spatial reference id: 4 bytes */
+ uint16_t width; /* pixel columns: 2 bytes */
+ uint16_t height; /* pixel rows: 2 bytes */
+};
+
+/* NOTE: the initial part of this structure matches the layout
+ * of data in the serialized form version 0, starting
+ * from the numBands element
+ */
+struct rt_raster_t {
+ uint32_t size;
+ uint16_t version;
+
+ /* Number of bands, all share the same dimension
+ * and georeference */
+ uint16_t numBands;
+
+ /* Georeference (in projection units) */
+ double scaleX; /* pixel width */
+ double scaleY; /* pixel height */
+ double ipX; /* geo x ordinate of the corner of upper-left pixel */
+ double ipY; /* geo y ordinate of the corner of bottom-right pixel */
+ double skewX; /* skew about the X axis*/
+ double skewY; /* skew about the Y axis */
+
+ int32_t srid; /* spatial reference id */
+ uint16_t width; /* pixel columns - max 65535 */
+ uint16_t height; /* pixel rows - max 65535 */
+ rt_band *bands; /* actual bands */
+
+};
+
+/* WKT string representing each polygon in WKT format acompagned by its
+correspoding value */
+struct rt_geomval_t {
+ int srid;
+ double val;
+ char * geom;
+};
+
+/* summary stats of specified band */
+struct rt_bandstats_t {
+ double sample;
+ uint32_t count;
+
+ double min;
+ double max;
+ double sum;
+ double mean;
+ double stddev;
+
+ double *values;
+ int sorted; /* flag indicating that values is sorted ascending by value */
+};
+
+/* histogram bin(s) of specified band */
+struct rt_histogram_t {
+ uint32_t count;
+ double percent;
+
+ double min;
+ double max;
+
+ int inc_min;
+ int inc_max;
+};
+
+/* quantile(s) of the specified band */
+struct rt_quantile_t {
+ double quantile;
+ double value;
+};
+
+/* number of times a value occurs */
+struct rt_valuecount_t {
+ double value;
+ uint32_t count;
+ double percent;
+};
+
+/* reclassification expression */
+struct rt_reclassexpr_t {
+ struct rt_reclassrange {
+ double min;
+ double max;
+ int inc_min; /* include min */
+ int inc_max; /* include max */
+ int exc_min; /* exceed min */
+ int exc_max; /* exceed max */
+ } src, dst;
+};
+
+/* gdal driver information */
+struct rt_gdaldriver_t {
+ int idx;
+ char *short_name;
+ char *long_name;
+ char *create_options;
+};
/**
* Global functions for memory/logging handlers.
*
* @return the summary statistics for a band
*/
-typedef struct rt_bandstats_t* rt_bandstats;
rt_bandstats rt_band_get_summary_stats(rt_band band, int exclude_nodata_value,
double sample, int inc_vals, uint64_t *cK, double *cM, double *cQ);
*
* @return the histogram of the data
*/
-typedef struct rt_histogram_t* rt_histogram;
rt_histogram rt_band_get_histogram(rt_bandstats stats,
int bin_count, double *bin_widths, int bin_widths_count,
int right, double min, double max, int *rtn_count);
*
* @return the default set of or requested quantiles for a band
*/
-typedef struct rt_quantile_t* rt_quantile;
rt_quantile rt_band_get_quantiles(rt_bandstats stats,
double *quantiles, int quantiles_count, int *rtn_count);
*
* @return the default set of or requested quantiles for a band
*/
-typedef struct rt_valuecount_t* rt_valuecount;
rt_valuecount rt_band_get_value_count(rt_band band, int exclude_nodata_value,
double *search_values, uint32_t search_values_count,
double roundto, int *rtn_count);
*
* @return a new rt_band or 0 on error
*/
-typedef struct rt_reclassexpr_t* rt_reclassexpr;
rt_band rt_band_reclass(rt_band srcband, rt_pixtype pixtype,
uint32_t hasnodata, double nodataval,
rt_reclassexpr *exprset, int exprcount);
*
* @return set of "gdaldriver" values of available GDAL drivers
*/
-typedef struct rt_gdaldriver_t* rt_gdaldriver;
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count);
/**
#define MAX_DBL_CHARLEN (3 + DBL_MANT_DIG - DBL_MIN_EXP)
#define MAX_INT_CHARLEN 32
-/* size of rt_raster_serialized_t */
-struct rt_raster_serialized_t {
- uint32_t size;
- uint16_t version;
- uint16_t numBands;
- double scaleX;
- double scaleY;
- double ipX;
- double ipY;
- double skewX;
- double skewY;
- int32_t srid;
- uint16_t width;
- uint16_t height;
-};
-
-#define RT_RASTER_SERIALIZED_T_LEN sizeof(struct rt_raster_serialized_t)
-
/*
* This is required for builds against pgsql 8.2
*/
uchar* pglwgeom;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
{
raster = rt_raster_deserialize(pgraster, TRUE);
}
-/**
- * Needed for sizeof
- */
-struct rt_geomval_t {
- int srid;
- double val;
- char * geom;
-};
-
-
PG_FUNCTION_INFO_V1(RASTER_dumpAsWKTPolygons);
Datum RASTER_dumpAsWKTPolygons(PG_FUNCTION_ARGS)
{
int32_t srid;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster ) {
uint16_t width;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster ) {
uint16_t height;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster ) {
int32_t num_bands;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster ) {
double xsize;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster ) {
double ysize;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster ) {
double xskew;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster ) {
double yskew;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster ) {
double xul;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster ) {
double yul;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster ) {
/* Deserialize raster */
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster )
/* Deserialize raster */
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(pgraster, TRUE);
if ( ! raster )
PG_RETURN_POINTER(pgraster);
}
-struct rt_bandstats_t {
- double sample;
- uint32_t count;
-
- double min;
- double max;
- double sum;
- double mean;
- double stddev;
-
- double *values;
- int sorted;
-};
-
/**
* Get summary stats of a band
*/
PG_RETURN_DATUM(result);
}
-/* get histogram */
-struct rt_histogram_t {
- uint32_t count;
- double percent;
-
- double min;
- double max;
-
- int inc_min;
- int inc_max;
-};
-
/**
* Returns histogram for a band
*/
}
}
-/* get quantiles */
-struct rt_quantile_t {
- double quantile;
- double value;
-};
-
/**
* Returns quantiles for a band
*/
}
}
-struct rt_valuecount_t {
- double value;
- uint32_t count;
- double percent;
-};
-
/* get counts of values */
PG_FUNCTION_INFO_V1(RASTER_valueCount);
Datum RASTER_valueCount(PG_FUNCTION_ARGS) {
}
}
-struct rt_reclassexpr_t {
- struct rt_reclassrange {
- double min;
- double max;
- int inc_min;
- int inc_max;
- int exc_min;
- int exc_max;
- } src, dst;
-};
-
/**
* Reclassify the specified bands of the raster
*/
PG_RETURN_POINTER(result);
}
-/**
- * Needed for sizeof
- */
-struct rt_gdaldriver_t {
- int idx;
- char *short_name;
- char *long_name;
- char *create_options;
-};
-
/**
* Returns available GDAL drivers
*/
/* pgraster is null, return null */
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
- pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, RT_RASTER_SERIALIZED_T_LEN);
+ pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
/* raster */
raster = rt_raster_deserialize(pgraster, TRUE);
rt_raster_destroy(rast);
}
-struct rt_bandstats_t {
- double sample;
- uint32_t count;
-
- double min;
- double max;
- double sum;
- double mean;
- double stddev;
-
- double *values;
- int sorted;
-};
-struct rt_histogram_t {
- uint32_t count;
- double percent;
-
- double min;
- double max;
-
- int inc_min;
- int inc_max;
-};
-struct rt_quantile_t {
- double quantile;
- double value;
-};
static void testBandStats() {
rt_bandstats stats = NULL;
rt_histogram histogram = NULL;
if (mem) rtdealloc(mem);
}
-struct rt_reclassexpr_t {
- struct rt_reclassrange {
- double min;
- double max;
- int inc_min; /* include min */
- int inc_max; /* include max */
- int exc_min; /* exceed min */
- int exc_max; /* exceed max */
- } src, dst;
-};
static void testBandReclass() {
rt_reclassexpr *exprset;
rt_band_destroy(newband);
}
-struct rt_gdaldriver_t {
- int idx;
- char *short_name;
- char *long_name;
- char *create_options;
-};
static void testGDALDrivers() {
int i;
uint32_t size;
deepRelease(raster);
}
-struct rt_valuecount_t {
- double value;
- uint32_t count;
- double percent;
-};
static void testValueCount() {
rt_valuecount vcnts = NULL;
/* We can check rt_raster_has_no_band here too */
CHECK(!rt_raster_has_no_band(rt, 1));
- /**
- * Need to define again, to access the struct fields
- **/
- struct rt_geomval_t {
- int srid;
- double val;
- char * geom;
- };
-
- typedef struct rt_geomval_t* rt_geomval;
int nPols = 0;
rt_geomval gv = (rt_geomval) rt_raster_dump_as_wktpolygons(rt, 1, &nPols);