[postgis-users] Spatial Object Queries - complete

Norman Barker nbarker at ittvis.com
Thu Feb 1 01:27:57 PST 2007


Hi Antonio,

Thanks for your comments, I have answered inline;

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Antonio Pace
Sent: 31 January 2007 20:32
To: 'PostGIS Users Discussion'
Subject: R: [postgis-users] Spatial Object Queries - complete

Hi Norman your work is very interesting, I have two questions:

The first.


>Query union = entityManager.createQuery("Select spatial.Union(p.location,
person.location) from >PersonEntity p, PersonEntity as person where person =
:person"); union.setParameter("person", p);

>The result is a person object (with a location geometry field).

The result is  a person which own geometry field is the Union of p.location
and person.location or the result is a geometry (user defined type)  that
rapresent the union?

<ncb>
Ok, my typos, the result of the union query is a Geometry object that is created by the geometry type, however the result of a query like 'from PersonEntity p where spatial.xxx(...)=..' would be a populated PersonEntity.

So running the union query on my points table the result is

UNION
[POINT(0.3 52), MULTIPOINT(20 20,0.3 52), MULTIPOINT(0 52,0.3 52), MULTIPOINT(0 52,0.3 52), MULTIPOINT(0 52,0.3 52)]

</ncb>

In PostGISDialect.java :

registerFunction( PostGISDialect.NAMESPACE + "union", new
StandardSQLFunction("geomunion", Hibernate.custom(GeometryType.class)));


The second (in ejb3 enviroment).

It is possible to use a parameter of type "GeometryType"  in these function?

Example:


Query distance = entityManager.createQuery("Select
spatial.Distance(p.location, :point) from PersonEntity p, where person =
:person");

distance.setParameter("person", thePerson);

org.hibernate.ejb.QueryImpl hs = (QueryImpl) query;

org.hibernate.Query hbQuery = hs.getHibernateQuery();
         
hbQuery.setParameter("point ", thePoint,
org.hibernate.Hibernate.custom(com.mygeometrytypes.GeometryUserType.class));

<ncb>
This is where we get to the (current) debate about the functionality of ejb-ql and hql, since we can't pass the class type in with ejb-ql.

You can pass the point parameter in as a plain geometry, the tostring method will render it in WKT and the query will work in ejb-ql and hql.
</ncb>

         
return hbQuery.list();


This is right?

<ncb>

Hope you find this useful, and please do contribute back to it.  I appreciate that not everyone will find this interesting, but the current fashion for hibernate and ORM designer tools means I hope this helps PostGIS.
</ncb>


Many thanks,

A.

-----Messaggio originale-----
Da: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] Per conto di Norman
Barker
Inviato: mercoledì 31 gennaio 2007 18.46
A: PostGIS Users Discussion
Oggetto: [postgis-users] Spatial Object Queries - complete

Hi,

After much time (and in the end a stupid mistake on my part of not
recognizing namespaces) I have added the code to do spatial object queries
(HibernateQL (HQL) and EJB(3)-QL) with PostGIS.
hi norman your work is very interesting, I have two questions:


In the attached there is a service file PostGISService.java which exercises
all the functionality of PostGIS from Java Object Queries.

The advantage here is that when you perform these queries you get complex
objects back containing your data (no parsing of resultsets) and these
queries are polymorphic (so include sub-classes). e.g. 

If you use JBoss EJBs (rather than Spring + Hibernate) you will get an
implicit transaction lock on the entity as well.

Hopefully someone finds it of use since the hibernate dialect is portable,
it could be used for a WFS-T, Catalog etc. specific for PostGIS.

My next step is to make it portable across DBs, and to integrate with SOLR
to give a catalog type interface.

Hopefully you are happy to keep this with PostGIS, and give me commit access
to SVN so that I don't have to attach files!!

Many thanks,

Norman   



_______________________________________________
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