[postgis-users] libpg
Ricardo
ricardoluis at ufs.br
Fri Nov 10 09:47:32 PST 2006
Hi all,
I'm trying to wirite a file from a odi field of my data base with the
folwing source code:
-----------------------------------------------------------------------------
------------------------------------------------
1 const char *conninfo = "Driver=PostgreSQL Unicode; Server=10.0.0.62;
Database=energia; user=postgres; password=postgres";
2 PGconn *conn;
3 PGresult *res;
4 Oid inv_oid;
5 int r = 1;
6 int lobj_fd;// = lo_open(conn, inv_oid, 1);
7 int fd;
8 char buf[300000];
9 int nbytes, tmp;
10 FILE* fp;
11 /* Make a connection to the database */
12 conn = PQconnectdb(conninfo);
13 inv_oid = lo_creat(conn, 1);
14 res = PQexec(conn, "SELECT imagem FROM raster"); /* ask for
binary results */
15 lobj_fd = lo_open(conn, inv_oid, 1);
16 fp = fopen("test.tif", "wt");
17 while ((nbytes = lo_read(conn, lobj_fd, buf, 300000)) > 0)
18 {
19 tmp = fwrite(&buf, sizeof(buf), 1, fp);
20 }
21 (void) lo_close(conn, lobj_fd);
22 (void) fclose(fp);
-----------------------------------------------------------------------------
-------------------------------------------------
The query on the line 14 has been applied over the folwing table:
-----------------------------------------------------------------------------
-------------------------------------------------
CREATE TABLE raster
(
name varchar(30),
imagem oid,
geometria geometry,
CONSTRAINT enforce_dims_geometria CHECK (ndims(geometria) = 3),
CONSTRAINT enforce_srid_geometria CHECK (srid(geometria) = -1)
)
WITH OIDS;
-----------------------------------------------------------------------------
-------------------------------------------------
So evry time on the line 15 the value -1 was returned to lobj_fd variable;
Forgot I something?
What is the problem with that code?
Where can I get references or samples to do that?
Thank you all.
Ricardo Luís.
More information about the postgis-users
mailing list