1

For things like simple filters and comparisons in a where clause, is there any way of representing a location value? For example, something like:

https://data.seattle.gov/rescource/82su-5fxf.json?location='LOCATION (Seattle, 47.612237, -122.290868)'

The documentation mentions that other geographic data can be represented as Well-known Text (WKT) and you can use that in things like simple filters and comparisons, however as far as I can find, there doesn't seem to be a WKT representation of location values.

It's probably intended for users to use things like within_circle rather than directly comparing the values and I've seen the note on the documentation page that location is a legacy datatype, so it would make sense if there wasn't a way.

I personally would use something like within_circle in an app, but I'm working on writing a haskell SODA bindings library, so I just want to make it available (although discouraged) if it is possible. I wouldn't want the bindings to prevent a valid call from being made.

StevenW
  • 27
  • 2
  • 7

1 Answers1

1

My examples will be using the version 2.1 end point rather than the old 2.0 one you link to above, so make sure you're using this verison: https://dev.socrata.com/foundry/data.seattle.gov/3c4b-gdxv

You actually can't do exact equality in a simple filter on a Point column. The closest approximation I'd recommend is using within_circle with a very small circle, like this:

GET https://data.seattle.gov/resource/3c4b-gdxv.json?$where=within_circle(location,%2047.514821,%20-122.258635,%2010)

If you're looking for how to format lat/longs in WKT, you'll want to format them as a POINT

I didn't realize it, but that's not actually documented for our Point datatype, so I'll add that to my queue!

UPDATE: StevenW discovered you can do an exact filter if you get the syntax right:

GET https://data.cityofchicago.org/resource/6zsd-86xi.json?locat‌​ion='POINT (-87.631046 41.694312)'

Note that this requires you to have the EXACT same lat/lon as the point, so it doesn't have much margin for error.

chrismetcalf
  • 1,556
  • 1
  • 8
  • 7
  • Oops, I didn't realize that was a 2.0 end point. Now that I look around, I actually can't find any 2.1 datasets with a column datatype of [location](https://dev.socrata.com/docs/datatypes/location.html#,). You're also right about not being able to do exact equality with points. I thought I had tried that successfully, but I guess I must have tested with something like multipolygon and misremembered. Anyways, thanks for the quick and helpful answer! – StevenW Dec 16 '16 at 03:28
  • 1
    Actually, while testing some queries, I found you can actually do exact equality with a simple filter using the following syntax `https://data.cityofchicago.org/resource/6zsd-86xi.json?location='POINT (-87.631046 41.694312)'`. I don't think you can see this though because I don't have enough reputation yet. – StevenW Dec 16 '16 at 04:18
  • Good find StevenW, I tried that too but I must have been doing something wrong. – chrismetcalf Dec 19 '16 at 16:50