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:<br><br>        CoordinateSequence cs = new PackedCoordinateSequence.Double(1, 2);<br>
<br>        cs.setOrdinate(0, 0, 10);<br>        cs.setOrdinate(0, 1, 10);<br><br>        Coordinate coord = cs.toCoordinateArray()[0];<br>        System.out.println(coord);<br><br>and it outputs:<br>(10.0, 10.0, 0.0)<br>
instead of<br>(10.0, 10.0, NaN)<br><br>I'm moving to the JTS mailing list. Thanks for the help.<br><br>Fernando.<br><br><br><div class="gmail_quote">On Thu, Mar 6, 2008 at 10:17 AM, Fernando González <<a href="mailto:fergonco@gmail.com">fergonco@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">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:<div class="Ih2E3d">
<br>        String geom = rs.getString(2);<br><br>        WKBReader reader = new WKBReader();<br></div>
        JtsBinaryParser parser = new JtsBinaryParser();<br>        String bytes = rs.getString(2);<br>        long t1 = System.currentTimeMillis();<br>        for (int i = 0; i < 1000000; i++) {<br>            Geometry g = parser.parse(bytes);<br>

        }<br>        long t2 = System.currentTimeMillis();<br>        System.out.println((t2 - t1) / 1000000.0);<br>        t1 = System.currentTimeMillis();<br>        for (int i = 0; i < 1000000; i++) {<div class="Ih2E3d">
<br>            Geometry g = reader.read(WKBReader.hexToBytes(geom));<br>
        }<br></div>        t2 = System.currentTimeMillis();<br>        System.out.println((t2 - t1) / 1000000.0);<br><br>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.<br>
<font color="#888888">
<br>Fernando.</font><div><div></div><div class="Wj3C7c"><br><br><br><br><div class="gmail_quote">On Wed, Mar 5, 2008 at 10:22 PM, Kevin Neufeld <<a href="mailto:kneufeld@refractions.net" target="_blank">kneufeld@refractions.net</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Alternatively, don't use the postgis jar at all ... use a regular<br>
postgres driver and JTS.  This yields the results you are looking for.<br>
The only real difference here is the use of WKBReader instead of<br>
JtsBinaryParser.<br>
<div><br>
    public static void main(String[] args) throws Throwable {<br>
        Class.forName("org.postgresql.Driver").newInstance();<br>
        String sql = "CREATE TABLE test (pk_0 int4 NOT NULL);";<br>
        sql += "select<br>
AddGeometryColumn('test','the_geom','-1','GEOMETRY','2');";<br>
        sql += "insert into test " + "values(3, "<br>
                + "GeomFromText('LINESTRING(191232 243118,191108<br>
243242)',-1));";<br>
<br>
        Connection c = DriverManager.getConnection(<br>
</div>            "jdbc:postgresql://turtle:9876/cwb/",<br>
            "postgres",<br>
            "postgres");<br>
<div><br>
        Statement st = c.createStatement();<br>
        try {<br>
            st.execute("drop table test");<br>
        } catch (SQLException e) {<br>
<br>
        }<br>
        st.execute(sql);<br>
<br>
        ResultSet rs = st.executeQuery("select * from test");<br>
        rs.next();<br>
        String geom = rs.getString(2);<br>
</div>        WKBReader reader = new WKBReader();<br>
        Geometry g = reader.read(WKBReader.hexToBytes(geom));<br>
        Coordinate[] coords = g.getCoordinates();<br>
        for (int i = 0; i < coords.length; i++) {<br>
            System.out.println(coords[i]);<br>
        }<br>
    }<br>
