pelias / api

HTTP API for Pelias Geocoder
http://pelias.io
MIT License
218 stars 162 forks source link

Add original place id when postalcode is overridden #1635

Open Joxit opened 1 year ago

Joxit commented 1 year ago

:wave: I did some awesome work for the Pelias project and would love for everyone to have a look at it and provide feedback.


Here's the reason for this change :rocket:

Addresses from OpenAddresses can override parent place name (such as postalcode). When this happens, we don't know where the postalcode came from, especially if there was one from another source (like WOF).

Also, since postalcodes are part of an document's parents, not having a gid makes the API less consistent.


Here's what actually got changed :clap:

In renamePlacenames middleware, I added an option that allows us to add/override the postalcode gid. Thanks to this, we will know where the data comes from.


Here's how others can test the changes :eyes:

You can try with 815 Tennessee St, San Francisco, CA 94107, États-Unis where the postalcode_gid will be openaddresses:address:us/ca/san_francisco:819b088d2837cf5d

{
  "id": "us/ca/san_francisco:819b088d2837cf5d",
  "gid": "openaddresses:address:us/ca/san_francisco:819b088d2837cf5d",
  "layer": "address",
  "source": "openaddresses",
  "source_id": "us/ca/san_francisco:819b088d2837cf5d",
  "country_code": "US",
  "name": "815 Tennessee Street",
  "housenumber": "815",
  "street": "Tennessee Street",
  "postalcode": "94107",
  "postalcode_gid": "openaddresses:address:us/ca/san_francisco:819b088d2837cf5d",
  "accuracy": "point",
  "country": "États-Unis",
  "country_gid": "whosonfirst:country:85633793",
  "country_a": "USA",
  "region": "Californie",
  "region_gid": "whosonfirst:region:85688637",
  "region_a": "CA",
  "county": "San Francisco",
  "county_gid": "whosonfirst:county:102087579",
  "county_a": "SF",
  "locality": "San Francisco",
  "locality_gid": "whosonfirst:locality:85922583",
  "locality_a": "SF",
  "neighbourhood": "Dogpatch",
  "neighbourhood_gid": "whosonfirst:neighbourhood:85882179",
  "continent": "Amérique du Nord",
  "continent_gid": "whosonfirst:continent:102191575",
  "label": "815 Tennessee Street, San Francisco, CA, USA"
}

Maybe when the postalcode is already present in the parent object we may not override it with OA data ?

Feel free the close the PR if this is not valuable for the project :smile: