[postgis-devel] Missing something simple
Nathaniel Clay
clay.nathaniel at gmail.com
Fri Apr 12 07:40:39 PDT 2013
Hi all,
I am developing a function that takes in two points on a raster and returns
a line from one to the other consisting of the pixel values between the two
points in the z ordinate in the form of a lwline. However, I am getting a
Sig Bus error.
1) Is there any interest in a function like this?
2) I've looked through other similar functions in the doxygen
documentation, and I can't see what I am missing that is causing the error.
Any help would be appreciated.
{{{
/*
ST_Profile
*/
PG_FUNCTION_INFO_V1(RASTER_profile);
Datum RASTER_profile(PG_FUNCTION_ARGS)
{
rt_pgraster *pgraster;
rt_raster raster;
rt_band band;
LWLINE *rtnline;
LWPOINT *point;
double value;
int nodata;
int bandn;
double gt;
double xw,yw;
int where =0;
int error, err,e2;
int x0, x1, y0, y1, dx, dy, sx, sy;
int32_t srid;
/* Deserialize raster */
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
bandn = PG_GETARG_INT32(1);
x0 = PG_GETARG_INT32(2);
y0 = PG_GETARG_INT32(3);
x1 = PG_GETARG_INT32(4);
y1 = PG_GETARG_INT32(5);
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
elog(ERROR, "RASTER_profile: Could not deserialize raster");
PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_NULL();
}
srid = rt_raster_get_srid(raster);
rtnline = lwline_construct_empty(srid,true,false);
rt_raster_get_geotransform_matrix(raster,>);
band = rt_raster_get_band(raster, bandn - 1);
dx = abs(x1-x0);
sx = x0<x1 ? 1 : -1;
dy = abs(y1-y0);
sy = y0<y1 ? 1 : -1;
err = (dx>dy ? dx : -dy)/2;
for(;;){
error = rt_band_get_pixel(band,x0,y0,&value,&nodata);
if( error != 0 ) {
elog(ERROR,"RASTER_Profile: Could not get value for pixel");
PG_FREE_IF_COPY(pgraster,0);
PG_RETURN_NULL();
}
if (!nodata){
rt_raster_cell_to_geopoint(raster,(double)x0,(double)y0,&xw,&yw,>);
point = lwpoint_make3dz(srid,xw,yw,value);
lwline_add_lwpoint(rtnline,point,where);
where++;
}
if (x0==x1 && y0==y1) break;
e2 = err;
if (e2 >-dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
PG_RETURN_POINTER(geometry_serialize(lwline_as_lwgeom(rtnline)));
}
}}}
Thanks,
Nathaniel Hunter Clay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20130412/0faad838/attachment.html>
More information about the postgis-devel
mailing list