Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geocoding addresses #85

Open
vingkan opened this issue Jul 20, 2021 · 0 comments
Open

Geocoding addresses #85

vingkan opened this issue Jul 20, 2021 · 0 comments
Labels
api Work for backend API app Work for frontend app enhancement New feature or request pipeline Work for offline pipeline stretch Stretch project for Scarlet Data Studio interns.

Comments

@vingkan
Copy link
Contributor

vingkan commented Jul 20, 2021

We have several product features where it would be useful to geocode: convert an address to longitude/latitude coordinates and other geographic information.

For example:

  • Datasets in offline pipeline that have address or zip code but not other geo fields could be mapped to coordinates and community areas
  • Pages on the frontend could allow the user to enter their address or zip code and then see results for their community area
  • Pages on the frontend could show pins on a map for the coordinates of a record

We would like to find a free geocoding service, I think I found two a few months ago that could work:

  • Chicago geocoding service
  • Census geocoding service

Below are my messy notes from playing around with those. I can explain how to get these into Python code and add them into our codebase.

We could do geocoding in the offline pipeline or in the backend API or both depending on the use case.

fetch(
    `https://api.chicago.gov/els/forwardgeocoding/rest/geocode_3`,
    {
        method: "POST",
        headers: {
            'Accept': 'application/json, text/javascript, */*; q=0.01',
            'Accept-Encoding': 'gzip, deflate, br',
            'Accept-Language': 'en-US,en;q=0.9',
            'Authorization': 'Basic ZWxzX2NsaWVudF93YXJkZ2VvOnR2S0xANFM2N2Fw',
            'Connection': 'keep-alive',
            'Content-Type': 'application/json',
            'Host': 'api.chicago.gov',
            'Origin': 'https://gisapps.chicago.gov',
            'Referer': 'https://gisapps.chicago.gov/',
            'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
            'sec-ch-ua-mobile': '?0',
            'Sec-Fetch-Dest': 'empty',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Site': 'same-site',
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
        },
        body: JSON.stringify({
            ForwardGeocodeServiceInput3: {
                "systemId": "WARD_LOOKUP",
                "offsetFt": "20",
                "fullAddress": "2345 S Michigan Ave",
                "getGeos": {
                    "geographyName": "CENSUS_TRACT"
                }
            }
        }),
    }
).then(async (res) => {
    const data = await res.text();
    console.log(data);
}).catch((err) => {
    console.error("Something went wrong:");
    console.log(err);
});
let address = "2345 S Michigan Ave, Chicago, IL";
fetch(
    `https://geocoding.geo.census.gov/geocoder/locations/onelineaddress?format=json&benchmark=2020&address=${encodeURIComponent(address)}`
).then(async (res) => {
    const data = await res.json();
    console.log(data);
}).catch((err) => {
    console.error("Something went wrong:");
    console.log(err);
});
@vingkan vingkan added enhancement New feature or request pipeline Work for offline pipeline app Work for frontend app api Work for backend API stretch Stretch project for Scarlet Data Studio interns. labels Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Work for backend API app Work for frontend app enhancement New feature or request pipeline Work for offline pipeline stretch Stretch project for Scarlet Data Studio interns.
Projects
None yet
Development

No branches or pull requests

1 participant