[postgis-users] Potential errors in JDBC documentation
Obe, Regina
robe.dnd at cityofboston.gov
Mon May 14 07:40:04 PDT 2007
I just noticed a couple of minor things in the jdbc documentation in the
postgis manual. I'm a bit rusty on my java programming so I will just
pose these as possible errors.
http://postgis.refractions.net/docs/ch04.html#id3032239
------------------------------------
Potential issue/error
ResultSet r = s.executeQuery("select
AsText(geom) as geom,id from geomtable"); while( r.next() ) { /* *
Retrieve the geometry as an object then cast it to the geometry
type. *
Print things out. */ PGgeometry geom = (PGgeometry)r.getObject(1);
----
Wouldn't it have been more efficient to just not bother casting this as
text before you pull it and does the above really work?
Shouldn't it be.
ResultSet r = s.executeQuery("select
geom,id from geomtable"); while( r.next() ) { /* *
Retrieve the geometry as an object then cast it to the geometry
type. *
Print things out. */ PGgeometry geom = (PGgeometry)r.getObject(1);
rather than first converting it to text and then converting back to an
object?
---
Potential issue/error 2
PGgeometry geom = (PGgeometry)r.getObject(1); if(
geom.getType() = Geometry.POLYGON ) { Polygon pl =
(Polygon)geom.getGeometry(); for( int r = 0; r < pl.numRings();
r++
) { LinearRing rng = pl.getRing(r); System.out.println("Ring: "
+ r); for( int p = 0; p < rng.numPoints(); p++ ) { Point pt =
rng.getPoint(p); System.out.println("Point: " + p);
System.out.println(pt.toString()); } } }
--
Shouldn't that be ==
PGgeometry geom = (PGgeometry)r.getObject(1); if(
geom.getType() == Geometry.POLYGON ) { Polygon pl =
(Polygon)geom.getGeometry(); for( int r = 0; r < pl.numRings();
r++
) { LinearRing rng = pl.getRing(r); System.out.println("Ring: "
+ r); for( int p = 0; p < rng.numPoints(); p++ ) { Point pt =
rng.getPoint(p); System.out.println("Point: " + p);
System.out.println(pt.toString()); } } }
-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070514/bd9f85c1/attachment.html>
More information about the postgis-users
mailing list