Fetching localities through zipcode

Hey, I am new to openstreetmap and doesn’t know much about how to use its APIs yet. I have been looking to find out all the localities(not just city name, might be village,neighbourhoods etc) that fall under a certain zipcode. Is there any way to do it through osm?
Thanks

1 Like

If you’re specifically interested in ZIP codes in the United States, as opposed to postal codes elsewhere, that would be somewhat difficult to do with OSM data alone. We do map boundaries of cities, villages, etc., but ZIP codes are delivery routes, not boundaries, which means we can’t really map them as such. We do collect individual addresses, including their postal codes, so this query returns the municipal boundary that contains all the addresses of ZIP code 02134.

That query returns Boston, which contains the entire ZIP code. However, many ZIP codes are associated with a neighboring city where the main post office is located. In many cases, you can also query for U.S. Post Office branches by the ZIP codes they serve, for example, post offices serving ZIP code 47579. The returned feature has tags indicating a postal city of Santa Claus, Indiana. With either of these queries, you can either run the query in your browser at these links or click the Export button to get a link to an API endpoint.

If your goal is to come up with the best postal city name associated with a given ZIP code and accuracy is important, these queries may not give you the best results. For example, the USPS will accept Boston for ZIP code 02134, but they prefer to call it Allston. In some cases, the city that physically includes the address or the post office is not an acceptable postal city name. You might be able to determine this by getting all the addresses matching a given ZIP code in addr:postcode=* and figuring out the most common value of addr:city=* on these features.

Other addressing-specific datasets, such as OpenAddresses, may be better-suited for this kind of use case. The USPS also has its own API, if you don’t mind paying for it.

5 Likes

Vaibhav, I find Minh’s answer to be complete, on point and hope it answers your question. If it does, you might find a checkbox and “Answered” (or similar wording) next to each other that you might check. (Only you can see this as you are @vaibhav541 , Original Poster in this topic).

Yes, “ZIP” (and ZCTA) are uniquely USA-ish, though other countries have similar “postal-coding,” unique in their own ways, too. It’s a technical topic.

“Somewhat difficult” is an answer with which I concur. If it helps (to go with the thinking of how others consider ZIPs) I think of ZIP codes as part “point cloud” (especially the last two digits) and part “routing algorithm” (especially the first three digits). What you are asking to do seems to me it might not grasp what data these are, which ZIP codes capture. The linked illustrations are helpful, including to me, who understands that ZIP codes ≠ “polygons” (in OSM, closed ways), as well as how this is a familiar, lots-of-people-do-this stumbling block about ZIPs. No harm, no foul.

If you need further clarification, please ask.

2 Likes

Thank you guys. I think I understood, OSM data might not be enough for me here.

1 Like