Is there any library to calculate the geographic distance between two points?

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

Is there any library to calculate the geographic distance between two points?

Paul DeBruicker
I've got a few objects with latitude and longitude and want to be able to find the nearest from a collection


Thanks

Paul
Reply | Threaded
Open this post in threaded view
|

Re: Is there any library to calculate the geographic distance between two points?

Paul DeBruicker
umm ... here is a good place to start

http://forum.world.st/Geo-coordinates-operations-td4732373.html#a4732441


Paul DeBruicker wrote
I've got a few objects with latitude and longitude and want to be able to find the nearest from a collection


Thanks

Paul
Reply | Threaded
Open this post in threaded view
|

Re: Is there any library to calculate the geographic distance between two points?

Sven Van Caekenberghe-2
Hi Paul,

This is what we use (given WGS84 coordinates)

T3GeoTools class>>#distanceBetween: firstPosition and: secondPosition
        "T3GeoTools distanceBetween: 5.33732@50.926 and: 5.49705@50.82733"

        | c |
        c := (firstPosition y degreeSin * secondPosition y degreeSin)
                + (firstPosition y degreeCos * secondPosition y degreeCos
                        * (secondPosition x degreesToRadians - firstPosition x degreesToRadians) cos).
        c := c >= 0 ifTrue: [ 1 min: c ] ifFalse: [ -1 max: c ].
        ^ c arcCos * 6371000

Sven

> On 05 Oct 2016, at 23:28, Paul DeBruicker <[hidden email]> wrote:
>
> umm ... here is a good place to start
>
> http://forum.world.st/Geo-coordinates-operations-td4732373.html#a4732441
>
>
>
> Paul DeBruicker wrote
>> I've got a few objects with latitude and longitude and want to be able to
>> find the nearest from a collection
>>
>>
>> Thanks
>>
>> Paul
>
>
>
>
>
> --
> View this message in context: http://forum.world.st/Is-there-any-library-to-calculate-the-geographic-distance-between-two-points-tp4918207p4918208.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: Is there any library to calculate the geographic distance between two points?

hernanmd
Hi Sven,

Are you ok if I integrate your code into Territorial?

I'd like to have

'Ottawa@CA' asTerritoiralCity distanceWGS84To: 'Rome@IT' asTerritorialCity

Hernán


2016-10-05 19:00 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:
Hi Paul,

This is what we use (given WGS84 coordinates)

T3GeoTools class>>#distanceBetween: firstPosition and: secondPosition
        "T3GeoTools distanceBetween: 5.33732@50.926 and: 5.49705@50.82733"

        | c |
        c := (firstPosition y degreeSin * secondPosition y degreeSin)
                + (firstPosition y degreeCos * secondPosition y degreeCos
                        * (secondPosition x degreesToRadians - firstPosition x degreesToRadians) cos).
        c := c >= 0 ifTrue: [ 1 min: c ] ifFalse: [ -1 max: c ].
        ^ c arcCos * 6371000

Sven

> On 05 Oct 2016, at 23:28, Paul DeBruicker <[hidden email]> wrote:
>
> umm ... here is a good place to start
>
> http://forum.world.st/Geo-coordinates-operations-td4732373.html#a4732441
>
>
>
> Paul DeBruicker wrote
>> I've got a few objects with latitude and longitude and want to be able to
>> find the nearest from a collection
>>
>>
>> Thanks
>>
>> Paul
>
>
>
>
>
> --
> View this message in context: http://forum.world.st/Is-there-any-library-to-calculate-the-geographic-distance-between-two-points-tp4918207p4918208.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>



Reply | Threaded
Open this post in threaded view
|

Re: Is there any library to calculate the geographic distance between two points?

Sven Van Caekenberghe-2

> On 06 Oct 2016, at 00:07, Hernán Morales Durand <[hidden email]> wrote:
>
> Hi Sven,
>
> Are you ok if I integrate your code into Territorial?

Sure !

BTW, I got the basic code from http://www.movable-type.co.uk/scripts/latlong.html with the necessary adaptions.

> I'd like to have
>
> 'Ottawa@CA' asTerritoiralCity distanceWGS84To: 'Rome@IT' asTerritorialCity

Well, I also have this one that you might need (testing containment in a closed polygon).

T3GeoTools class>>#is: position inside: polygon
        "T3GeoTools is: 5.33732@50.92601 inside: { 5.48230@50.82249. 5.49523@50.81288. 5.50138@50.82008. 5.50228@50.82595. 5.49265@50.82560. 5.48230@50.82249 }"
       
        "T3GeoTools is: 5.49007@50.82205 inside: { 5.48230@50.82249. 5.49523@50.81288. 5.50138@50.82008. 5.50228@50.82595. 5.49265@50.82560. 5.48230@50.82249 }"
       
        "Point in polygon - ray casting algorithm - http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html"
       
        | inside otherIndex |
        inside := false.
        otherIndex := polygon size.
        polygon doWithIndex: [ :each :index | | other |
                other := polygon at: otherIndex.
                (((each y > position y) ~= (other y > position y))
                        and: [ position x < (((other x - each x) * (position y - each y) / (other y - each y)) + each x) ])
                                ifTrue: [ inside := inside not ].
                otherIndex := index ].
        ^ inside

Sven

> Hernán
>
>
> 2016-10-05 19:00 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:
> Hi Paul,
>
> This is what we use (given WGS84 coordinates)
>
> T3GeoTools class>>#distanceBetween: firstPosition and: secondPosition
>         "T3GeoTools distanceBetween: 5.33732@50.926 and: 5.49705@50.82733"
>
>         | c |
>         c := (firstPosition y degreeSin * secondPosition y degreeSin)
>                 + (firstPosition y degreeCos * secondPosition y degreeCos
>                         * (secondPosition x degreesToRadians - firstPosition x degreesToRadians) cos).
>         c := c >= 0 ifTrue: [ 1 min: c ] ifFalse: [ -1 max: c ].
>         ^ c arcCos * 6371000
>
> Sven
>
> > On 05 Oct 2016, at 23:28, Paul DeBruicker <[hidden email]> wrote:
> >
> > umm ... here is a good place to start
> >
> > http://forum.world.st/Geo-coordinates-operations-td4732373.html#a4732441
> >
> >
> >
> > Paul DeBruicker wrote
> >> I've got a few objects with latitude and longitude and want to be able to
> >> find the nearest from a collection
> >>
> >>
> >> Thanks
> >>
> >> Paul
> >
> >
> >
> >
> >
> > --
> > View this message in context: http://forum.world.st/Is-there-any-library-to-calculate-the-geographic-distance-between-two-points-tp4918207p4918208.html
> > Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
> >
>
>
>