I have been trying to extract sensors with the PurpleAir API using a bounding box, which is allowed. However, when I try using different bounding boxes, the same sensors are returned.
Specifically, I am using the PurpleAir R package written by
The following code attempts to extract sensors from Clifton, Ohio and Ithaca, NY and returns the same output (I also tried the Bay Area and got the same output):
I contacted the creator of the package, and he told me that the problem appears to be coming from PurpleAir and not the package. He said he tried querying the same bounding boxes from the API directly and also gets the same output with the same boxes.
@asmarcheva, thank you for the detail in your post and including a code snippet.
It looks like your code is sending requests using xmin and xmax as latitude values and ymin and ymax as longitude values. Swapping xmin with ymin and swapping xmax with ymax will likely use the correct bounding box without any other code changes.
I confirmed this by examining the logs for your API account. You can view these logs for your requests by logging in to https://develop.purpleair.com and clicking “Logs” at the top. The table below shows how the parameters were being mixed up for Clifton, Ohio:
Parameter
Bounding Box for Clifton
Supplied in Your Requests
nwlat
39.31206
-84.8203
nwlng
-84.8203
39.02153
selat
39.02153
-84.25633
selng
-84.25633
39.31206
Why Both Bounding Boxes Received the Same Set of Sensors
Since latitude and longitude were mixed up, both of the bounding boxes you created were over Antarctica. Sensors registered without a location are placed near Antarctica (more specifically around a latitude of -70), which we refer to as “No Mans Land”.
Requesting a bounding box from the API that goes below a latitude of -70 will result in sensors from No Man’s Land being included in the response. Since these sensors have no location set, requesting the fields latitude and longitude from them will return values of null.
Both mixed-up bounding boxes sent in your requests were below -70, which is why they both returned these sensors.
Ok, it seems like the package I am using may be inputting the coordinates incorrectly to the API. I will check with the pacakge creator then. Thanks for solving the mystery!