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