whosonfirst / whosonfirst-www-api

4 stars 2 forks source link

getHierarchiesByLatLon with spr=1 turns -1 into an empty array #54

Closed simonw closed 7 years ago

simonw commented 7 years ago

Consider this response:

https://whosonfirst-api.mapzen.com/?method=whosonfirst.places.getHierarchiesByLatLon&latitude=36.7232166&longitude=-4.3704579&api_key=mapzen-XXX

{
    "hierarchies": [
        {
            "region_id": -1,
            "continent_id": -1,
            "country_id": 85633129,
            "locality_id": 101748185,
            "county_id": -1,
            "neighbourhood_id": 85863513
        }
    ],
    "stat": "ok"
}

The region_id, continent_id and county_id are all -1 - which is surprising, because this is a perfectly regular point somewhere in Spain... https://whosonfirst.mapzen.com/spelunker/id/85863513/ - but that's not the bug I'm reporting here.

If I add &spr=1 to the above, I get this:

https://whosonfirst-api.mapzen.com/?method=whosonfirst.places.getHierarchiesByLatLon&latitude=36.7232166&longitude=-4.3704579&api_key=mapzen-xxx&spr=1

{
    "hierarchies": [
        {
            "region": [],
            "continent": [],
            "country": {
                "wof:id": 85633129,
                "wof:parent_id": "102191581",
                "wof:name": "Spain",
                "wof:placetype": "country",
                "wof:country": "ES",
                "wof:repo": "whosonfirst-data"
            },
            "locality": {
                "wof:id": 101748185,
                "wof:parent_id": "404339241",
                "wof:name": "Málaga",
                "wof:placetype": "locality",
                "wof:country": "ES",
                "wof:repo": "whosonfirst-data"
            },
            "county": [],
            "neighbourhood": {
                "wof:id": 85863513,
                "wof:parent_id": "101748185",
                "wof:name": "Valle Los Galanes",
                "wof:placetype": "neighbourhood",
                "wof:country": "ES",
                "wof:repo": "whosonfirst-data"
            }
        }
    ],
    "stat": "ok"
}

Note how county, region and continent are now all represented as empty arrays []. This is unexpected, since normally those would be an object {}.

Proposed solution: either omit those keys entirely, or set their value to null (this is my preferred solution), or set their value to an empty {} object. The null version would look like this:

{
    "hierarchies": [
        {
            "region": null,
            "continent": null,
            "country": {
                "wof:id": 85633129,
                "wof:parent_id": "102191581",
                "wof:name": "Spain",
                "wof:placetype": "country",
                "wof:country": "ES",
                "wof:repo": "whosonfirst-data"
            },
            "locality": {
                "wof:id": 101748185,
                "wof:parent_id": "404339241",
                "wof:name": "Málaga",
                "wof:placetype": "locality",
                "wof:country": "ES",
                "wof:repo": "whosonfirst-data"
            },
            "county": null,
            "neighbourhood": {
                "wof:id": 85863513,
                "wof:parent_id": "101748185",
                "wof:name": "Valle Los Galanes",
                "wof:placetype": "neighbourhood",
                "wof:country": "ES",
                "wof:repo": "whosonfirst-data"
            }
        }
    ],
    "stat": "ok"
}
thisisaaronland commented 7 years ago

We can do null. That might be done by the time you read or, if not, then shortly thereafter!

thisisaaronland commented 7 years ago

Done!

curl -X GET 'https://whosonfirst-api.mapzen.com?method=whosonfirst.places.getHierarchiesByLatLon&api_key=mapzen-xxxxxx&latitude=36.7232166&longitude=-4.3704579&spr=1&format=json'

{
  "hierarchies": [
    {
      "region": null,
      "continent": null,
      "country": {
        "wof:id": 85633129,
        "wof:parent_id": "102191581",
        "wof:name": "Spain",
        "wof:placetype": "country",
        "wof:country": "ES",
        "wof:repo": "whosonfirst-data"
      },
      "locality": {
        "wof:id": 101748185,
        "wof:parent_id": "404339241",
        "wof:name": "Málaga",
        "wof:placetype": "locality",
        "wof:country": "ES",
        "wof:repo": "whosonfirst-data"
      },
      "county": null,
      "neighbourhood": {
        "wof:id": 85863513,
        "wof:parent_id": "101748185",
        "wof:name": "Valle Los Galanes",
        "wof:placetype": "neighbourhood",
        "wof:country": "ES",
        "wof:repo": "whosonfirst-data"
      }
    }
  ],
  "stat": "ok"
}