<br>
-- output is<br>
<div>(191232.0, 243118.0, NaN)<br>
(191108.0, 243242.0, NaN)<br>
<br>
</div>-------------<br>
Kevin Neufeld<br>
Software Developer<br>
Refractions Research Inc.<br>
300-1207 Douglas St.<br>
Victoria, B.C., V8W 2E7<br>
<br>
Phone: (250) 383-3022<br>
Email: <a href="mailto:kneufeld@refractions.net" target="_blank">kneufeld@refractions.net</a><br>
<div><div></div><div><br>
<br>
<br>
Fernando González wrote:<br>
> Thank you for the answer. When I execute this code:<br>
><br>
>     public static void main(String[] args) throws Throwable {<br>
>         Class.forName("org.postgresql.Driver").newInstance();<br>
>         String sql = "CREATE TABLE test (pk_0 int4 NOT NULL);";<br>
>         sql += "select<br>
> AddGeometryColumn('test','the_geom','-1','GEOMETRY','2');";<br>
>         sql += "insert into test "<br>
>                 + "values(3, "<br>
>                 + "GeomFromText('LINESTRING(191232 243118,191108<br>
> 243242)',-1));";<br>
><br>
>         Connection c = DriverManager<br>
>                 .getConnection("jdbc:postgresql://127.0.0.1/gdms/test",<br>
>                         "postgres", "postgres");<br>
>         ((PGConnection) c)<br>
>                 .addDataType("geometry", org.postgis.PGgeometry.class);<br>
>         ((PGConnection) c).addDataType("box3d",<br>
> org.postgis.PGbox3d.class);<br>
><br>
>         Statement st = c.createStatement();<br>
>         try {<br>
>             st.execute("drop table test");<br>
>         } catch (SQLException e) {<br>
><br>
>         }<br>
>         st.execute(sql);<br>
><br>
>         ResultSet rs = st.executeQuery("select * from test");<br>
>         rs.next();<br>
>         String geom = rs.getString(2);<br>
>         JtsBinaryParser parser = new JtsBinaryParser();<br>
>         Geometry g = parser.parse(geom);<br>
>         Coordinate[] coords = g.getCoordinates();<br>
>         for (Coordinate coordinate : coords) {<br>
>             System.out.println(coordinate);<br>
>         }<br>
>     }<br>
><br>
> I obtain this output:<br>
> (191232.0, 243118.0, 0.0)<br>
> (191108.0, 243242.0, 0.0)<br>
><br>
> I think I should obtain<br>
> (191232.0, 243118.0, NaN)<br>
> (191108.0, 243242.0, NaN)<br>
><br>
> am I wrong?<br>
><br>
><br>
> Fernando.<br>
><br>
> On Wed, Mar 5, 2008 at 12:14 PM, Mark Cave-Ayland<br>
> <<a href="mailto:mark.cave-ayland@siriusit.co.uk" target="_blank">mark.cave-ayland@siriusit.co.uk</a><br>
</div></div><div><div></div><div>> <mailto:<a href="mailto:mark.cave-ayland@siriusit.co.uk" target="_blank">mark.cave-ayland@siriusit.co.uk</a>>> wrote:<br>
><br>
>     On Wednesday 05 March 2008 10:13:26 Fernando González wrote:<br>
>     > Hi,<br>
>     ><br>
>     > I'm storing and reading some geometries from a postgis table.<br>
>     The table is<br>
>     > 2D. I'm using a jar I have compiled with the "make postgis_jts"<br>
>     command. It<br>
>     > works very well except for one thing. I write 2D JTS geometries,<br>
>     this is<br>
>     > with the z component equal to NaN, into a postgis table but when<br>
>     I read<br>
>     > them the Z coordinate is no longer equal to NaN but equal to 0.<br>
>     is this a<br>
>     > feature? a bug?<br>
>     ><br>
>     > I'm using this code to read the geometry. To store them I use<br>
>     GeomFromText<br>
>     > function and I specify only X-Y components for each coordinate<br>
>     (I'm not<br>
>     > specifying the Z coordinate):<br>
>     ><br>
>     > JtsBinaryParser parser = new JtsBinaryParser();<br>
>     > String bytes = rs.getString(fieldId);<br>
>     > Geometry geom = parser.parse(bytes);<br>
>     ><br>
>     > is it clear? I can write some code to reproduce the problem if<br>
>     anyone is<br>
>     > interested.<br>
>     ><br>
>     > Thanks in advance,<br>
>     > Fernando<br>
><br>
><br>
>     Hi Fernando,<br>
><br>
>     Yes please. I may not be the person that eventually looks at this,<br>
>     however a<br>
>     reproducible test case is enormously helpful in cases like these.<br>
><br>
><br>
>     ATB,<br>
><br>
>     Mark.<br>
><br>
>     --<br>
>     Mark Cave-Ayland<br>
>     Sirius Corporation - The Open Source Experts<br>
>     <a href="http://www.siriusit.co.uk" target="_blank">http://www.siriusit.co.uk</a><br>
>     T: +44 870 608 0063<br>
>     _______________________________________________<br>
>     postgis-users mailing list<br>
>     <a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a><br>
</div></div>>     <mailto:<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a>><br>
<div>>     <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
><br>
><br>
</div>> ------------------------------------------------------------------------<br>
<div><div></div><div>><br>
> _______________________________________________<br>
> postgis-users mailing list<br>
> <a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a><br>
> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
><br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>