[postgis] JDBC and WKB; shp2postgresql

Paul Ramsey pramsey at refractions.net
Sat Nov 24 20:47:59 PST 2001


Your numbering is a little funny (1,2,2,3) :) but I'll take a try
anyways:

> First question:
> Does anyone have some examples on how to insert and retreive geometry
> using WKB and JDBC:

No, because as far as I can tell, it cannot be done. I have gone through
the postgresql jdbc driver, and it looks to me like it is restricted to
text cursors. If someone knows or has done different I would be
interested to see the results.

> -------------------------------------------------------
> Second question:
> According to the OpenGIS SQL specicification an insert using WKB
> would use the following format:
> INSERT INTO Countries (Name, Location) VALUES ('Kenya', PolygonFromWKB
> (:wnb, :srid)).
> 
> Using this format, how do you insert an WKB object using JDBC?

Again, unfortunately WKB just is not on the agenda using the JDBC
driver.

> As an example, if I have this:
> 
> Polygon polygon = new Polygon(...);
> ....
> PreparedStatement pstmt = cnn.prepareStatement("INSERT INTO Countries
> (Name, Location) VALUES ('Kenya', ?)
> pstmt.setOject(1, polygon)
> How would I implement PolgyonFromWKB(:wkb, :srid)?

Not entirely sure what is being asked here, but see the comments above,
as they might have a bearing.

> ----------------------------------------------------
> 
> Second question:
> Is the following the correct way to retreive an object using JDBC and
> WKB?
> 
> ResultSet rst = cnn.executeQuery("SELECT Name, AsBinary(Location)
> FROM Countries WHERE Name like 'k%');
> while(r.next()){
>   String name = r.getString(1)
>   PGgeometry geometry = (PGgeometry)r.getObject(2);
> }

What is actually happening behind the scenes when you do this is that
the proxy object PGgeometry is parsing the WKT representation of the
object. It is nice because you do not have to worry about parsing, but
it is not WKB, it is just hiding the WKT for you.

> ------------------------------------------------------
> Third question:
> If I insert an object as text, can I retreive it as binary, and vice-
> versa -- If I insert it as binary, can I retreive it as text?

Yes, absolutely. In the database, there is just one geometry
representation, a C struct. The WKT and WKB representations are
generated on the fly when requested. You can make a geometry from either
representation and you can retrieve a geometry as either representation.
In fact, the idea of an AsGML() function is Yet Another Way to retrieve
geometries. 
(If anyone wants to do AsGML() it would be a great simple function for
someone to add as a learning project...)

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Need new boots for winter? Looking for a perfect gift for your shoe loving friends?
Zappos.com is the perfect fit for all your shoe needs!
http://us.click.yahoo.com/3wM6yD/QrSDAA/ySSFAA/PhFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
postgis-unsubscribe at yahoogroups.com

 

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





More information about the postgis-users mailing list