

I'm trying to figure out the best way to calculate the distance between two geometries in meters to use with Hibernate Spatial. The 'distance()' function is supported in PostGIS but it returns the distance w degrees (as everything is at some point converted to JTS' Geometry object to be stored in the database). I know that I can perform a simple calculation to get the distance in meters, but as the earth is not a perfect sphere, there is an error.
I have also experimented in trying to converting onthefly into PostGIS geography objects, but to no avail...
Best regards,
_______________________________________________
hibernatespatialusers mailing list
[hidden email]
http://www.hibernatespatial.org/cgibin/mailman/listinfo/hibernatespatialusers


You could get the points as JTS geometries, get their coordinates, and apply the Haversine Formula [1] to compute the distance
On Thu, Mar 24, 2011 at 11:16 AM, Coquelicot <[hidden email]> wrote:
I'm trying to figure out the best way to calculate the distance between two geometries in meters to use with Hibernate Spatial. The 'distance()' function is supported in PostGIS but it returns the distance w degrees (as everything is at some point converted to JTS' Geometry object to be stored in the database). I know that I can perform a simple calculation to get the distance in meters, but as the earth is not a perfect sphere, there is an error.
I have also experimented in trying to converting onthefly into PostGIS geography objects, but to no avail...
Best regards,
_______________________________________________
hibernatespatialusers mailing list
[hidden email]
http://www.hibernatespatial.org/cgibin/mailman/listinfo/hibernatespatialusers
 Juan Marín Otero GIS Consultant Visita mi blog en http://guachintoneando.blogspot.com

_______________________________________________
hibernatespatialusers mailing list
[hidden email]
http://www.hibernatespatial.org/cgibin/mailman/listinfo/hibernatespatialusers


Alternatively, if you're trying to do this in the database, see this:
You could extend PostgisDialect and add the necessary methods.
Shane On Thu, Mar 24, 2011 at 8:25 AM, Shane StClair <[hidden email]> wrote:
Hi,
Have you looked into com.vividsolutions.jts.operation.distance.DistanceOp.distance(Geometry g0, Geometry g1)?
Shane
2011/3/24 Juan Marín Otero <[hidden email]>
You could get the points as JTS geometries, get their coordinates, and apply the Haversine Formula [1] to compute the distance
I'm trying to figure out the best way to calculate the distance between two geometries in meters to use with Hibernate Spatial. The 'distance()' function is supported in PostGIS but it returns the distance w degrees (as everything is at some point converted to JTS' Geometry object to be stored in the database). I know that I can perform a simple calculation to get the distance in meters, but as the earth is not a perfect sphere, there is an error.
I have also experimented in trying to converting onthefly into PostGIS geography objects, but to no avail...
Best regards,
_______________________________________________
hibernatespatialusers mailing list
[hidden email]
http://www.hibernatespatial.org/cgibin/mailman/listinfo/hibernatespatialusers
 Juan Marín Otero GIS Consultant Visita mi blog en http://guachintoneando.blogspot.com

_______________________________________________
hibernatespatialusers mailing list
[hidden email]
http://www.hibernatespatial.org/cgibin/mailman/listinfo/hibernatespatialusers
 Shane StClair Software Engineer Axiom Consulting & Design 523 W 8th Ave Suite 104 Anchorage, AK 99501 Website: http://www.axiomalaska.com
 Shane StClair Software Engineer Axiom Consulting & Design 523 W 8th Ave Suite 104 Anchorage, AK 99501 Website: http://www.axiomalaska.com
_______________________________________________
hibernatespatialusers mailing list
[hidden email]
http://www.hibernatespatial.org/cgibin/mailman/listinfo/hibernatespatialusers


Juan,
thanks for the quick answer  I was considering that but in my application I have to query the distances not only from the points but other geometries (lines, polygons etc) and I couldn´t find a solution for that...
Lukasz
2011/3/24 Juan Marín Otero <[hidden email]>
You could get the points as JTS geometries, get their coordinates, and apply the Haversine Formula [1] to compute the distance
I'm trying to figure out the best way to calculate the distance between two geometries in meters to use with Hibernate Spatial. The 'distance()' function is supported in PostGIS but it returns the distance w degrees (as everything is at some point converted to JTS' Geometry object to be stored in the database). I know that I can perform a simple calculation to get the distance in meters, but as the earth is not a perfect sphere, there is an error.
I have also experimented in trying to converting onthefly into PostGIS geography objects, but to no avail...
Best regards,
_______________________________________________
hibernatespatialusers mailing list
[hidden email]
http://www.hibernatespatial.org/cgibin/mailman/listinfo/hibernatespatialusers
 Juan Marín Otero GIS Consultant Visita mi blog en http://guachintoneando.blogspot.com

_______________________________________________
hibernatespatialusers mailing list
[hidden email]
http://www.hibernatespatial.org/cgibin/mailman/listinfo/hibernatespatialusers

