javascriptapisoqlsocratasoda

Socrata map results in $http request, Javascript


I am trying to use this dataset to determine which district boundary an address (passed into the API call) falls within.

The endpoint returns an array of objects for each district or council. The polygon is found within the "the_geom" property, with 2 properties - type and coordinates. I have tried using $where, but I get errors.

[
{
    "comments": "Inaugurated 2015-06-22",
    "council": "1",
    "councilper": "Scott Griggs",
    "district": "1",
    "objectid": "1",
    "shape_area": "343352603.892",
    "shape_leng": "88541.3042539",
    "the_geom": {
        "type": "MultiPolygon",
        "coordinates": [
            [
                [
                    [
                        -96.80995700065864,
                        32.77138899977414
                    ],
                    [
                        -96.80969800043205,
                        32.77121999997131
                    ],
                    [ ...

I tried to use the query below, but it gave me an error:

https://www.dallasopendata.com/resource/h9ws-fqcn.json?$where=within_polygon(the_geom,  'MULTIPOLYGON (((-96.800270, 32.779091)))')

This is the page reference page - https://www.dallasopendata.com/Geography-Boundaries/Adopted-Council-Districts/6dcw-hhpj

And this is the endpoint- https://www.dallasopendata.com/resource/dgxr-hmze.json

any help would be greatly appreciated.


Solution

  • I suspect you're the developer who popped into our IRC channel, but I'll answer here too!

    You're pretty close here! What you want to do here is use the intersects(...) SoQL function with a Well Known Text (WKT) POINT.

    Here's an example that works for your use case:

    https://www.dallasopendata.com/resource/h9ws-fqcn.json?$where=intersects(the_geom,%20%27POINT%20(-96.7994007%2032.775765)%27)