[postgis-users] 3d buffer

Sufficool, Stanley ssufficool at rov.sbcounty.gov
Fri Aug 15 08:33:50 PDT 2008


Step 1: Get center of cube by averaging all points (x,y,z) on the cube
Step 2: Get the delta of each points (x,y,z) from the center point and
divide by distance from the center and then add/subtract that delta from
the points (x,y,z) multiplied by the buffer number
 
This would expand the CUBE from the center by the given amount.
 
Someone correct this if needed since I have absolutely no practical
application or data to drive this code.
 
VERY PSEUDO CODE (since there is no cube geometry type?):
 
CREATE FUNCTION st_buffercube(theCube geometry, buffer double precision)

returns geometry AS $BODY$
 
declare i int;
 
/* Centroid of cube */
declare cx double precision; 
declare cy double precision; 
declare cz double precision;
 
/* Cube point */
declare px double precision; 
declare py double precision; 
declare pz double precision;
 
/* Cube point delta */
declare segLength double precision;
declare dx double precision; 
declare dy double precision; 
declare dz double precision;
 
/* Output ?CUBE? */
declare retWKT character varying(4096);
 
BEGIN
 
    cx := 0;
    cy := 0;
    cz := 0;
    for i IN 1..st_npoints(theCube) LOOP
        cx := cx + st_x(pointn(theCube,i));
        cy := cy + st_y(pointn(theCube,i));
        cz := cz + st_z(pointn(theCube,i));
    END LOOP;
 
    /* Compute centroid of cube */
    cx := cx / st_npoints(theCube);
    cy := cy / st_npoints(theCube);
    cz := cz / st_npoints(theCube);
 
    /* WHAT WOULD THE APPROPRIATE STORAGE TYPE FOR THIS BE ??? */
    retWKT := 'POLYGON( ';
    for i in 1..st_npoints(theCube) loop
        px := st_x(pointn(theCube,i)); 
        py := st_y(pointn(theCube,i)); 
        pz := st_z(pointn(theCube,i));
 
        dx := st_x(pointn(theCube,i)) - cx; 
        dy := st_y(pointn(theCube,i)) - cy; 
        dz := st_z(pointn(theCube,i)) - cz;
        /* Divide by distance from center point */
        segLength := sqrt( (cx -px) ^ 2  + (cy - py) ^ 2 + (cz - pz) ^
2);
        dx := dx / segLength;
        dy := dy / segLength;
        dz := dz /segLength;
        
        /* Buffer the point */
        px := px + dx;
        py := py + dy;
        pz := pz + dz;
 
        retWKT := ' ( ' || px::text || ' ' || py::text || ' ' ||
pz::text || ' )';
        
    end loop;
 
    retWKT := ' )';
    
    return setsrid(retWKT::geometry, st_srid(theCube));
END;
$BODY$
  LANGUAGE 'plpgsql'
 

	-----Original Message-----
	From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of
eehab hamzeh
	Sent: Friday, August 15, 2008 1:51 AM
	To: postgis-users at postgis.refractions.net
	Subject: [postgis-users] 3d buffer
	
	
	What i mean by 3d buffer are i have a room which is like a box
and i need to find all the areas that this room Box that will intersect
if the room are extended and get larger....
	
	
	
	buffer FROM (SELECT gid,buffer(r.the_geom,10) as buffer FROM
room r WHERE r.roomname='guest room') AS foo USING UNIQUE gid USING
SRID=31467"
	
	i need such query to take the 3d dimension in consideration and
make it not just only in 2d 
	



	Thanks
	
	ihab
	
	
	
	
________________________________

	Get news, entertainment and everything you care about at
Live.com. Check it out! <http://www.live.com/getstarted.aspx>  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080815/b3d47b2a/attachment.html>


More information about the postgis-users mailing list