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

Check if address is located within NYC #72

Open
WillNilges opened this issue Oct 27, 2023 · 0 comments
Open

Check if address is located within NYC #72

WillNilges opened this issue Oct 27, 2023 · 0 comments

Comments

@WillNilges
Copy link

I'm working on a project that needs to get the BIN from a given address, and I noticed that if I give it an address in, say, Ohio, it will still spit out a result, vastly wrong as it may be.

Here's an example:

    def lookup(address):
        print(f"Address is {address}")
        # Look up BIN in NYC Planning's Authoritative Search
        query_params = {
            "text": address,
            "size": 1,
        }
        nyc_planning_req = requests.get(f"https://geosearch.planninglabs.nyc/v2/search", params=query_params)
        nyc_planning_resp = json.loads(nyc_planning_req.content.decode("utf-8"))
        print(nyc_planning_resp)

        if len(nyc_planning_resp["features"]) == 0:
            raise requests.exceptions.HTTPError("Address not found.")

        bin = nyc_planning_resp["features"][0]["properties"]["addendum"]["pad"]["bin"]
        longitude, latitude = nyc_planning_resp["features"][0]["geometry"]["coordinates"]
        print(bin, longitude, latitude)
Address is 1 Capitol Square, Columbus, OH 43215
{'geocoding': {'version': '0.2', 'attribution': 'http://geosearch.planninglabs.nyc/attribution', 'query': {'text': '1 Capitol Square, Columbus, OH 43215', 'size': 1, 'private': False, 'lang': {'name': 'English', 'iso6391': 'en', 'iso6393': 'eng', 'via': 'default', 'defaulted': True},
 'querySize': 20, 'parser': 'pelias', 'parsed_text': {'subject': '1 Capitol Square', 'housenumber': '1', 'street': 'Capitol Square', 'locality': 'Columbus', 'region': 'OH', 'postcode': '43215', 'admin': 'Columbus, OH'}}, 'engine': {'name': 'Pelias', 'author': 'Mapzen', 'version': '1.
0'}, 'timestamp': 1698382191726}, 'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-73.943863, 40.747003]}, 'properties': {'id': '1745142', 'gid': 'nycpad:venue:1745142', 'layer': 'venue', 'source': 'nycpad', 'source_id': '17
45142', 'country_code': 'US', 'name': '1 COURT SQUARE', 'housenumber': '1', 'street': 'COURT SQUARE', 'postalcode': '11101', 'confidence': 0.8, 'match_type': 'fallback', 'accuracy': 'point', 'country': 'United States', 'country_gid': 'whosonfirst:country:85633793', 'country_a': 'USA'
, 'region': 'New York', 'region_gid': 'whosonfirst:region:85688543', 'region_a': 'NY', 'county': 'Queens County', 'county_gid': 'whosonfirst:county:102082377', 'locality': 'New York', 'locality_gid': 'whosonfirst:locality:85977539', 'locality_a': 'NYC', 'borough': 'Queens', 'borough_
gid': 'whosonfirst:borough:421205767', 'neighbourhood': 'Long Island City', 'neighbourhood_gid': 'whosonfirst:neighbourhood:85831303', 'label': '1 COURT SQUARE, Long Island City, NY, USA', 'addendum': {'pad': {'bbl': '4000790030', 'bin': '4307108', 'version': '23B'}}}}], 'bbox': [-73
.943863, 40.747003, -73.943863, 40.747003]}

I suppose it uses fuzzy search to give you the closest result, but the website autocomplete gives you nothing, which is arguably better:

https://geosearch.planninglabs.nyc/v2/autocomplete?text=1 Capitol Square, Columbus, OH 43215

{"geocoding":{"version":"0.2","attribution":"http://geosearch.planninglabs.nyc/attribution","query":{"text":"1 Capitol Square, Columbus, OH 43215","parser":"pelias","parsed_text":{"subject":"1 Capitol Square","housenumber":"1","street":"Capitol Square","locality":"Columbus","region":"OH","postcode":"43215","admin":"Columbus, OH"},"size":10,"private":false,"lang":{"name":"English","iso6391":"en","iso6393":"eng","via":"header","defaulted":false},"querySize":20},"engine":{"name":"Pelias","author":"Mapzen","version":"1.0"},"timestamp":1698384129413},"type":"FeatureCollection","features":[]}

Two workarounds that will probably work OK for my use case

  • Check the contents of the address fields in the API response and compare to the input. If they don't match, bail.
  • Use the autocomplete API, possibly even in my frontend, instead of doing all the address validation in the backend.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant