[postgis] About description of usage of C Clients (libpq) in PostGIS Manual

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[postgis] About description of usage of C Clients (libpq) in PostGIS Manual

Hisaji ONO-3
Hello.
 
 This is my first message in this mailing list.
 
 I've tried to use PostGIS in cygwin's PostgreSQL 7.1,2 on WinNT 4.0 Server SP6.0a for a month. I've been very impressed with this extension's performance which can handle large-scale geospatial data.
 
 I'd like to use a function of C Clients (libpq) of PostGIS to create some applications, but still no description in PostGIS Manual.
 
 When will it be available?
 
Thanks.
 

Yahoo! Groups Sponsor

To unsubscribe from this group, send an email to:
[hidden email]



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Reply | Threaded
Open this post in threaded view
|

Re: [postgis] About description of usage of C Clients (libpq) in PostGIS Manual

Paul Ramsey-2


> Hisaji ONO wrote:
>
>  I've tried to use PostGIS in cygwin's PostgreSQL 7.1,2 on WinNT 4.0
> Server SP6.0a for a month. I've been very impressed with this
> extension's performance which can handle large-scale geospatial data.
>
>  I'd like to use a function of C Clients (libpq) of PostGIS to create
> some applications, but still no description in PostGIS Manual.
>
>  When will it be available?

Sorry the doco still lags. However, since presumably you are a C
programmer there is an example bundled with the 0.5 code, under
examples/wkb_reader. That program has code which attaches to a
PostGIS/PostgreSQL server with libpq and reads features out using
Well-Known Binary. It might be enough to get you going.
Paul

--
      __
     /
     | Paul Ramsey
     | Refractions Research
     | Email: [hidden email]
     | Phone: (250) 885-0632
     \_

To unsubscribe from this group, send an email to:
[hidden email]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



Reply | Threaded
Open this post in threaded view
|

Re: [postgis] About description of usage of C Clients (libpq) in PostGIS Manual

Frank Warmerdam
In reply to this post by Hisaji ONO-3


Hisaji ONO wrote:

> Hello.
>
>  
>
>  This is my first message in this mailing list.
>
>  
>
>  I've tried to use PostGIS in cygwin's PostgreSQL 7.1,2 on WinNT 4.0
> Server SP6.0a for a month. I've been very impressed with this
> extension's performance which can handle large-scale geospatial data.
>
Hi,

I have looked around once or twice for a PostgreSQL source for NT, but
didn't find any
pre-built binaries on the postgresql ftp site.  Did you build it
yourself from source under Cygwin?
Any special advice?

>  I'd like to use a function of C Clients (libpq) of PostGIS to create
> some applications, but still no description in PostGIS Manual.
>
There isn't really anything special with regard to PostGIS integration
with libpq.  Once you know
the SQL to use interactively with PostGIS, you just do the same thing
through libpq.  There is
respectible libpq documentation on the postgresql web site.

There is an example of code using libpq with postgis in my GDAL/OGR
library.  If you want
to look at it download the following and look in gdal/ogr/ogrsf_frmts/pg.

  ftp://ftp.remotesensing.org/pub/gdal/gdal-1.1.5b1.tar.gz

Best regards,

--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, [hidden email]
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent


To unsubscribe from this group, send an email to:
[hidden email]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



Reply | Threaded
Open this post in threaded view
|

RE: [postgis] About description of usage of C Clients (libpq) in PostGIS Manual

Norman Vine
Frank Warmerdam writes:
>
>I have looked around once or twice for a PostgreSQL source for NT, but
>didn't find any pre-built binaries on the postgresql ftp site.

Frank

PostGreSQL has been part of the Cygwin distribution for a while now.

Just rerun the cygwin setup program
< might have to click on experimental or all >

FYI
You will also need the Cygwin distributed source in order to build PostGIS

Cheers

Norman

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Small business owners...
Tell us what you think! http://promo2.yahoo.com/sbin/Yahoo!_BusinessNewsletter/survey.cgi
http://us.click.yahoo.com/vO1FAB/txzCAA/ySSFAA/PhFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[hidden email]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



Reply | Threaded
Open this post in threaded view
|

Re: [postgis] About description of usage of C Clients (libpq) in PostGIS Manual

David Blasby-3
In reply to this post by Hisaji ONO-3
>  This is my first message in this mailing list.

Welcome aboard.
 
>  I've tried to use PostGIS in cygwin's PostgreSQL 7.1,2 on WinNT 4.0
> Server SP6.0a for a month. I've been very impressed with this
> extension's performance which can handle large-scale geospatial data.

Excellent - Its good to hear from people who are using it.
 
>  I'd like to use a function of C Clients (libpq) of PostGIS to create
> some applications, but still no description in PostGIS Manual.

You can use it just like the normal libpq.  You should, first, decide if
you want binary access or text access.  

If you want text access you can easily get geometry in Well Known Text
(the WKT spec is at http://www.opengis.org/techno/specs/99-049.pdf) -
this will give you things like the string 'POINT(100 100)' or the string
'LINESTRING(0 0, 100 100)'.  WKT is a bit of a pain to parse.  You might
want to use the force_2d(geometry) to get results that are in 2D.

ie.
select force2d(mygeom),mydesc,mygeo_id from <table> where ...;

If you want binary access, you should check out the examples/readwkb.c
example in the PostGIS distribution or the examples in the postgresql
client (libpq) documentation from the postgresql website.  Basically,
you have to allocate a postgresql binary cursor, then execute a fetch
from it.  Unfortunately all the results are in binary format (and that
could mean endian problems if the client endian is not the same as the
server's).  

You have to convert the geometry column to Well Known Binary (the WKB
spec is also at http://www.opengis.org/techno/specs/99-049.pdf).  The
WKB format will specifies what endian its in. You do this with the
asbinary(geometry) function.   There are two version of this.

a) asbinary(geometry)  - returns geometry in WKB form with the
postgresql's server's endianess.
b) asbinary(geometry,'XDR') or asbinary(geometry,'NDR') - return
geometry in WKB form with
        the specified endian (NDR for i386 machines, and XDR for sparc
machines)

If you specify the endian to match the client machine, it will make the
WKB easier to parse.  To make it even easier to parse, you could also do
a force_collection(geometry) and the geometry will be returned as a
geometrycollection with points, lines, or polygons inside.  This is what
I do for the mapserver connector - it might not help you...

3D geometries are not specified in WKB, I use the same method as Frank
Warmerdam and add 32768 to the geometry type to indicate that the points
are 3d.  If you use the force2d(geometry) function, you'll never get 3d
points out.

One easy way around having all the other columns in binary format (and
endian problems) is to force postgresql to return the columns in text
format.  Its cheating, but its useful.

ie.
select asbinary(force2d(mygeom),'NDR'), text(mydesc), text(mygeo_id)
from <table> where ...;

dave
ps. Whats endian?  Basically the IEEE defined what information would be
in binary data types like integers and floating point numbers.
Unfortunately, they didnt specify the order of the bytes for these
types.  Different processor companies decided to do it differently.
Basically, to convert endian you just have to reverse the order of the
bytes.  Ie. to convert a 4-byte integer (bytes 1 2 3 4) in BIG ENDIAN to
LITTLE ENDIAN you just re-order the bytes as (4 3 2 1).

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Small business owners...
Tell us what you think! http://promo2.yahoo.com/sbin/Yahoo!_BusinessNewsletter/survey.cgi
http://us.click.yahoo.com/vO1FAB/txzCAA/ySSFAA/PhFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[hidden email]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



Reply | Threaded
Open this post in threaded view
|

Re: [postgis] About description of usage of C Clients (libpq) in PostGIS Manual

Hisaji ONO-3
In reply to this post by Frank Warmerdam
Hi, Frank.

> Hi,
>
> I have looked around once or twice for a PostgreSQL source for NT, but
> didn't find any
> pre-built binaries on the postgresql ftp site.  Did you build it
> yourself from source under Cygwin?
> Any special advice?
>

 For building PostgreSQL 7.1.2 in Cygwin, I've no trouble.

 Pre-built binaries is available from the following site, but this binariies
were build with multtibyte and EUC-JP(Japanese character code.). And the
document was written in Japanese.


http://www.s34.co.jp/~luster/pgsql/postgresql7.1.2-cygwin117-mb-unicode.tar.
bz2

> There isn't really anything special with regard to PostGIS integration
> with libpq.  Once you know
> the SQL to use interactively with PostGIS, you just do the same thing
> through libpq.  There is
> respectible libpq documentation on the postgresql web site.
>
> There is an example of code using libpq with postgis in my GDAL/OGR
> library.  If you want
> to look at it download the following and look in gdal/ogr/ogrsf_frmts/pg.
>
>   ftp://ftp.remotesensing.org/pub/gdal/gdal-1.1.5b1.tar.gz
>

  Thank you very muh for above info for libpq. I'll try to execute your
sample.

 Best regards.




------------------------ Yahoo! Groups Sponsor ---------------------~-->
Secure your servers with 128-bit SSL encryption! Grab your copy of
VeriSign's FREE Guide "Securing Your Web Site for Business." Get it now!
http://www.verisign.com/cgi-bin/go.cgi?a=n094442340008000
http://us.click.yahoo.com/6lIgYB/IWxCAA/yigFAA/PhFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[hidden email]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/