Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
hello everyone,
i have a scenario where in a table which are having latitude and longitude data,
In my task i have to find difference between first location and second location on the basis of latitude and longitude and overall find total difference in start point to end point, in my table total 1 million records.
Please help!!
thanks and regards,
Manish
Hi,
I'm assuming you know Java in some form, if not you'll need to read up a little on what I'm going to describe next.
1/ Within Talend Studio, open the Repository-Code in the Repository, right click on Routines, select Create Routine.
2/ Add the Java code for a static class to return a double (GCD) and accept 4 doubles (LatA, LongA, LatB, LongB).
3/ Within your Talend job, in either a tJavaRow or tMap, invoke the static class, and put the passed back value into a new column (or whatever you want to do with it).
Hope this helps, if you're not sure, then you probably need to look up how to do some of these things within Talend first, before tackling this specific example.
Hi,
Your best option would be to write a static java class method to be passed in the 4 values, 2 sets of long/latitude, performs the calculation and passes back the distance using a Great Circle Distance calculation of either Spherical Law of Cosines or Spherical Law of Haversines.
Couple of things to consider:
-What units of measure do you want the distance returned in, typically, Kilometers, Miles or Nautical Miles.
-You'll need to use an accepted Earth radius in Kilometers is you want the distance in Kilometers (normally 6371Km).
-If your 2 lat/long points are close, then the Haversines method is preferable.
Example: https://introcs.cs.princeton.edu/java/12types/GreatCircle.java.html
hello,
thanks for reply sir,
i don't know how to execute it by using java, can you please explain or give any real time example. and is there any other way to solve this task by using talend components.
thanks
Hi,
I'm assuming you know Java in some form, if not you'll need to read up a little on what I'm going to describe next.
1/ Within Talend Studio, open the Repository-Code in the Repository, right click on Routines, select Create Routine.
2/ Add the Java code for a static class to return a double (GCD) and accept 4 doubles (LatA, LongA, LatB, LongB).
3/ Within your Talend job, in either a tJavaRow or tMap, invoke the static class, and put the passed back value into a new column (or whatever you want to do with it).
Hope this helps, if you're not sure, then you probably need to look up how to do some of these things within Talend first, before tackling this specific example.
Hi,
Another method is to use Distance Matrix API from Google and you can make a call to the API from Talend using REST components.
https://developers.google.com/maps/documentation/distance-matrix/intro
Warm Regards,
Nikhil Thampi
Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
hello sir,
thanks again!!
i have done with 1st and 2nd point , but confuse in 3rd one ..
i attached screenshot with it, please find and guide me i am on the right way or not .
kindly give me suggestion what is the poisition of my source, target , also how i call this routine through tmap or tjavarow
thanks,
Hi,
You need to create the java routine as a static method that is passed in the 4 values for latA, longA, latB & longB rather than trying to pull them from args[].
Something like:
public static Double GCDAngleInRadians(Double LatA, Double LongA, Double LatB, Double LongB)
Also I'd suggest not using the Google API, with the number of requests you need to make, the Google API will be too slow.
thank you so much sir for help,
in my scenario it accepts only 1st row values as latA, longA, latB & longB and gives 0 .
how can i pass 2nd row value as latB & longB. ?
thanks
Manish
Hi,
So, as I understand it, you have a source with consecutive data points that have latitude and longitude. So, on point 2 onward you want to work out the distance from the previous point to this point.
I'd suggest you use a tMemorizeRow component,to retain the last single row. You'll need to put some logic in so that on row 1,it doesn't try and calculate the distance (or just uses the same Lat/Long to give a distance of 0).