-1

I am currently working on a project where I have two datasets. I have been able to write a program to match records between the two datasets on timestamp and lat/long positions.

Example: datasetA

{"LATITUDE": 29.83, 
 "LONGITUDE": 106.73, 
 "MINUTE": 0, 
 "SECOND": 2, 
 "MONTH": 10,  
 "WIND_DIRECTION": 219, 
 "WIND_SPEED": 3.0, 
 "YEAR": 2019}

example: dataset2

{"LATITUDE": 29.83, 
 "LONGITUDE": 106.73, 
 "MINUTE": 0, 
 "SECOND": 2, 
 "MONTH": 10,  
 "WIND_SPEED": 3.0, 
 "YEAR": 2019},

Now, say I have another record in dataset2, which is close to the number for lat/long and timestamp.

Example dataset2a

{"LATITUDE": 30.83, 
 "LONGITUDE": 107.73, 
 "MINUTE": 0, 
 "SECOND": 4, 
 "MONTH": 10,  
 "WIND_SPEED": 3.0, 
 "YEAR": 2019}

Below is my code so far for matching, it is matching on exact lat/long + minute & second. If I wanted to introduce an interval to this, say to match on seconds near 1 minute of time and lat/long to be 1 - 2 integers. How would I go at implementing this?

if (z['latitude'] == True and z['longitude'] == True) and z['minute'] == True:
       trueMatches += 1
       dict3 = {**dictA , **dictB}
       list.append(dict3)
       print(dict3)

It doesn't have to follow my code, but I'm matching dictionaries within a list. Any general approach will be helpful.

Prune
  • 76,765
  • 14
  • 60
  • 81
Zayn_SE
  • 153
  • 1
  • 1
  • 13
  • For the times, convert to seconds and compare. – Prune Dec 12 '19 at 18:29
  • voted to reopen since OP is not asking how to determine whether two values are "close" to each other. Rather, OP is asking how to implement this is his script (i.e. how can I search through two datasets and identify/extract values that are coincident in time and space?). – tnknepp Dec 12 '19 at 18:45

1 Answers1

1

Not entirely sure what the rest of your code looks like that compares lats and longs, but you could create intermediate variables latDiff and longDiff. Then just change your logic to see if those were less than a threshold (diffThresh):

if (latDiff < diffThresh and longDiff < diffThresh):
    # Do something cool here!

You could have different thresholds for latitude and longitude. An alternative, and probably necessary for points that are very far away, is to calculate Haversine distance between the two points, and then change your logic to look for points less than a certain distance away (instead of looking at individual lat and long coords).

EDIT: isclose looks like a nifty little solution to this.

EDIT: You'll probably want to take the absolute value of the difference.

Tee
  • 126
  • 6
  • Hey Tee, going to implement your methods. Thanks for the help, really appreciate it. – Zayn_SE Dec 12 '19 at 18:49
  • Glad I could help, Zayn. I'm not sure it's possible since the question was marked closed, but if it is - I'd appreciate if you marked this answer as accepted. Cheers! – Tee Dec 12 '19 at 18:59