Getting incorrect data when using the search boundaries

Nilesh Khonde 60 Reputation points
2024-11-06T12:55:14.76+00:00

Hi guys. I am using Search for boundaries

https://samples.azuremaps.com/?search=boundaries&sample=search-for-boundaries

Sample code to retrieve boundaries for regions.

https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/main/Samples/Services%20Module/Search%20for%20boundaries/Search%20for%20boundaries.html

I was wondering about this. I am getting different responses for names when I call APIs.

For example, when I call the geocode API for postal code 75365, which is in Dallas, Texas

https://atlas.microsoft.com/geocode?api-version=2023-06-01&view=Auto&top=1&countryRegion=&postalCode=75265&adminDistrict=&locality=&adminDistrict2=&subscription-key=


I get the following response. Screenshot (97)

And when I request the Get Search Polygon API

https://atlas.microsoft.com/search/polygon?api-version=2023-06-01&coordinates=-96.83056640625,32.74223709106445&view=Auto&resultType=postalCode&resolution=medium&subscription-key=


I get the following response

Screenshot (96)

as you can see here, the postal code I get from the response is 75208, which is different. I searched for the postal code 75265, so my understanding is that I should have received the postal code 75208. Am I doing it in an incorrect way or did i miss something between the steps, but the boundaries I am getting are the correct ones.

here are some more examples.

Los Angeles, CA 90060

Dallas TX 75265

Salt Lake City, UT 84131

Lexington, KY 40512

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
739 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. rbrundritt 18,686 Reputation points Microsoft Employee
    2024-11-06T18:45:48.53+00:00

    I wrote a long response initially as I'm not a fan of the v2 boundary service (It is the Bing Maps boundary service that has been brought over to Azure Maps and is less than ideal for your scenario).

    First off, it's important to note that the geocoder and the boundary services are independent of each other. The v2 boundary service will retrieve any boundary that intersects with the coordinate provided. This is good for hierarchy type searches, but can be error prone if a "display coordinate" (center point) is used for an area that has an irregular shape and thus the display coordinate does not overlap the boundary. Normally I would recommend using the V1 services when searching for a specific boundary since each boundary in that version has a unique ID that is returned by the geocoder. However, if you go down that path you will find none of the zip codes you provided will return a boundary ID, which indicates that it's not a data issue. Digging into this I found that these zip codes are "non deliverable zip codes" like PO boxes which have no area (multiple zip codes can exist in the same spot). Around 30% of US zip codes are like this. For example, the building that has a PO box will have a street address and zip code that aligns with the wider area it is in, while it may contain one or more zip codes for its boxes. These zip codes are points, and have no area. In the case of 75265, it is within the zip code area of 75208. I used this tool to verify: https://www.unitedstateszipcodes.org/ You can also us some tools on the USPS site, but they are less intuitive. Good similar discussion on this can be found here: https://gis.stackexchange.com/questions/22324/where-can-i-find-a-list-of-non-deliverable-zip-codes

    I haven't found a free list of all PO Box zip codes, however, zip code tabulation areas (ZTCA) used by the US census, is a list of all zip codes that have a population. So, nearly every zip code you come across that isn't in that list, is most likely a non-area zip code like a PO box. So, you could do a check to see if your input zip code is in that list before deciding to try and get its boundary or not. You can get the latest list of ZCTA here: https://www.census.gov/geographies/reference-files/time-series/geo/gazetteer-files.html

    There is also this project that looks to categorize the zip code types: https://github.com/MacHu-GWU/uszipcode-project

    All that said, if this is for a business intelligence type app, note that zip codes are not great for that type of analysis (at least in the US). Zip code boundaries are not well-defined areas and you will find that the shape/area varies between map provides. Zip codes area's as per the postal service is a set of delivery routes (roads), and the area between roads is a "gray" area where approximations are used to determine the boundary lines. There are a ton of articles that go into more details on this topic. Here are a couple:

    When I work with customers who are focused on BI type scenarios in the US, I typically direct them towards census tracts.

    1 person found this answer helpful.
    0 comments No comments

  2. IoTGirl 3,211 Reputation points Microsoft Employee
    2024-11-07T01:42:12.4433333+00:00

    Hi Nilesh,

    For the postal Code issue, can I get you to try https://samples.azuremaps.com/?search=boundaries&sample=search-for-boundaries with the codes that are failing for you? Are these also incorrect?

    For the Texas "75365" example "https://tools.usps.com/zip-code-lookup.htm?citybyzipcode" says that is not a valid Zip so you may have a typo but for the others that sample returns polygons for me. Can you confirm what is incorrect regarding those?

    Sincere thanks,

    IoTGirl


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.