[postgis-commits] svn - r3875 - spike/wktraster/rt_pg
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Mon Mar 16 15:23:58 PDT 2009
Author: pracine
Date: 2009-03-16 15:23:58 -0700 (Mon, 16 Mar 2009)
New Revision: 3875
Modified:
spike/wktraster/rt_pg/rt_pg.c
Log:
Added RT_BandPath(rast,bandnum)
Modified: spike/wktraster/rt_pg/rt_pg.c
===================================================================
--- spike/wktraster/rt_pg/rt_pg.c 2009-03-16 22:23:02 UTC (rev 3874)
+++ spike/wktraster/rt_pg/rt_pg.c 2009-03-16 22:23:58 UTC (rev 3875)
@@ -1,19 +1,19 @@
-/*
+/*
* WKTRaster - Raster Types for PostGIS
* http://www.postgis.org/support/wiki/index.php?WKTRasterHomePage
*
* Copyright (C) 2009 Sandro Santilli <strk at 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
@@ -94,6 +94,7 @@
Datum RASTER_getBandPixelType(PG_FUNCTION_ARGS);
Datum RASTER_getBandPixelTypeName(PG_FUNCTION_ARGS);
Datum RASTER_getBandNoDataValue(PG_FUNCTION_ARGS);
+Datum RASTER_getBandPath(PG_FUNCTION_ARGS);
Datum RASTER_getPixelValue(PG_FUNCTION_ARGS);
Datum RASTER_setPixelValue(PG_FUNCTION_ARGS);
@@ -242,7 +243,7 @@
}
/*
- * Input is a string with hex chars in it.
+ * Input is a string with hex chars in it.
* Convert to binary and put in the result
*/
PG_FUNCTION_INFO_V1(RASTER_in);
@@ -485,7 +486,7 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
srid = rt_raster_get_srid(ctx, raster);
PG_RETURN_INT32(srid);
}
@@ -507,7 +508,7 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
width = rt_raster_get_width(ctx, raster);
PG_RETURN_INT32(width);
}
@@ -529,7 +530,7 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
height = rt_raster_get_height(ctx, raster);
PG_RETURN_INT32(height);
}
@@ -551,7 +552,7 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
num_bands = rt_raster_get_num_bands(ctx, raster);
PG_RETURN_INT32(num_bands);
}
@@ -573,7 +574,7 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
xsize = rt_raster_get_pixel_width(ctx, raster);
PG_RETURN_FLOAT8(xsize);
}
@@ -595,7 +596,7 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
ysize = rt_raster_get_pixel_height(ctx, raster);
PG_RETURN_FLOAT8(ysize);
}
@@ -617,7 +618,7 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
xrotation = rt_raster_get_x_rotation(ctx, raster);
PG_RETURN_FLOAT8(xrotation);
}
@@ -639,13 +640,13 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
yrotation = rt_raster_get_y_rotation(ctx, raster);
PG_RETURN_FLOAT8(yrotation);
}
/**
- * Return
+ * Return
*/
PG_FUNCTION_INFO_V1(RASTER_getXUpperLeft);
Datum RASTER_getXUpperLeft(PG_FUNCTION_ARGS)
@@ -661,13 +662,13 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
xul = rt_raster_get_x_offset(ctx, raster);
PG_RETURN_FLOAT8(xul);
}
/**
- * Return
+ * Return
*/
PG_FUNCTION_INFO_V1(RASTER_getYUpperLeft);
Datum RASTER_getYUpperLeft(PG_FUNCTION_ARGS)
@@ -683,7 +684,7 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
yul = rt_raster_get_y_offset(ctx, raster);
PG_RETURN_FLOAT8(yul);
}
@@ -705,7 +706,7 @@
double xdim, ydim; /* line 1 and 4 */
double xrot, yrot; /* line 2 and 3 */
double xul, yul; /* line 5 and 6 */
-
+
memset(buf, 0, buf_size);
/* TODO: can be optimized to only detoast the header! */
@@ -731,7 +732,7 @@
snprintf(buf, buf_size, "%.10f\n%.10f\n%.10f\n%.10f\n%.10f\n%.10f\n",
xdim, xrot, yrot, ydim, xul, yul);
buf[buf_size - 1] = '\0';
-
+
text_size = strlen(buf);
result = palloc(VARHDRSZ + text_size);
if ( ! result ) {
@@ -775,7 +776,7 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
/* Fetch requested band and its pixel type */
band = rt_raster_get_band(ctx, raster, index - 1);
if ( ! band ) {
@@ -784,7 +785,7 @@
PG_RETURN_NULL();
}
- pixtype = rt_band_get_pixtype(ctx, band);
+ pixtype = rt_band_get_pixtype(ctx, band);
PG_RETURN_INT32(pixtype);
}
@@ -824,7 +825,7 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
/* Fetch requested band and its pixel type */
band = rt_raster_get_band(ctx, raster, index - 1);
if ( ! band ) {
@@ -833,7 +834,7 @@
PG_RETURN_NULL();
}
- pixtype = rt_band_get_pixtype(ctx, band);
+ pixtype = rt_band_get_pixtype(ctx, band);
result = palloc(VARHDRSZ + name_size);
if ( ! result ) {
@@ -889,7 +890,7 @@
}
size = VARHDRSZ + strlen(ptr);
- SET_VARSIZE(result, size);
+ SET_VARSIZE(result, size);
PG_RETURN_TEXT_P(result);
}
@@ -925,7 +926,7 @@
elog(ERROR, "Could not deserialize raster");
PG_RETURN_NULL();
}
-
+
/* Fetch requested band and its NODATA value */
band = rt_raster_get_band(ctx, raster, index - 1);
if ( ! band ) {
@@ -934,11 +935,70 @@
PG_RETURN_NULL();
}
- nodata = rt_band_get_nodata(ctx, band);
+ nodata = rt_band_get_nodata(ctx, band);
PG_RETURN_FLOAT4(nodata);
}
/**
+ * Return the path of the raster for out-db raster.
+ */
+PG_FUNCTION_INFO_V1(RASTER_getBandPath);
+Datum RASTER_getBandPath(PG_FUNCTION_ARGS)
+{
+ rt_pgraster *pgraster = NULL;
+ rt_raster raster = NULL;
+ rt_band band = NULL;
+ rt_context ctx = NULL;
+ int32_t index;
+ const char *bandpath;
+ text *result;
+
+ /* Index is 1-based */
+ index = PG_GETARG_INT32(1);
+ if ( index < 1 ) {
+ elog(ERROR, "Invalid band index (must use 1-based)");
+ PG_RETURN_NULL();
+ }
+ assert(0 <= (index - 1));
+
+ /* Deserialize raster */
+ pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+ ctx = get_rt_context(fcinfo);
+
+ raster = rt_raster_deserialize(ctx, pgraster);
+ if ( ! raster ) {
+ elog(ERROR, "Could not deserialize raster");
+ PG_RETURN_NULL();
+ }
+
+ /* Fetch requested band and its NODATA value */
+ band = rt_raster_get_band(ctx, raster, index - 1);
+ if ( ! band ) {
+ /* TODO: Throw rrror or notice or nothing? */
+ elog(ERROR, "Could not find raster band of index %d", index);
+ PG_RETURN_NULL();
+ }
+
+ bandpath = rt_band_get_ext_path(ctx, band);
+ if ( ! bandpath )
+ {
+ elog(ERROR, "Could not get band path");
+ PG_RETURN_NULL();
+ }
+
+ result = (text *) palloc(VARHDRSZ + strlen(bandpath) + 1);
+ if ( ! result ) {
+ elog(ERROR, "Could not allocate memory for output text object");
+ PG_RETURN_NULL();
+ }
+ SET_VARSIZE(result, VARHDRSZ + strlen(bandpath) + 1);
+
+ strcpy((char *) VARDATA(result), bandpath);
+ PG_RETURN_TEXT_P(result);
+}
+
+
+/**
* Return value of a single pixel.
* Pixel location is specified by 1-based index of Nth band of raster and
* X,Y coordinates (X <= RT_Width(raster) and Y <= RT_Height(raster)).
@@ -964,7 +1024,7 @@
PG_RETURN_NULL();
}
assert(0 <= (nband - 1));
-
+
/* Validate pixel coordinates are in range */
x = PG_GETARG_INT32(2);
y = PG_GETARG_INT32(3);
@@ -1000,7 +1060,7 @@
Datum RASTER_setPixelValue(PG_FUNCTION_ARGS)
{
double pixvalue = 0;
-
+
/* TODO: TO BE IMPLEMENTED */
pixvalue = PG_GETARG_FLOAT8(4);
PG_RETURN_FLOAT8(pixvalue);
More information about the postgis-commits
mailing list