Search code examples
socratasoda

Socrata API call using within_polygon function returning error


Using hurl.it, I am trying to make an API call to the City of Seattle open data.

Here's the GET destination:

https://data.seattle.gov/resource/82su-5fxf.json?$where=within_polygon(location, 'MULTIPOLYGON(((-122.345239999941 47.7339842230969,-122.344670705637 47.7051200031236, -122.35540073991 47.7051536806063,-122.355548433321 47.7340195160745, -122.345239999941 47.7339842230969)))')

The error I'm receiving:

Error: function within_polygon is not defined in SoQL.

However, both within_box and within_circle work on this endpoint- just not within_polygon. The data originates within the city of Seattle's open data docs- this particular data set is called My Neighborhood:

https://data.seattle.gov/Community/My-Neighborhood-Map/82su-5fxf

Here is a working example for 'within_polygon` but using a different endpoint:

https://data.seattle.gov/resource/pu5n-trf4.json? $where=within_polygon(incident_location, 'MULTIPOLYGON(((-122.345239999941 47.7339842230969,-122.344670705637 47.7051200031236, -122.35540073991 47.7051536806063,-122.355548433321 47.7340195160745, -122.345239999941 47.7339842230969)))')

Thanks in advance for your help.


Solution

  • The within_polygon function is only available on the newest API endpoint for each dataset, so make sure you're using the correct endpoint. You should be using this one instead:

    https://dev.socrata.com/foundry/#/data.seattle.gov/3c4b-gdxv

    Using that endpoint, and correcting the location fieldname to location, I was able to create this query that works:

    https://data.seattle.gov/resource/3c4b-gdxv.json?$where=within_polygon(location,%20%27MULTIPOLYGON(((-122.345239999941%2047.7339842230969,-122.344670705637%2047.7051200031236,%20-122.35540073991%2047.7051536806063,-122.355548433321%2047.7340195160745,%20-122.345239999941%2047.7339842230969)))%27)