[postgis-users] How to instanziate the Geometry class from the geometry string?

martinelli at pi.ingv.it martinelli at pi.ingv.it
Thu Oct 5 08:29:32 PDT 2006


Hi Markus,
during my last email I thought I got the solution, as method
org.postgis.binary.binaryWriter.writeHexed()

returned the same string as I received from the database, and indeed the
same string as showed querying pgadmin3.

Nevertheless, when I moved my sptes forward and tried to really connect to
the databse for updating the geometry data, the following error came up:
org.postgresql.util.PSQLException: ERROR: column "the_geom" is of type
geometry but expression is of type character
        at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1525)
        at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1309)
        at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:354)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:308)

Is there something I missed?

Thank you very much,
Francesco.

> Hi, Martinelli,
>
> martinelli at pi.ingv.it wrote:
>
>> OJB requires the table fields to be defined as one of the types defined
>> in
>> java.sql.Types in its configuration file, therefore POINT is not
>> allowed.
>> Using VARCHAR I receive the geometry data string.
>
> I'm afraid that you'll have to go the way of receiving them as VARCHAR,
> unless OJB begins to support java.sql.Types.Other.
>
>> However, to convert the geometry value received from the table I need to
>> write the "serializer" to create the geometry instance (of class Point
>> in
>> my case).
>
>> What method(s) I need to call to instanziate the proper class?
>> Please consider I have only the geometry string returned by the
>> database,
>> and it is not in WKB or WKT format.
>
> The geometry string from the database (should be a bunch of hex
> characters) is Hexed EWKB, an downwards-compatible PostGIS extension (to
> include SRIDs and measures) of the OpenGIS standard WKB (Well Known
> Binary). It is converted to hex as the JDBC driver currently drives the
> connection in text mode, the same as pgadmin3 or the psql command line.
>
> As a side note, PostGIS 0.X delivered E(xtended) WKT formats, PostGIS
> 1.X will deliver pure EWKB when the PostgreSQL connection is driven in
> binary mode.
>
> The org.postgis.PGGeometry class has a method public static Geometry
> geomFromString(String value) that will happily parse WKT, EWKT, HexWKB
> and HexEWKB into the proper org.postgis.Geometry subclass.
>
> If you compile PostGIS with JTS support, the org.postgis.jts.JTSGeometry
> class geomFromString(String value) method will do the same with the
> appropriate com.vividsolutions.jts.geom.Geometry subclass.
>
> For the other way round (deserializer), you have the following
> possibilities:
> For org.postgis.Geometry:
> - .toString() delivers EWKT.
> - org.postgis.binary.binaryWriter.writeHexed() delivers HexEWKB.
>
> For jts Geometries.
> - .toSTring() delivers WKT.
> - org.postgis.jts.JtsBinaryWriter.writeHexed() delivers HexEWKB.
>
> The PostgreSQL backend will parse both EWKT and HexEWKB in text mode,
> and WKB in binary mode.
>
> HTH,
> Markus
> --
> Markus Schaber | Logical Tracking&Tracing International AG
> Dipl. Inf.     | Software Development GIS
>
> Fight against software patents in Europe! www.ffii.org
> www.nosoftwarepatents.org
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>





More information about the postgis-users mailing list