<div dir="ltr"><div><div><div><div><div>Hi all,<br><br></div>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.<br>
<br></div>1) Is there any interest in a function like this?<br></div>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.<br>
<br>{{{<br><br>/*<br> ST_Profile<br>*/<br><br>PG_FUNCTION_INFO_V1(RASTER_profile);<br>Datum RASTER_profile(PG_FUNCTION_ARGS)<br>{<br> rt_pgraster *pgraster;<br> rt_raster raster;<br> rt_band band;<br><br> LWLINE *rtnline;<br>
LWPOINT *point;<br><br> double value;<br> int nodata;<br> int bandn;<br><br> double gt;<br> double xw,yw;<br> int where =0;<br> int error, err,e2;<br> int x0, x1, y0, y1, dx, dy, sx, sy;<br> int32_t srid;<br>
<br> /* Deserialize raster */<br> if (PG_ARGISNULL(0)) PG_RETURN_NULL();<br> pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));<br> bandn = PG_GETARG_INT32(1);<br> x0 = PG_GETARG_INT32(2);<br>
y0 = PG_GETARG_INT32(3);<br> x1 = PG_GETARG_INT32(4);<br> y1 = PG_GETARG_INT32(5);<br><br> raster = rt_raster_deserialize(pgraster, FALSE);<br> if (!raster) {<br> elog(ERROR, "RASTER_profile: Could not deserialize raster");<br>
PG_FREE_IF_COPY(pgraster, 0);<br> PG_RETURN_NULL();<br> }<br> srid = rt_raster_get_srid(raster);<br> rtnline = lwline_construct_empty(srid,true,false);<br> rt_raster_get_geotransform_matrix(raster,>);<br>
band = rt_raster_get_band(raster, bandn - 1);<br><br> dx = abs(x1-x0);<br> sx = x0<x1 ? 1 : -1;<br> dy = abs(y1-y0);<br> sy = y0<y1 ? 1 : -1; <br> err = (dx>dy ? dx : -dy)/2;<br> <br>
for(;;){<br><br> error = rt_band_get_pixel(band,x0,y0,&value,&nodata);<br> <br> <br> if( error != 0 ) {<br> elog(ERROR,"RASTER_Profile: Could not get value for pixel");<br>
PG_FREE_IF_COPY(pgraster,0);<br> PG_RETURN_NULL();<br> }<br> if (!nodata){<br> rt_raster_cell_to_geopoint(raster,(double)x0,(double)y0,&xw,&yw,>);<br> point = lwpoint_make3dz(srid,xw,yw,value);<br>
lwline_add_lwpoint(rtnline,point,where);<br> where++;<br> }<br><br> if (x0==x1 && y0==y1) break;<br> e2 = err;<br> if (e2 >-dx) { err -= dy; x0 += sx; }<br>
if (e2 < dy) { err += dx; y0 += sy; }<br> }<br> <br><br> PG_RETURN_POINTER(geometry_serialize(lwline_as_lwgeom(rtnline)));<br> <br>}<br>}}}<br><br></div>Thanks,<br><br></div>Nathaniel Hunter Clay<br>
</div>