[postgis-users] Problem with Z coordinate using postgis-jts
Fernando González
fergonco at gmail.com
Thu Mar 6 01:31:39 PST 2008
After debugging a bit I have found that the postgis-jts code identifies
perfectly the dimension. I think the problem is in JTS. If anyone is
interested, I have made this test:
CoordinateSequence cs = new PackedCoordinateSequence.Double(1, 2);
cs.setOrdinate(0, 0, 10);
cs.setOrdinate(0, 1, 10);
Coordinate coord = cs.toCoordinateArray()[0];
System.out.println(coord);
and it outputs:
(10.0, 10.0, 0.0)
instead of
(10.0, 10.0, NaN)
I'm moving to the JTS mailing list. Thanks for the help.
Fernando.
On Thu, Mar 6, 2008 at 10:17 AM, Fernando González <fergonco at gmail.com>
wrote:
> Thanks Kevin. I'm using your solution. However, there is another real
> difference: it takes twice the time to parse with that method. I have
> inserted this code to test:
> String geom = rs.getString(2);
>
> WKBReader reader = new WKBReader();
> JtsBinaryParser parser = new JtsBinaryParser();
> String bytes = rs.getString(2);
> long t1 = System.currentTimeMillis();
> for (int i = 0; i < 1000000; i++) {
> Geometry g = parser.parse(bytes);
> }
> long t2 = System.currentTimeMillis();
> System.out.println((t2 - t1) / 1000000.0);
> t1 = System.currentTimeMillis();
> for (int i = 0; i < 1000000; i++) {
> Geometry g = reader.read(WKBReader.hexToBytes(geom));
> }
> t2 = System.currentTimeMillis();
> System.out.println((t2 - t1) / 1000000.0);
>
> Is the postgis-jts stuff supported at all? My ignorance says it's not
> difficult to fix... I'm taking a look at the source to see if I can see
> something.
>
> Fernando.
>
>
>
>
> On Wed, Mar 5, 2008 at 10:22 PM, Kevin Neufeld <kneufeld at refractions.net>
> wrote:
>
> > Alternatively, don't use the postgis jar at all ... use a regular
> > postgres driver and JTS. This yields the results you are looking for.
> > The only real difference here is the use of WKBReader instead of
> > JtsBinaryParser.
> >
> > public static void main(String[] args) throws Throwable {
> > Class.forName("org.postgresql.Driver").newInstance();
> > String sql = "CREATE TABLE test (pk_0 int4 NOT NULL);";
> > sql += "select
> > AddGeometryColumn('test','the_geom','-1','GEOMETRY','2');";
> > sql += "insert into test " + "values(3, "
> > + "GeomFromText('LINESTRING(191232 243118,191108
> > 243242)',-1));";
> >
> > Connection c = DriverManager.getConnection(
> > "jdbc:postgresql://turtle:9876/cwb/",
> > "postgres",
> > "postgres");
> >
> > Statement st = c.createStatement();
> > try {
> > st.execute("drop table test");
> > } catch (SQLException e) {
> >
> > }
> > st.execute(sql);
> >
> > ResultSet rs = st.executeQuery("select * from test");
> > rs.next();
> > String geom = rs.getString(2);
> > WKBReader reader = new WKBReader();
> > Geometry g = reader.read(WKBReader.hexToBytes(geom));
> > Coordinate[] coords = g.getCoordinates();
> > for (int i = 0; i < coords.length; i++) {
> > System.out.println(coords[i]);
> > }
> > }
> >
> > -- output is
> > (191232.0, 243118.0, NaN)
> > (191108.0, 243242.0, NaN)
> >
> > -------------
> > Kevin Neufeld
> > Software Developer
> > Refractions Research Inc.
> > 300-1207 Douglas St.
> > Victoria, B.C., V8W 2E7
> >
> > Phone: (250) 383-3022
> > Email: kneufeld at refractions.net
> >
> >
> >
> > Fernando González wrote:
> > > Thank you for the answer. When I execute this code:
> > >
> > > public static void main(String[] args) throws Throwable {
> > > Class.forName("org.postgresql.Driver").newInstance();
> > > String sql = "CREATE TABLE test (pk_0 int4 NOT NULL);";
> > > sql += "select
> > > AddGeometryColumn('test','the_geom','-1','GEOMETRY','2');";
> > > sql += "insert into test "
> > > + "values(3, "
> > > + "GeomFromText('LINESTRING(191232 243118,191108
> > > 243242)',-1));";
> > >
> > > Connection c = DriverManager
> > >
> > .getConnection("jdbc:postgresql://127.0.0.1/gdms/test",
> > > "postgres", "postgres");
> > > ((PGConnection) c)
> > > .addDataType("geometry", org.postgis.PGgeometry.class
> > );
> > > ((PGConnection) c).addDataType("box3d",
> > > org.postgis.PGbox3d.class);
> > >
> > > Statement st = c.createStatement();
> > > try {
> > > st.execute("drop table test");
> > > } catch (SQLException e) {
> > >
> > > }
> > > st.execute(sql);
> > >
> > > ResultSet rs = st.executeQuery("select * from test");
> > > rs.next();
> > > String geom = rs.getString(2);
> > > JtsBinaryParser parser = new JtsBinaryParser();
> > > Geometry g = parser.parse(geom);
> > > Coordinate[] coords = g.getCoordinates();
> > > for (Coordinate coordinate : coords) {
> > > System.out.println(coordinate);
> > > }
> > > }
> > >
> > > I obtain this output:
> > > (191232.0, 243118.0, 0.0)
> > > (191108.0, 243242.0, 0.0)
> > >
> > > I think I should obtain
> > > (191232.0, 243118.0, NaN)
> > > (191108.0, 243242.0, NaN)
> > >
> > > am I wrong?
> > >
> > >
> > > Fernando.
> > >
> > > On Wed, Mar 5, 2008 at 12:14 PM, Mark Cave-Ayland
> > > <mark.cave-ayland at siriusit.co.uk
> > > <mailto:mark.cave-ayland at siriusit.co.uk>> wrote:
> > >
> > > On Wednesday 05 March 2008 10:13:26 Fernando González wrote:
> > > > Hi,
> > > >
> > > > I'm storing and reading some geometries from a postgis table.
> > > The table is
> > > > 2D. I'm using a jar I have compiled with the "make postgis_jts"
> > > command. It
> > > > works very well except for one thing. I write 2D JTS geometries,
> > > this is
> > > > with the z component equal to NaN, into a postgis table but when
> > > I read
> > > > them the Z coordinate is no longer equal to NaN but equal to 0.
> > > is this a
> > > > feature? a bug?
> > > >
> > > > I'm using this code to read the geometry. To store them I use
> > > GeomFromText
> > > > function and I specify only X-Y components for each coordinate
> > > (I'm not
> > > > specifying the Z coordinate):
> > > >
> > > > JtsBinaryParser parser = new JtsBinaryParser();
> > > > String bytes = rs.getString(fieldId);
> > > > Geometry geom = parser.parse(bytes);
> > > >
> > > > is it clear? I can write some code to reproduce the problem if
> > > anyone is
> > > > interested.
> > > >
> > > > Thanks in advance,
> > > > Fernando
> > >
> > >
> > > Hi Fernando,
> > >
> > > Yes please. I may not be the person that eventually looks at this,
> > > however a
> > > reproducible test case is enormously helpful in cases like these.
> > >
> > >
> > > ATB,
> > >
> > > Mark.
> > >
> > > --
> > > Mark Cave-Ayland
> > > Sirius Corporation - The Open Source Experts
> > > http://www.siriusit.co.uk
> > > T: +44 870 608 0063
> > > _______________________________________________
> > > postgis-users mailing list
> > > postgis-users at postgis.refractions.net
> > > <mailto:postgis-users at postgis.refractions.net>
> > > http://postgis.refractions.net/mailman/listinfo/postgis-users
> > >
> > >
> > >
> > ------------------------------------------------------------------------
> > >
> > > _______________________________________________
> > > postgis-users mailing list
> > > postgis-users at postgis.refractions.net
> > > http://postgis.refractions.net/mailman/listinfo/postgis-users
> > >
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users at postgis.refractions.net
> > http://postgis.refractions.net/mailman/listinfo/postgis-users
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080306/eb17ee04/attachment.html>
More information about the postgis-users
mailing list