ZIP Codes and Zmanim – A Practical Approach

99557 ZIP code area (the largest in the USA)
99557 ZIP code area (the largest in the USA)
As mentioned in the ZIP Codes and Zmanim – Use With Care article, using ZIP codes to geolocate your position for zmanim can be problematic when the zip code is large. With large zip codes, zmanim on the west side of the zip code can be quite a bit later than zmanim on the east side of the zip. Recently, Lazer Guttman created an SMS based zmanim service at (914) 409-9394 that provides a warning when zmanim are requested for large zip codes. This approach is probably the best that can be done. I would recommend that any zmanim service that is zip code based (and does not have a map to allow zeroing in to a precise location), use this data to provide a warning whenever the zip codes is wider than 0.5° of longitude. A degree of longitude spans 4 minutes (regardless of the latitude), so half of a zip code with half of a degree would span 2 minutes (one minute east or west of the center). It should be noted that Canadian postal codes are much smaller than zip codes (usually covering one side of a city block), and most likely do not face the same issue. A spreadsheet listing all zip codes with the maximum longitude and latitude distances (in degrees), was generated by Avraham David Gelbfish from OpenDataDE that is based on US Census data. His Python source code is below.

import json
import csv
​
jsonfile = open("tl_2019_us_zcta510/out2.geojson")
zipcodes = json.load(jsonfile)
​
def getop(geolist, operation, longitude = None, latitude = None):
    if isinstance(geolist[0], list):
        answers = [getop(geo, operation) for geo in geolist]
        for answer in answers:
            lat, lng = answer
            if latitude is None:
                latitude = lat
            if longitude is None:
                longitude = lng
            latitude = operation(latitude, lat)
            longitude = operation(longitude, lng)
        return latitude, longitude
    else:
        return geolist
​
with open("out2.csv", "w") as csvfile:
    zwriter = csv.writer(csvfile)
    zwriter.writerow(["Zip", "Latitude max distance", "Longitude max distance"])
    for zipcode in zipcodes["features"]:
        zip = zipcode["properties"]["ZCTA5CE10"]
        geometry = zipcode["geometry"]["coordinates"]
        maxlat, maxlng = getop(geometry, lambda x, y: x if x > y else y)
        minlat, minlng = getop(geometry, lambda x, y: x if x < y else y)
        dlat = abs(maxlat - minlat)
        dlng = abs(maxlng - minlng)
        zwriter.writerow([zip, dlat, dlng])

Leave a Reply

Your email address will not be published. Required fields are marked *