socrata / odn-backend

Backend for the Open Data Network.
Other
9 stars 6 forks source link

support map gen of zip data for a city #95

Open zang0 opened 7 years ago

zang0 commented 7 years ago

In order to support map generation in the 311 place/incident app where we wish to overlay data like income, education levels, demographic data, etc alongside 311 or other incidents, we want to support the generation of a map showing ODN data by zip code. Here's what we're thinking:

  1. alter relations generation script to add zip codes as children to counties and cities in this data set: https://odn.data.socrata.com/dataset/ODN-Relations/5c34-z2gi - this script will likely need to leverage the intersects SOQL function using these datasets:

Zips: https://dev.socrata.com/foundry/odn.data.socrata.com/92xu-eg4b Cities: https://dev.socrata.com/foundry/odn.data.socrata.com/h7w8-g2pa Counties: https://dev.socrata.com/foundry/odn.data.socrata.com/euye-aijz

Some tricks per @chrismetcalf:

Our JSON API returns GeoJSON, but you need a WKT string to plug into intersects(…). Use the .csv output type to get a WKT version of the data you can plug into that function for your second call.

If the polygon is too complicated, you can use simplify_preserve_topology(…) to simplify it and shorten the WKT string: https://dev.socrata.com/docs/functions/simplify_preserve_topology.html

  1. Once the relations dataset is modified, this api call: https://api.opendatanetwork.com/entity/v1/child?app_token=cQovpGcdUT1CSzgYk0KPYdAI0&entity_id=1600000US0606000 or this api call: https://api.opendatanetwork.com/entity/v1/child?app_token=cQovpGcdUT1CSzgYk0KPYdAI0&entity_id=0500000US53033 should return zip_codes.

  2. the caller can then take the resulting zip code fips ids into the data/values call to get the data (e.g. https://api.opendatanetwork.com/data/v1/values?app_token=cQovpGcdUT1CSzgYk0KPYdAI0&describe=true&forecast=5&format=google&variable=demographics.population.count&entity_id=1600000US0606000,1600000US5363000)