1

I'm trying to write a query to this data set:

https://data.sfgov.org/City-Infrastructure/Street-Tree-List/tkzw-k3nq

I want to return the records that have a latitude AND longitude between certain values.

My attempt at a query string:

"https://data.sfgov.org/resource/2zah-tuvt.json?$limit=1000&$where=latitude between 37.709864 and 37.781918 AND longitude between -122.398942 and -122.501212"

The request limits the response to 1000 records and searches for records with a latitude between the specified numbers AND a longitude between the specified numbers.

The request does not produce an error but it also doesn't include any results. There are thousands of records that should satisfy the parameters and I'm not sure why I'm not getting a response.

When I test off of the latitude values only, the response returns as expected. When I test off of the longitude values only, I get no response. I've tested the longitude for values < 0 (since all of the longitude values are negative numbers) and that does produce a correct response.

I have a feeling the negative numbers I'm trying to search for are causing the issue. Is there some way to format the negative numbers so SoQL sees them as part of the search number instead of an operator? I've also tried wrapping the negative numbers in parentheses but that didn't help.

What do I need to change to get the response to return my desired results?

Dylan
  • 13
  • 2

1 Answers1

1

On a "between", the LOWER number needs to be on the left and the GREATER number on the right. Negative numbers obviously work the opposite (greatest absolute value actually belongs on the LEFT)

change to

 between -122.501212 and -122.398942 
Joe Love
  • 5,594
  • 2
  • 20
  • 32
  • 1
    Fantastic! Thanks so much for the quick and helpful reply! – Dylan Nov 01 '16 at 18:11
  • 1
    Also, normally you'd be able to use the [`within_box`](https://dev.socrata.com/docs/functions/within_box.html) function to do what you're doing, but it looks like the `location` column in that dataset isn't properly populated. I'll reach out to our support team and get that fixed. – chrismetcalf Nov 01 '16 at 20:31
  • Thanks for the note, Chris. I noticed that the location column was correctly populated yesterday but it's empty again today. Can you reach out to the support team again to see if they can fix that again? – Dylan Nov 08 '16 at 19:44
  • @Dylan - Looks like the issue with the Location column has been fixed! Take a look and let me know if the `within_box` works out for you! – chrismetcalf Nov 09 '16 at 21:05