1

I'm trying to read a PostGIS geometry column and save it as a Java byte[] with hibernate.

As far as I know I should be storing it in Java the way it's represented in psql.

I manage to write it and even see it within psql but when I read it with the wkbreader - I get the following error:

com.vividsolutions.jts.io.ParseException: Unknown WKB type 48

0

3 Answers 3

2

PostGIS exports a ST_AsBinary function or (if you want to preserve SRID) ST_AsEWKB.

You should store the results of this function, rather than trying to cast the display representation, and then load with ST_GeomFromWKB or ST_GeomFromEWKB (depending on whether you used the AsBinary or AsEWKB form on output).

Sign up to request clarification or add additional context in comments.

Comments

1

I have seen this error resolved by upgrading the JDBC driver version. I'm able to able to read PostGIS geometry into JTS with the following:

Query:

SELECT ST_AsBinary(geom) FROM mytable;

Code:

// myWKBReader is a JTS WKBReader
// myResultSet is a JDBC ResultSet
Geometry geom = myWKBReader.read(myResultSet.getBytes("st_asbinary"));

POM:

  <dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.2-1003-jdbc4</version>
  </dependency>

Comments

0

Run this command as Postgres

ALTER DATABASE table SET bytea_output TO 'escape';

then restart Postgres.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.