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:<br> String geom = rs.getString(2);<br><br> WKBReader reader = new WKBReader();<br>
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++) {<br> Geometry g = reader.read(WKBReader.hexToBytes(geom));<br>
}<br> 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>
<br>Fernando.<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">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 class="Ih2E3d"><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 class="Ih2E3d"><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 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>
> 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">mark.cave-ayland@siriusit.co.uk</a><br>
</div></div><div><div></div><div class="Wj3C7c">> <mailto:<a href="mailto:mark.cave-ayland@siriusit.co.uk">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">postgis-users@postgis.refractions.net</a><br>
</div></div>> <mailto:<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a>><br>
<div class="Ih2E3d">> <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 class="Wj3C7c">><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>
><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>