Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Novice > Re: Server Prog...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 3142 of 3323
Post > Topic >>

Re: Server Programming Interface - spi.exec() overheds issue

by eggyknap@[EMAIL PROTECTED] ("Josh Tolley") Jun 22, 2008 at 09:57 AM

On Wed, Jun 18, 2008 at 11:35 AM, Jo=E3o Gon=E7alves <joaofgo@[EMAIL PROTECTED]
>
wr=
ote:
> Hi!
> I'm not quite sure if this is the right place to discuss this issue but
> here goes. I've been testing PL/R language coupled with SPI and postgis
to
> produce Voronoi tiles, the following function pushes a set of polygon
> vertexes into an R array and inserts the Voronoi tiles into the
database.
> Since my current working dataset has something like 1.5M vertexes the
> overheads built up are huge and the proccess fails due to insuficient
> memory. Also, I can only see the results until all data is proccessed.
>
> What is the best way to handle this? Can I flush/purge pg buffers to
bett=
er
> handle memory issues?
> Should I adopt a block processing strategy to narrow down the initial
> dataset through a LIMIT statement or something along this line?
> Is spi.execute() in read-only mode usable / effective in this context?
> Are spi.freetuple or spi.freetuptable usable? How?
> Any ideas?
>
> CREATE OR REPLACE FUNCTION voronoi_tiles(TEXT, TEXT, INTEGER) RETURNS
> void AS '
>   library(deldir)
>
>   gids<-pg.spi.exec(sprintf("SELECT DISTINCT a.poly_gid AS gid FROM
> %1$s AS a ORDER BY gid;",arg1))
>
>   for (i in 1:length(gids$gid)){
>
>       # Retrieve points from the auxiliary geometry
>       points <- pg.spi.exec(sprintf("SELECT st_x(a.the_geom) AS x,
> st_y(a.the_geom) AS y FROM %1$s AS a WHERE a.poly_gid =3D %2$i;", arg1,
> gids$gid[[i]]))
>
>       # External envelope
>       xmin<-min(points$x)-abs(min(points$x)-max(points$x))
>       xmax<-max(points$x)+abs(min(points$x)-max(points$x))
>       ymin<-min(points$y)-abs(min(points$y)-max(points$y))
>       ymax<-max(points$y)+abs(min(points$y)-max(points$y))
>
>       # Generate the voronoi object
>       voro =3D deldir(points$x, points$y, digits=3D6, frac=3D1e-3,
> list(ndx=3D2,ndy=3D2), rw=3Dc(xmin,xmax,ymin,ymax))
>
>       # Get the individual tiles/polygons for the Voronoi diagram
>       tiles =3D tile.list(voro)
>
>       for(j in 1:length(tiles)){
>
>           tile<-tiles[[j]]
>           geom =3D "GeomFromText(''LINESTRING("
>
>           for(k in 1:length(tile$x)){
>               geom =3D sprintf("%s %.6f %.6f,", geom, tile$x[[k]],
> tile$y[[k]])
>           }
>
>           # Close the tile by appending the first vertex
>           geom =3D sprintf("%s %.6f %.6f)'' , %i)", geom, tile$x[[1]],
> tile$y[[1]], arg3)
>
>           # Insert into the database
>           pg.spi.exec(sprintf("INSERT INTO %1$s (gid, the_geom) VALUES
> (%2$i, %3$s)", arg2, gids$gid[[i]], geom))
>       }
>   }
> ' LANGUAGE 'plr';
>
> Example:
> SELECT voronoi_tiles('test_set', 'output_test_table', <SRID>);
>
>
>
>
>
>
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice@[EMAIL PROTECTED]
)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>

Try using a cursor. See pg.spi.cursor_open in the pl/r do***entation.
It will allow you to issue the query once, but fetch and process
results a little at a time (like your LIMIT idea, but easier).

- Josh / eggyknap

--=20
Sent via pgsql-novice mailing list (pgsql-novice@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
 




 2 Posts in Topic:
Server Programming Interface - spi.exec() overheds issue
joaofgo@[EMAIL PROTECTED]  2008-06-18 18:35:27 
Re: Server Programming Interface - spi.exec() overheds issue
eggyknap@[EMAIL PROTECTED  2008-06-22 09:57:34 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 6:19:59 CST 2008.