va_end(ap);
}
-
+
void
default_rt_warning_handler(const char *fmt, va_list ap) {
-
+
static const char *label = "WARNING: ";
char newfmt[1024] = {0};
snprintf(newfmt, 1024, "%s%s\n", label, fmt);
newfmt[1023] = '\0';
-
+
vprintf(newfmt, ap);
-
+
va_end(ap);
}
char newfmt[1024] = {0};
snprintf(newfmt, 1024, "%s%s\n", label, fmt);
newfmt[1023] = '\0';
-
+
vprintf(newfmt, ap);
va_end(ap);
ctx_t.dealloc = default_rt_deallocator;
ctx_t.err = default_rt_error_handler;
ctx_t.info = default_rt_info_handler;
- ctx_t.warn = default_rt_warning_handler;
+ ctx_t.warn = default_rt_warning_handler;
}
*/
void
rt_set_handlers(rt_allocator allocator, rt_reallocator reallocator,
- rt_deallocator deallocator, rt_message_handler error_handler,
+ rt_deallocator deallocator, rt_message_handler error_handler,
rt_message_handler info_handler, rt_message_handler warning_handler) {
ctx_t.alloc = allocator;
}
-
+
/**
* Initialisation allocators
*
- * These are used the first time any of the allocators are called to enable
- * executables/libraries that link into raster to be able to set up their own
- * allocators. This is mainly useful for older PostgreSQL versions that don't
+ * These are used the first time any of the allocators are called to enable
+ * executables/libraries that link into raster to be able to set up their own
+ * allocators. This is mainly useful for older PostgreSQL versions that don't
* have functions that are called upon startup.
**/
void *
return ctx_t.alloc(size);
}
-
+
void
init_rt_deallocator(void *mem)
{
rt_init_allocators();
-
+
ctx_t.dealloc(mem);
}
-
+
void *
init_rt_reallocator(void *mem, size_t size)
{
return ctx_t.realloc(mem, size);
}
-
+
void
init_rt_inforeporter(const char *fmt, va_list ap)
{
rt_init_allocators();
-
+
(*ctx_t.info)(fmt, ap);
}
-
+
void
init_rt_warnreporter(const char *fmt, va_list ap)
{
rt_init_allocators();
-
+
(*ctx_t.warn)(fmt, ap);
}
-
+
void
init_rt_errorreporter(const char *fmt, va_list ap)
{
/**
- * Raster core memory management functions.
- *
+ * Raster core memory management functions.
+ *
* They use the functions defined by the caller.
- */
+ */
void *
rtalloc(size_t size) {
void * mem = ctx_t.alloc(size);
rt_pixtype pixtype) {
int result = 0;
-
+
switch (pixtype)
{
char* hex = NULL;
uint32_t i = 0;
-
+
assert(NULL != raw);
assert(NULL != hexsize);
-
+
*hexsize = size * 2; /* hex is 2 times bytes */
hex = (char*) rtalloc((*hexsize) + 1);
char* hex = NULL;
uint32_t hexsize = 0;
-
+
assert(NULL != msg);
assert(NULL != raw);
-
+
hex = d_binary_to_hex(raw, size, &hexsize);
if (NULL != hex) {
int
rt_pixtype_size(rt_pixtype pixtype) {
int pixbytes = -1;
-
-
+
+
switch (pixtype) {
case PT_1BB:
int
rt_pixtype_alignment(rt_pixtype pixtype) {
-
+
return rt_pixtype_size(pixtype);
}
rt_pixtype
rt_pixtype_index_from_name(const char* pixname) {
assert(pixname && strlen(pixname) > 0);
-
+
if (strcmp(pixname, "1BB") == 0)
return PT_1BB;
const char*
rt_pixtype_name(rt_pixtype pixtype) {
-
-
+
+
switch (pixtype) {
case PT_1BB:
uint8_t* data) {
rt_band band = NULL;
-
+
assert(NULL != data);
band = rtalloc(sizeof (struct rt_band_t));
rt_pixtype pixtype, uint32_t hasnodata, double nodataval,
uint8_t bandNum, const char* path) {
rt_band band = NULL;
-
-
+
+
assert(NULL != path);
band = rtalloc(sizeof (struct rt_band_t));
int
rt_band_is_offline(rt_band band) {
-
+
assert(NULL != band);
-
+
return band->offline;
}
void
rt_band_destroy(rt_band band) {
-
-
+
+
RASTER_DEBUGF(3, "Destroying rt_band @ %p", band);
/* band->data content is externally owned */
const char*
rt_band_get_ext_path(rt_band band) {
-
+
assert(NULL != band);
-
+
if (!band->offline) {
RASTER_DEBUG(3, "rt_band_get_ext_path: non-offline band doesn't have "
uint8_t
rt_band_get_ext_band_num(rt_band band) {
-
+
assert(NULL != band);
-
+
if (!band->offline) {
RASTER_DEBUG(3, "rt_band_get_ext_path: non-offline band doesn't have "
void *
rt_band_get_data(rt_band band) {
-
+
assert(NULL != band);
-
+
if (band->offline) {
RASTER_DEBUG(3, "rt_band_get_data: "
rt_pixtype
rt_band_get_pixtype(rt_band band) {
-
+
assert(NULL != band);
-
+
return band->pixtype;
}
uint16_t
rt_band_get_width(rt_band band) {
-
+
assert(NULL != band);
-
+
return band->width;
}
uint16_t
rt_band_get_height(rt_band band) {
-
+
assert(NULL != band);
-
+
return band->height;
}
char mask = 0xFF >> (8 - bits);
char ival = val;
-
+
assert(8 - bitOffset >= bits);
RASTER_DEBUGF(4, "ival:%d bits:%d mask:%hhx bitoffset:%d\n",
int
rt_band_get_hasnodata_flag(rt_band band) {
-
+
assert(NULL != band);
-
+
return band->hasnodata;
}
void
rt_band_set_hasnodata_flag(rt_band band, int flag) {
-
+
assert(NULL != band);
-
+
band->hasnodata = (flag) ? 1 : 0;
}
void
rt_band_set_isnodata_flag(rt_band band, int flag) {
-
+
assert(NULL != band);
-
+
band->isnodata = (flag) ? 1 : 0;
}
int
rt_band_get_isnodata_flag(rt_band band) {
-
+
assert(NULL != band);
return band->isnodata;
float checkvalfloat = 0;
double checkvaldouble = 0;
-
-
+
+
assert(NULL != band);
pixtype = band->pixtype;
double checkval = 0;
-
-
+
+
assert(NULL != band);
pixtype = band->pixtype;
uint8_t* data = NULL;
uint32_t offset = 0;
-
-
+
+
assert(NULL != band);
pixtype = band->pixtype;
double
rt_band_get_nodata(rt_band band) {
-
-
+
+
assert(NULL != band);
if (!band->hasnodata)
rt_band_get_min_value(rt_band band) {
rt_pixtype pixtype = PT_END;
-
-
+
+
assert(NULL != band);
pixtype = band->pixtype;
switch (pixtype) {
- case PT_1BB:
- case PT_2BUI:
- case PT_4BUI:
+ case PT_1BB:
+ case PT_2BUI:
+ case PT_4BUI:
case PT_8BUI:
{
return (double)CHAR_MIN;
{
return (double)SCHAR_MIN;
}
- case PT_16BSI:
+ case PT_16BSI:
case PT_16BUI:
{
return (double)SHRT_MIN;
}
- case PT_32BSI:
+ case PT_32BSI:
case PT_32BUI:
{
return (double)INT_MIN;
double pxValue = band->nodataval;
double dEpsilon = 0.0;
-
-
+
+
assert(NULL != band);
/* Check if band has nodata value */
rt_raster_new(uint16_t width, uint16_t height) {
rt_raster ret = NULL;
-
-
+
+
ret = (rt_raster) rtalloc(sizeof (struct rt_raster_t));
if (!ret) {
rterror("rt_raster_new: Out of virtual memory creating an rt_raster");
void
rt_raster_destroy(rt_raster raster) {
-
-
+
+
RASTER_DEBUGF(3, "Destroying rt_raster @ %p", raster);
if (raster->bands) {
uint16_t
rt_raster_get_width(rt_raster raster) {
-
+
assert(NULL != raster);
return raster->width;
uint16_t
rt_raster_get_height(rt_raster raster) {
-
+
assert(NULL != raster);
return raster->height;
void
rt_raster_set_scale(rt_raster raster,
double scaleX, double scaleY) {
-
-
+
+
assert(NULL != raster);
raster->scaleX = scaleX;
double
rt_raster_get_x_scale(rt_raster raster) {
-
-
+
+
assert(NULL != raster);
return raster->scaleX;
double
rt_raster_get_y_scale(rt_raster raster) {
-
-
+
+
assert(NULL != raster);
return raster->scaleY;
void
rt_raster_set_skews(rt_raster raster,
double skewX, double skewY) {
-
-
+
+
assert(NULL != raster);
raster->skewX = skewX;
double
rt_raster_get_x_skew(rt_raster raster) {
-
-
+
+
assert(NULL != raster);
return raster->skewX;
double
rt_raster_get_y_skew(rt_raster raster) {
-
-
+
+
assert(NULL != raster);
return raster->skewY;
void
rt_raster_set_offsets(rt_raster raster, double x, double y) {
-
-
+
+
assert(NULL != raster);
raster->ipX = x;
double
rt_raster_get_x_offset(rt_raster raster) {
-
-
+
+
assert(NULL != raster);
return raster->ipX;
double
rt_raster_get_y_offset(rt_raster raster) {
-
-
+
+
assert(NULL != raster);
return raster->ipY;
int32_t
rt_raster_get_srid(rt_raster raster) {
-
-
+
+
assert(NULL != raster);
return raster->srid;
void
rt_raster_set_srid(rt_raster raster, int32_t srid) {
-
-
+
+
assert(NULL != raster);
raster->srid = srid;
int
rt_raster_get_num_bands(rt_raster raster) {
-
-
+
+
assert(NULL != raster);
return raster->numBands;
rt_band
rt_raster_get_band(rt_raster raster, int n) {
-
-
+
+
assert(NULL != raster);
if (n >= raster->numBands || n < 0) return 0;
rt_band tmpband = NULL;
uint16_t i = 0;
-
-
+
+
assert(NULL != raster);
RASTER_DEBUGF(3, "Adding band %p to raster %p", band, raster);
double checkvaldouble = 0;
float checkvalfloat = 0;
int i;
-
-
+
+
assert(NULL != raster);
/* Make sure index is in a valid range */
rt_raster_cell_to_geopoint(rt_raster raster,
double x, double y,
double* x1, double* y1) {
-
-
+
+
assert(NULL != raster);
assert(NULL != x1);
assert(NULL != y1);
double dBandNoData = 0.0;
/* Checkings */
-
-
+
+
assert(NULL != raster);
assert(nband > 0 && nband <= rt_raster_get_num_bands(raster));
GDALClose(memdataset);
GDALDeregisterDriver(gdal_drv);
GDALDestroyDriver(gdal_drv);
-
+
OGR_Fld_Destroy(hFldDfn);
OGR_DS_DeleteLayer(memdatasource, 0);
OGRReleaseDataSource(memdatasource);
RASTER_DEBUGF(4, "Feature %d, Polygon: %s", j, pols[j].geom);
RASTER_DEBUGF(4, "Feature %d, value: %f", j, pols[j].val);
RASTER_DEBUGF(4, "Feature %d, srid: %d", j, pols[j].srid);
-
+
/**
* We can't use deallocator from rt_context, because it comes from
* postgresql backend, that uses pfree. This function needs a
//rtdealloc(pszSrcText);
free(pszSrcText);
pszSrcText = NULL;
-
+
OGR_F_Destroy(hFeature);
}
LWPOLY* ret = NULL;
POINT4D p4d;
-
-
+
+
assert(NULL != raster);
RASTER_DEBUGF(3, "rt_raster_get_convex_hull: raster is %dx%d",
unsigned long sz = 0;
uint32_t v = 0;
-
-
+
+
assert(NULL != ptr);
assert(NULL != end);
uint16_t version = 0;
uint16_t i = 0;
-
-
+
+
assert(NULL != ptr);
/* Check that wkbsize is >= sizeof(rt_raster_serialized) */
uint32_t wkbsize = 0;
uint32_t i = 0;
-
-
+
+
assert(NULL != hexwkb);
RASTER_DEBUGF(3, "rt_raster_from_hexwkb: input wkb: %s", hexwkb);
uint32_t size = RT_WKB_HDR_SZ;
uint16_t i = 0;
-
-
+
+
assert(NULL != raster);
RASTER_DEBUGF(3, "rt_raster_wkb_size: computing size for %d bands",
uint16_t i = 0;
uint8_t littleEndian = isMachineLittleEndian();
-
-
+
+
assert(NULL != raster);
assert(NULL != wkbsize);
uint32_t i = 0;
uint32_t wkbsize = 0;
-
-
+
+
assert(NULL != raster);
assert(NULL != hexwkbsize);
uint32_t size = sizeof (struct rt_raster_serialized_t);
uint16_t i = 0;
-
-
+
+
assert(NULL != raster);
RASTER_DEBUGF(3, "Serialized size with just header:%d - now adding size of %d bands",
uint8_t* ptr = NULL;
uint16_t i = 0;
-
+
assert(NULL != raster);
ret = (uint8_t*) rtalloc(size);
uint16_t i = 0;
uint8_t littleEndian = isMachineLittleEndian();
-
-
+
+
assert(NULL != serialized);
RASTER_DEBUG(2, "rt_raster_deserialize: Entering...");
#if POSTGIS_DEBUG_LEVEL > 0
const uint8_t *padbeg = ptr;
#endif
- while (0 != ((ptr - beg) % 8))
- {
+ while (0 != ((ptr - beg) % 8)){
++ptr;
}
}
int rt_raster_is_empty(rt_raster raster) {
-
-
+
+
return (NULL == raster || raster->height <= 0 || raster->width <= 0);
}
int rt_raster_has_no_band(rt_raster raster, int nband) {
-
-
+
+
return (NULL == raster || raster->numBands < nband);
}
rt_raster fromrast, int fromindex, int toindex)
{
rt_band newband = NULL;
-
-
+
+
assert(NULL != torast);
assert(NULL != fromrast);
/***************************************************************
* Some rules for returning NOTICE or ERROR...
- *
+ *
* Send an ERROR like:
*
* elog(ERROR, "RASTER_out: Could not deserialize raster");
- *
+ *
* only when:
*
- * -something wrong happen with memory,
+ * -something wrong happen with memory,
* -a function got an invalid argument ('3BUI' as pixel type) so that no row can
* be processed
*
* when arguments (e.g. x, y, band) are NULL or out of range so that some or
* most rows can be processed anyway
*
- * in this case,
+ * in this case,
* for SET functions or function normally returning a modified raster, return
* the original raster
* for GET functions, return NULL
Datum RASTER_mapAlgebra(PG_FUNCTION_ARGS);
-/* Replace function taken from
+/* Replace function taken from
* http://ubuntuforums.org/showthread.php?s=aa6f015109fd7e4c7e30d2fd8b717497&t=141670&page=3
*/
/* ---------------------------------------------------------------------------
}
/**
- * Given a RASTER structure, convert it to Hex and put it in a string
+ * Given a RASTER structure, convert it to Hex and put it in a string
*/
PG_FUNCTION_INFO_V1(RASTER_out);
Datum RASTER_out(PG_FUNCTION_ARGS)
rt_raster raster = NULL;
uint32_t hexwkbsize = 0;
char *hexwkb = NULL;
-
+
pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
raster = rt_raster_deserialize(pgraster);
SET_VARSIZE(pglwgeom, VARHDRSZ+sz);
#endif
}
-
+
/* Free raster and lwgeom memory */
rt_raster_destroy(raster);
lwfree(convexhull);
}
POSTGIS_RT_DEBUGF(3, "raster dump, %d elements returned", nElements);
-
+
/* Store needed information */
funcctx->user_fctx = geomval;
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
-
+
PG_RETURN_INT32(num_bands);
}
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
-
+
PG_RETURN_FLOAT8(xsize);
}
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
-
+
PG_RETURN_FLOAT8(ysize);
}
SET_VARSIZE(pgraster, pgraster->size);
rt_raster_destroy(raster);
-
+
PG_RETURN_POINTER(pgraster);
}
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
-
+
PG_RETURN_FLOAT8(xskew);
}
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
-
+
PG_RETURN_FLOAT8(yskew);
}
SET_VARSIZE(pgraster, pgraster->size);
rt_raster_destroy(raster);
-
+
PG_RETURN_POINTER(pgraster);
}
SET_VARSIZE(pgraster, pgraster->size);
rt_raster_destroy(raster);
-
+
PG_RETURN_POINTER(pgraster);
}
xul = rt_raster_get_x_offset(raster);
- rt_raster_destroy(raster);
+ rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
-
+
PG_RETURN_FLOAT8(xul);
}
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
-
+
PG_RETURN_FLOAT4(nodata);
}
}
result = (text *) palloc(VARHDRSZ + strlen(bandpath) + 1);
-
+
SET_VARSIZE(result, VARHDRSZ + strlen(bandpath) + 1);
strcpy((char *) VARDATA(result), bandpath);
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
-
+
PG_RETURN_FLOAT8(pixvalue);
}
"Value not set. Returning original raster");
skipset = TRUE;
}
- else
+ else
y = PG_GETARG_INT32(3);
POSTGIS_RT_DEBUGF(3, "Pixel coordinates (%d, %d)", x, y);
POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebra: Creating new empty raster...");
-
+
/**
* Create a new empty raster with having the same georeference as the
* provided raster
rt_raster_destroy(raster);
pgraster = rt_raster_serialize(newrast);
- if (NULL == pgraster) {
+ if (NULL == pgraster) {
elog(ERROR, "RASTER_mapAlgebra: Could not serialize raster. "
"Returning NULL");
PG_RETURN_NULL();
SET_VARSIZE(pgraster, pgraster->size);
rt_raster_destroy(newrast);
-
+
PG_RETURN_POINTER(pgraster);
}
}
SET_VARSIZE(pgraster, pgraster->size);
-
+
rt_raster_destroy(newrast);
-
- PG_RETURN_POINTER(pgraster);
+
+ PG_RETURN_POINTER(pgraster);
}
-
+
/*
* Get NODATA value
*/
POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebra: Getting NODATA value for band...");
-
+
if (rt_band_get_hasnodata_flag(band)) {
newnodatavalue = rt_band_get_nodata(band);
}
strncpy(initexpr, "SELECT ", strlen("SELECT "));
strncpy(initexpr + strlen("SELECT "), strtoupper(expression),
strlen(expression));
- initexpr[len] = '\0';
+ initexpr[len] = '\0';
POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebra: Expression is %s", initexpr);
//expression = NULL;
}
-
+
/**
* Optimization: If a nodatavalueexpr is provided, recompute the initial
else {
newexpr = initndvexpr;
}
-
+
POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebra: initndvexpr = %s", newexpr);
/* Eval the NODATA expression to get new NODATA. Connect with SPI manager
SPI_freetuptable(tuptable);
/* Disconnect from SPI manager */
- SPI_finish();
+ SPI_finish();
PG_RETURN_NULL();
}
POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebra: new initial value = %f",
newinitialvalue);
-
+
}
-
-
+
+
/**
* Optimization: If the raster is only filled with nodata values return
* right now a raster filled with the nodatavalueexpr
pgraster = rt_raster_serialize(newrast);
if (NULL == pgraster) {
elog(ERROR, "RASTER_mapAlgebra: Could not serialize raster. "
- "Returning NULL");
+ "Returning NULL");
PG_RETURN_NULL();
}
/* Free memory allocated out of the current context */
if (SPI_tuptable)
SPI_freetuptable(tuptable);
-
+
SPI_finish();
PG_RETURN_NULL();
}
if (NULL == pgraster) {
elog(ERROR, "RASTER_mapAlgebra: Could not serialize raster. "
"Returning NULL");
-
+
PG_RETURN_NULL();
}
pgraster = rt_raster_serialize(newrast);
if (NULL == pgraster) {
elog(ERROR, "RASTER_mapAlgebra: Could not serialize raster. "
- "Returning NULL");
-
+ "Returning NULL");
+
PG_RETURN_NULL();
}
ret = SPI_execute(newexpr, FALSE, 0);
- if (ret != SPI_OK_SELECT || SPI_tuptable == NULL ||
+ if (ret != SPI_OK_SELECT || SPI_tuptable == NULL ||
SPI_processed != 1) {
elog(ERROR, "RASTER_mapAlgebra: Invalid construction"
" for expression. Aborting");
pfree(newexpr);
if (SPI_tuptable)
SPI_freetuptable(tuptable);
-
+
SPI_finish();
PG_RETURN_NULL();
}
uint16_t width = 2;
uint16_t height = 2;
*/
-
+
/* Second test raster */
uint16_t width = 9;
uint16_t height = 9;
-
+
/* Third test raster */
/*
uint16_t width = 5;
*/
rt_raster raster = rt_raster_new(width, height);
-
+
/* Fill raster. Option 1: simple raster */
/*
rt_band band = addBand(raster, PT_32BSI, 0, 0);
rt_band_set_pixel(band, 1, 0, 1);
rt_band_set_pixel(band, 1, 1, 1);
*/
-
- /* Fill raster. Option 2: 9x9, 1 band */
+
+ /* Fill raster. Option 2: 9x9, 1 band */
rt_band band = addBand(raster, PT_32BUI, hasnodata, nodatavalue);
-
+
{
int x, y;
for (x = 0; x < rt_band_get_width(band); ++x)
rt_band_set_pixel(band, 3, 7, 1);
rt_band_set_pixel(band, 4, 7, 1);
rt_band_set_pixel(band, 5, 7, 2);
-
+
/* Fill raster. Option 3: 5x5, 1 band */
/*
rt_band band = addBand(raster, PT_8BUI, 1, 255);
-
+
rt_band_set_pixel(band, 0, 0, 253);
rt_band_set_pixel(band, 1, 0, 254);
rt_band_set_pixel(band, 2, 0, 253);
rt_band_set_pixel(band, 3, 4, 254);
rt_band_set_pixel(band, 4, 4, 254);
*/
-
+
rt_raster_add_band(raster, band, 100);
-
+
return raster;
}
CHECK(!failure);
CHECK_EQUALS(val, 2);
- failure = rt_band_set_nodata(band, 4);
+ failure = rt_band_set_nodata(band, 4);
val = rt_band_get_nodata(band);
CHECK(!failure);
CHECK_EQUALS(val, 4);
- failure = rt_band_set_nodata(band, 8);
+ failure = rt_band_set_nodata(band, 8);
val = rt_band_get_nodata(band);
CHECK(!failure);
CHECK_EQUALS(val, 8);
- failure = rt_band_set_nodata(band, 15);
+ failure = rt_band_set_nodata(band, 15);
val = rt_band_get_nodata(band);
CHECK(!failure);
CHECK_EQUALS(val, 15);
{
int x, y;
-
+
for (x=0; x<rt_band_get_width(band); ++x)
{
for (y=0; y<rt_band_get_height(band); ++y)
static void testBand8BUI(rt_band band)
{
double val;
- int failure;
+ int failure;
failure = rt_band_set_nodata(band, 1);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 2);
- failure = rt_band_set_nodata(band, 4);
+ failure = rt_band_set_nodata(band, 4);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 4);
- failure = rt_band_set_nodata(band, 8);
+ failure = rt_band_set_nodata(band, 8);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 8);
- failure = rt_band_set_nodata(band, 15);
+ failure = rt_band_set_nodata(band, 15);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 15);
- failure = rt_band_set_nodata(band, 31);
+ failure = rt_band_set_nodata(band, 31);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 31);
- failure = rt_band_set_nodata(band, 255);
+ failure = rt_band_set_nodata(band, 255);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 255);
{
for (y=0; y<rt_band_get_height(band); ++y)
{
- failure = rt_band_set_pixel(band, x, y, 31);
+ failure = rt_band_set_pixel(band, x, y, 31);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
CHECK_EQUALS(val, 31);
- failure = rt_band_set_pixel(band, x, y, 255);
+ failure = rt_band_set_pixel(band, x, y, 255);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 2);
- failure = rt_band_set_nodata(band, 4);
+ failure = rt_band_set_nodata(band, 4);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 4);
- failure = rt_band_set_nodata(band, 8);
+ failure = rt_band_set_nodata(band, 8);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 8);
- failure = rt_band_set_nodata(band, 15);
+ failure = rt_band_set_nodata(band, 15);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 15);
- failure = rt_band_set_nodata(band, 31);
+ failure = rt_band_set_nodata(band, 31);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 31);
- failure = rt_band_set_nodata(band, -127);
+ failure = rt_band_set_nodata(band, -127);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, -127);
- failure = rt_band_set_nodata(band, 127);
+ failure = rt_band_set_nodata(band, 127);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 127);
/* out of range (-127..127) */
- failure = rt_band_set_nodata(band, -129);
+ failure = rt_band_set_nodata(band, -129);
CHECK(failure);
/* out of range (-127..127) */
- failure = rt_band_set_nodata(band, 129);
+ failure = rt_band_set_nodata(band, 129);
CHECK(failure);
/* out of range (-127..127) */
- failure = rt_band_set_pixel(band, 0, 0, -129);
+ failure = rt_band_set_pixel(band, 0, 0, -129);
CHECK(failure);
/* out of range (-127..127) */
- failure = rt_band_set_pixel(band, 0, 0, 129);
+ failure = rt_band_set_pixel(band, 0, 0, 129);
CHECK(failure);
{
for (y=0; y<rt_band_get_height(band); ++y)
{
- failure = rt_band_set_pixel(band, x, y, 31);
+ failure = rt_band_set_pixel(band, x, y, 31);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 0);
- failure = rt_band_set_nodata(band, 31);
+ failure = rt_band_set_nodata(band, 31);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 31);
- failure = rt_band_set_nodata(band, 255);
+ failure = rt_band_set_nodata(band, 255);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 255);
- failure = rt_band_set_nodata(band, 65535);
+ failure = rt_band_set_nodata(band, 65535);
CHECK(!failure);
val = rt_band_get_nodata(band);
//printf("set 65535 on %s band gets %g back\n", pixtypeName, val);
{
for (y=0; y<rt_band_get_height(band); ++y)
{
- failure = rt_band_set_pixel(band, x, y, 255);
+ failure = rt_band_set_pixel(band, x, y, 255);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
CHECK_EQUALS(val, 255);
- failure = rt_band_set_pixel(band, x, y, 65535);
+ failure = rt_band_set_pixel(band, x, y, 65535);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 0);
- failure = rt_band_set_nodata(band, 31);
+ failure = rt_band_set_nodata(band, 31);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 31);
- failure = rt_band_set_nodata(band, 255);
+ failure = rt_band_set_nodata(band, 255);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 255);
- failure = rt_band_set_nodata(band, -32767);
+ failure = rt_band_set_nodata(band, -32767);
CHECK(!failure);
val = rt_band_get_nodata(band);
//printf("set 65535 on %s band gets %g back\n", pixtypeName, val);
CHECK_EQUALS(val, -32767);
- failure = rt_band_set_nodata(band, 32767);
+ failure = rt_band_set_nodata(band, 32767);
CHECK(!failure);
val = rt_band_get_nodata(band);
//printf("set 65535 on %s band gets %g back\n", pixtypeName, val);
CHECK(failure);
/* out of range (-32767..32767) */
- failure = rt_band_set_pixel(band, 0, 0, -32769);
+ failure = rt_band_set_pixel(band, 0, 0, -32769);
CHECK(failure);
/* out of range (-32767..32767) */
- failure = rt_band_set_pixel(band, 0, 0, 32769);
+ failure = rt_band_set_pixel(band, 0, 0, 32769);
CHECK(failure);
/* out of dimensions range */
- failure = rt_band_set_pixel(band, rt_band_get_width(band), 0, 0);
+ failure = rt_band_set_pixel(band, rt_band_get_width(band), 0, 0);
CHECK(failure);
{
{
for (y=0; y<rt_band_get_height(band); ++y)
{
- failure = rt_band_set_pixel(band, x, y, 255);
+ failure = rt_band_set_pixel(band, x, y, 255);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
CHECK_EQUALS(val, 255);
- failure = rt_band_set_pixel(band, x, y, -32767);
+ failure = rt_band_set_pixel(band, x, y, -32767);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
CHECK_EQUALS(val, -32767);
- failure = rt_band_set_pixel(band, x, y, 32767);
+ failure = rt_band_set_pixel(band, x, y, 32767);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 0);
- failure = rt_band_set_nodata(band, 65535);
+ failure = rt_band_set_nodata(band, 65535);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 65535);
CHECK(!failure);
CHECK_EQUALS(val, 0);
- failure = rt_band_set_pixel(band, x, y, 65535);
+ failure = rt_band_set_pixel(band, x, y, 65535);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
CHECK_EQUALS(val, 65535);
- failure = rt_band_set_pixel(band, x, y, 4294967295UL);
+ failure = rt_band_set_pixel(band, x, y, 4294967295UL);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 0);
- failure = rt_band_set_nodata(band, 65535);
+ failure = rt_band_set_nodata(band, 65535);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 65535);
CHECK(failure);
/* out of value range */
- failure = rt_band_set_pixel(band, 0, 0, 2147483648UL);
+ failure = rt_band_set_pixel(band, 0, 0, 2147483648UL);
CHECK(failure);
/* out of dimensions range */
CHECK(!failure);
CHECK_EQUALS(val, 0);
- failure = rt_band_set_pixel(band, x, y, 65535);
+ failure = rt_band_set_pixel(band, x, y, 65535);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
CHECK_EQUALS(val, 65535);
- failure = rt_band_set_pixel(band, x, y, 2147483647);
+ failure = rt_band_set_pixel(band, x, y, 2147483647);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
//printf("set 65535.56 on %s band gets %g back\n", pixtypeName, val);
CHECK_EQUALS_DOUBLE(val, 65535.5);
- failure = rt_band_set_nodata(band, 0.006);
+ failure = rt_band_set_nodata(band, 0.006);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS_DOUBLE(val, 0.0060000000521540); /* XXX: Alternatively, use CHECK_EQUALS_DOUBLE_EX */
CHECK(!failure);
CHECK_EQUALS_DOUBLE(val, 65535.5);
- failure = rt_band_set_pixel(band, x, y, 0.006);
+ failure = rt_band_set_pixel(band, x, y, 0.006);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 0);
- failure = rt_band_set_nodata(band, 65535.56);
+ failure = rt_band_set_nodata(band, 65535.56);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 65535.56);
- failure = rt_band_set_nodata(band, 0.006);
+ failure = rt_band_set_nodata(band, 0.006);
CHECK(!failure);
val = rt_band_get_nodata(band);
CHECK_EQUALS(val, 0.006);
CHECK(!failure);
CHECK_EQUALS(val, 0);
- failure = rt_band_set_pixel(band, x, y, 65535.56);
+ failure = rt_band_set_pixel(band, x, y, 65535.56);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
CHECK_EQUALS(val, 65535.56);
- failure = rt_band_set_pixel(band, x, y, 0.006);
+ failure = rt_band_set_pixel(band, x, y, 0.006);
CHECK(!failure);
failure = rt_band_get_pixel(band, x, y, &val);
CHECK(!failure);
raster = rt_raster_new(256, 256);
assert(raster); /* or we're out of virtual memory */
-
+
printf("Checking empty and hasnoband functions...\n");
{ /* Check isEmpty and hasnoband */
CHECK(!rt_raster_is_empty(raster));
-
+
/* Create a dummy empty raster to test the opposite
* to the previous sentence
*/
rt_raster emptyraster = rt_raster_new(0, 0);
CHECK(rt_raster_is_empty(emptyraster));
rt_raster_destroy(emptyraster);
-
+
/* Once we add a band to this raster, we'll check the opposite */
CHECK(rt_raster_has_no_band(raster, 1));
}
-
+
printf("Checking raster properties...\n");
{ /* Check scale */
float scale;
typedef struct rt_geomval_t* rt_geomval;
int nPols = 0;
-
+
rt_geomval gv = (rt_geomval) rt_raster_dump_as_wktpolygons(rt, 1, &nPols);
CHECK_EQUALS_DOUBLE(gv[0].val, 1.0);
CHECK(!strcmp(gv[1].geom, "POLYGON ((3 3,3 6,6 6,6 3,3 3))"));
CHECK_EQUALS_DOUBLE(gv[2].val, 2.0);
- CHECK(!strcmp(gv[2].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))"));
+ CHECK(!strcmp(gv[2].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))"));
CHECK_EQUALS_DOUBLE(gv[3].val, 0.0);
CHECK(!strcmp(gv[3].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))"));
-
-
+
+
rt_raster_destroy(rt);
-
+
/* Second test: NODATA value = 1 */
rt = fillRasterToPolygonize(1, 1.0);
-
+
/* We can check rt_raster_has_no_band here too */
CHECK(!rt_raster_has_no_band(rt, 1));
nPols = 0;
-
+
gv = (rt_geomval) rt_raster_dump_as_wktpolygons(rt, 1, &nPols);
CHECK(!strcmp(gv[0].geom, "POLYGON ((3 3,3 6,6 6,6 3,3 3))"));
CHECK_EQUALS_DOUBLE(gv[1].val, 2.0);
- CHECK(!strcmp(gv[1].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))"));
+ CHECK(!strcmp(gv[1].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))"));
CHECK_EQUALS_DOUBLE(gv[2].val, 0.0);
CHECK(!strcmp(gv[2].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))"));
rt_raster_destroy(rt);
-
+
/* Third test: NODATA value = 2 */
rt = fillRasterToPolygonize(1, 2.0);
-
+
/* We can check rt_raster_has_no_band here too */
CHECK(!rt_raster_has_no_band(rt, 1));
nPols = 0;
-
+
gv = (rt_geomval) rt_raster_dump_as_wktpolygons(rt, 1, &nPols);
CHECK_EQUALS_DOUBLE(gv[0].val, 1.0);
CHECK_EQUALS_DOUBLE(gv[2].val, 0.0);
CHECK(!strcmp(gv[2].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))"));
rt_raster_destroy(rt);
-
+
/* Fourth test: NODATA value = 0 */
rt = fillRasterToPolygonize(1, 0.0);
-
+
/* We can check rt_raster_has_no_band here too */
CHECK(!rt_raster_has_no_band(rt, 1));
nPols = 0;
-
+
gv = (rt_geomval) rt_raster_dump_as_wktpolygons(rt, 1, &nPols);
-
+
CHECK_EQUALS_DOUBLE(gv[0].val, 1.0);
CHECK(!strcmp(gv[0].geom, "POLYGON ((3 1,3 2,2 2,2 3,1 3,1 6,2 6,2 7,3 7,3 8,5 8,5 6,3 6,3 3,4 3,5 3,5 1,3 1))"));
-
+
CHECK_EQUALS_DOUBLE(gv[1].val, 2.0);
- CHECK(!strcmp(gv[1].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))"));
+ CHECK(!strcmp(gv[1].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))"));
rt_raster_destroy(rt);
-
+
/* Last test: There is no NODATA value (all values are valid) */
rt = fillRasterToPolygonize(0, 1.0);
-
+
/* We can check rt_raster_has_no_band here too */
CHECK(!rt_raster_has_no_band(rt, 1));
nPols = 0;
-
+
gv = (rt_geomval) rt_raster_dump_as_wktpolygons(rt, 1, &nPols);
CHECK_EQUALS_DOUBLE(gv[0].val, 1.0);
CHECK(!strcmp(gv[1].geom, "POLYGON ((3 3,3 6,6 6,6 3,3 3))"));
CHECK_EQUALS_DOUBLE(gv[2].val, 2.0);
- CHECK(!strcmp(gv[2].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))"));
+ CHECK(!strcmp(gv[2].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))"));
CHECK_EQUALS_DOUBLE(gv[3].val, 0.0);
CHECK(!strcmp(gv[3].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))"));
-/*
+/*
* $Id$
*
* WKTRaster - Raster Types for PostGIS
* http://www.postgis.org/support/wiki/index.php?WKTRasterHomePage
*
* Copyright (C) 2009 Sandro Santilli <strk@keybit.net>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
free((/*no const*/ void*)out);
- {
+ {
void *serialized;
rt_raster rast2;
{
double val;
int failure;
-
+
rt_band band = rt_raster_get_band(raster, 0);
CHECK(band);
CHECK_EQUALS(rt_band_get_pixtype(band), PT_8BSI);
free((/*no const*/ void*)out);
- {
+ {
void *serialized;
rt_raster rast2;
rt_raster_destroy(rast2);
free(serialized);
-
+
}
rt_raster_destroy(raster);
CHECK(!rt_band_is_offline(band));
CHECK(!rt_band_get_hasnodata_flag(band));
CHECK_EQUALS(rt_band_get_nodata(band), -1);
-
+
failure = rt_band_get_pixel(band, 0, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, -1);
failure = rt_band_get_pixel(band, 1, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 0);
-
+
failure = rt_band_get_pixel(band, 2, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, -16);
-
+
failure = rt_band_get_pixel(band, 0, 1, &val);
CHECK(!failure);
CHECK_EQUALS(val, 127);
-
+
failure = rt_band_get_pixel(band, 1, 1, &val);
CHECK(!failure);
CHECK_EQUALS(val, 10);
-
+
failure = rt_band_get_pixel(band, 2, 1, &val);
CHECK(!failure);
CHECK_EQUALS(val, 2);
failure = rt_band_get_pixel(band, 1, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 0);
-
+
failure = rt_band_get_pixel(band, 2, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, -16);
-
+
failure = rt_band_get_pixel(band, 0, 1, &val);
CHECK(!failure);
CHECK_EQUALS(val, 127);
-
+
failure = rt_band_get_pixel(band, 1, 1, &val);
CHECK(!failure);
CHECK_EQUALS(val, 10);
-
+
failure = rt_band_get_pixel(band, 2, 1, &val);
CHECK(!failure);
CHECK_EQUALS(val, 2);
"FFFF" /* nodata value (-1) */
"03" /* ext band num == 3 */
/* ext band path == /tmp/t.tif */
-"2F746D702F742E74696600"
+"2F746D702F742E74696600"
;
raster = rt_raster_from_hexwkb(hexwkb, strlen(hexwkb));
failure = rt_band_get_pixel(band, 1, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 436);
-
+
failure = rt_band_get_pixel(band, 2, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 431);
*/
free((/*no const*/ void*)out);
- {
+ {
void *serialized;
rt_raster rast2;
/* 5x5, little endian, 3 x band 8BUI (RGB), */
/* nodata 0, srid -1 */
/* Test case completes regress/bug_test_car5.sql */
- /* Test case repeated 4 times to mimic 4 tiles insertion */
+ /* Test case repeated 4 times to mimic 4 tiles insertion */
/* ------------------------------------------------------ */
for (i = 0; i < 5; ++i)
{
failure = rt_band_get_pixel(band, 1, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 254);
-
+
failure = rt_band_get_pixel(band, 2, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 253);
-
+
failure = rt_band_get_pixel(band, 3, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 254);
-
+
failure = rt_band_get_pixel(band, 4, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 254);
}
-
+
{
/* Test 2nd band */
double val;
failure = rt_band_get_pixel(band, 1, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 98);
-
+
failure = rt_band_get_pixel(band, 2, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 122);
-
+
failure = rt_band_get_pixel(band, 3, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 173);
-
+
failure = rt_band_get_pixel(band, 4, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 209);
}
-
+
{
/* Test 3rd band */
double val;
failure = rt_band_get_pixel(band, 1, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 86);
-
+
failure = rt_band_get_pixel(band, 2, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 100);
-
+
failure = rt_band_get_pixel(band, 3, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 135);
-
+
failure = rt_band_get_pixel(band, 4, 0, &val);
CHECK(!failure);
CHECK_EQUALS(val, 161);
*/
free((/*no const*/ void*)out);
- {
+ {
void *serialized;
rt_raster rast2;
free(serialized);
}
rt_raster_destroy(raster);
-
+
} /* for-loop running car5 tests */
/* ------------------------------------------------------ */
void rt_init_allocators(void)
{
rt_install_default_allocators();
-}
\ No newline at end of file
+}