Heater wrote: ↑Tue Oct 22, 2019 12:50 am
bensimmo,
I think you are saying something like we do for out air quality project (PM2.5 sensors).
We have result in an SQL (or similar) database, they all have their GNSS location.
I have my Pi with GNSS (or phone, or Alexa) and ask it to give me the current reading.
I can grab the nearest by actual distance from my current point.
I can also grab the nearest 5 and take an average, or remove any that haven't sent data back for a while.
I first did this in Python3, cheap and easy as we don't have that many points to loop through at the moment but moved it to the server in some language (php/SQL?).
Scale it up to 1000s of point and the Python3 would be slow probably.
Yes, the challenge is kind of inspired by that geographical problem.
Rather than loop through thousands of points stored in a database why not let the database do the work:
Code: Select all
SELECT * FROM Places WHERE
(Lat => 1.2393 AND Lat <= 1.5532) AND (Lon >= -1.8184 AND Lon <= 0.4221)
AND
acos(sin(1.3963) * sin(Lat) + cos(1.3963) * cos(Lat) * cos(Lon - (-0.6981))) <= 0.1570;
See nice article about this here: "Finding Points Within a Distance of a Latitude/Longitude Using Bounding Coordinates" -
http://janmatuschek.de/LatitudeLongitud ... SQLQueries
How fast it works will depend on your database of course. But I suspect it would be hugely faster than any home made looping through thousands of points in Python.
That sounds likes an interesting project you have there.
It wasn't slow as such, but having to transfer every point from the database to my device was not the best plan.
It is all done on the SQL database now with a call. Not sure which we are suing, that not my side of things, I think it is Maria but may be switched to something else.
I believe we now use the Spacial funtion provided ('Point' rings a bell and spherical distance, it was great working it out from my suggestion.
Interestingly, or not, it was so I could take a PiZero/Pimoroni ScrollBot with a GPS attached and show peoppe their local PM2.5 count from our sensors (or DEFRA or the Councils etc) to enthuse anyone that would listen

School being the initial target.
At least that was the plan, just need to get time and a bit of money to persue partII. Getting LoRaWAN/TTN setup around the city has taken over for a bit. Not to bad for what is basically a community interest group with no money
The main part isn't to bleat on about particle counts and climate health though as that far more complicated that putting a load of sensors up and telling them a number.
But to make them think, what could they do with a free to use slow but Long Distance 'WiFi' network or just fast but short range WiFi and a few relatively cheap ESP/Ardunio/Pi devices and sensors spread around.
The only stipulation so far is all data will be stored as open-data for anyone to use, analyse and make use of.
Hopefully all the UK's money pumped into Primary and Secondard school computing will give them the skills and encouragment to try thing for themselves.