[postgis-users] Hibernate Spatial Postgis 3D
Max
postgis at lists.meisel.cn
Wed May 7 08:04:07 PDT 2008
Hello,
first i want to thank Karel for the great hibernate-spatial extension.
Using this extension saves a lot of time.
These days i got the new sources from the svn, because i saw that Karel
was implementing the 3D stuff for the postgis-provider. So far so good.
After compiling and using the new provider i found out, that it doesnt
work for me, so maybe someone can help me to solve the problem. Writing
a 3D point to the postgis-db still returns a 2D point, so i dont know
whats wrong.
My files are looking like this (parts - taken from hibernate spatial
example)):
----------------------------
...hmb.xml
<property name="theGeom" type="org.hibernatespatial.GeometryUserType">
<column name="the_geom" />
</property>
----------------------------
Class File
import com.vividsolutions.jts.geom.Point;
...
public class Grd
private Point theGeom;
public Point getTheGeom() {
return this.theGeom;
}
public void setTheGeom(Point theGeom) {
this.theGeom = theGeom;
}
-------------------------------
hibernateTest.java
hibernateTest hbTest = new hibernateTest();
hbTest.createAndStoreEvent("POINT(12 14 15)");
HibernateUtil.getSessionFactory().close();
.........
private void createAndStoreEvent(String wktPoint) {
// First interpret the WKT string to a point
WKTReader fromText = new WKTReader();
Geometry geom = null;
try {
geom = fromText.read(wktPoint);
}
catch (ParseException e) {
throw new RuntimeException("Not a WKT string:" + wktPoint);
}
if (!geom.getGeometryType().equals("Point")) {
throw new RuntimeException("Geometry must be a point. Got a " + geom.getGeometryType());
}
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Grd theGrd = new Grd();
Point p = (Point) geom;
// at this point there is an Z-Coordinate ///
System.out.println(p.getCoordinate().z);
theGrd.setTheGeom(p);
session.save(theGrd);
session.getTransaction().commit();
HibernateUtil.getSessionFactory().close();
--------------------------
After reading the Point from the DB using:
private List<Grd> findAll() {
Session session =
HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Criteria testCriteria = session.createCriteria(Dgm050Grd.class);
List<Dgm050Grd> results = testCriteria.list();
session.getTransaction().commit();
return results;
// the Point has not Z-Coordinate, its just NaN
So whats wrong? I know to appreciate your hekp
best regards
Steffen
More information about the postgis-users
mailing list