How to easily compute distance between two geometries in meters

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to easily compute distance between two geometries in meters

Coquelicot-2
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 on-the-fly into PostGIS geography objects, but to no avail...


Best regards,

Lukasz

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How to easily compute distance between two geometries in meters

Juan Marín Otero
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 on-the-fly into PostGIS geography objects, but to no avail...


Best regards,

Lukasz

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users




--
Juan Marín Otero
GIS Consultant

-------Visita mi blog en---------------------
http://guachintoneando.blogspot.com
---------------------------------------------------

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How to easily compute distance between two geometries in meters

shane
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




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 on-the-fly into PostGIS geography objects, but to no avail...


Best regards,

Lukasz

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users




--
Juan Marín Otero
GIS Consultant

-------Visita mi blog en---------------------
http://guachintoneando.blogspot.com
---------------------------------------------------

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users




--
Shane StClair
Software Engineer
Axiom Consulting & Design
523 W 8th Ave
Suite 104
Anchorage, AK 99501
Website: http://www.axiomalaska.com

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How to easily compute distance between two geometries in meters

shane
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




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 on-the-fly into PostGIS geography objects, but to no avail...


Best regards,

Lukasz

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users




--
Juan Marín Otero
GIS Consultant

-------Visita mi blog en---------------------
http://guachintoneando.blogspot.com
---------------------------------------------------

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users




--
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

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How to easily compute distance between two geometries in meters

Coquelicot-2
In reply to this post by Juan Marín Otero
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




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 on-the-fly into PostGIS geography objects, but to no avail...


Best regards,

Lukasz

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users




--
Juan Marín Otero
GIS Consultant

-------Visita mi blog en---------------------
http://guachintoneando.blogspot.com
---------------------------------------------------


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users