[postgis-users] Hibernate Spatial Postgis 3D
Max
postgis at lists.meisel.cn
Wed May 7 21:24:36 PDT 2008
Hallo Drew,
well, i'm creating the schema for hibernate, i was using the example on
hibernatespatial.org and yes, i'm using the wktreader from vivid
solutions, but if you lookat the new source code for the
hibernate-spatial-postgisprovider
http://www.hibernatespatial.org/websvn/filedetails.php?repname=hibernate-spatial&path=%2Ftrunk%2Fhibernate-spatial-postgis%2Fsrc%2Fmain%2Fjava%2Forg%2Fhibernatespatial%2Fpostgis%2FPGGeometryUserType.java&rev=0&sc=0
you can see that it shoudl handle 3D Coordinates, because of the code in
the methods:
protected com.vividsolutions.jts.geom.Point convertPoint(Point pnt)
and
private Point convertJTSPoint(com.vividsolutions.jts.geom.Point point)
but i still dont know how to use it ....
best regards, Max
> Hi Max,
>
> What is your schema? Is hibernate creating it for you or are you creating it for hibernate?
>
> And if that is the WKTReader from VividSolutions, then you'll notice at: http://www.vividsolutions.com/JTS/JTSHome.htm that the API only handles 2D.
>
> HTH
>
> Drew
>
> On Thu, May 8, 2008 at 1:04 AM, Max <postgis at lists.meisel.cn> wrote:
> 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(Grd.class);
> > List<Grd> 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
> >
> > Max
> >
> > _______________________________________________
> > 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