Skip to content

Instantly share code, notes, and snippets.

@barseghyanartur
Last active January 23, 2019 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barseghyanartur/18c110896cf114131e8ce4429516b00d to your computer and use it in GitHub Desktop.
Save barseghyanartur/18c110896cf114131e8ce4429516b00d to your computer and use it in GitHub Desktop.
Find coordinates by postal code

Install pgeocode package:

pip install pgeocode

Find the geo coordinates by postal code:

import pgeocode

# Instantiate the object
nomi = pgeocode.Nominatim('nl')

# The first time, download the data for the country you need to
# use it for.
nomi._get_data('nl')

Output:

('/home/user/pgeocode_data/NL.txt',
      country code postal_code       place_name state_name    ...     community_code latitude  longitude  accuracy
 0              NL        9402            Assen    Drenthe    ...                NaN  53.0043     6.5594       6.0
 1              NL        9403            Assen    Drenthe    ...                NaN  53.0147     6.5864       6.0
 2              NL        9404            Assen    Drenthe    ...                NaN  52.9870     6.5765       6.0
 3              NL        9405            Assen    Drenthe    ...                NaN  52.9863     6.5293       6.0
 4              NL        9406            Assen    Drenthe    ...                NaN  53.0023     6.5434       6.0
 5              NL        9407            Assen    Drenthe    ...                NaN  53.0177     6.5614       6.0
 6              NL        9408            Assen    Drenthe    ...                NaN  53.0031     6.5116       6.0
 7              NL        9409             Loon    Drenthe    ...                NaN  53.0131     6.6118       6.0
 8              NL        9486             Rhee    Drenthe    ...                NaN  53.0336     6.5710       6.0
 9              NL        9487         Ter Aard    Drenthe    ...                NaN  53.0271     6.5446       6.0
 10             NL        9488       Zeijerveld    Drenthe    ...                NaN  53.0336     6.5193       6.0
 11             NL        9489            Assen    Drenthe    ...                NaN  53.0167     6.5453       6.0
 12             NL        9489       Zeijerveen    Drenthe    ...                NaN  53.0135     6.5210       6.0
 13             NL        9492           Ubbena    Drenthe    ...                NaN  53.0496     6.5795       6.0
 14             NL        7741        Coevorden    Drenthe    ...                NaN  52.6666     6.7351       6.0
 15             NL        7742        Coevorden    Drenthe    ...                NaN  52.6586     6.7539       6.0
 16             NL        7751            Dalen    Drenthe    ...                NaN  52.6927     6.7574       6.0
 17             NL        7753        Dalerpeel    Drenthe    ...                NaN  52.6812     6.6612       6.0
 18             NL        7754          Wachtum    Drenthe    ...                NaN  52.7250     6.7479       6.0
 19             NL        7755        Dalerveen    Drenthe    ...                NaN  52.6938     6.8086       6.0
 20             NL        7756  Stieltjeskanaal    Drenthe    ...                NaN  52.6747     6.8123       6.0
 21             NL        7841            Sleen    Drenthe    ...                NaN  52.7696     6.8018       6.0
 22             NL        7842         Diphoorn    Drenthe    ...                NaN  52.7706     6.8183       6.0
 23             NL        7843              Erm    Drenthe    ...                NaN  52.7484     6.8084       6.0
 24             NL        7845         Holsloot    Drenthe    ...                NaN  52.7225     6.8054       6.0
 25             NL        7846      Noord-Sleen    Drenthe    ...                NaN  52.7914     6.8021       6.0
 26             NL        7847       't Haantje    Drenthe    ...                NaN  52.8143     6.8255       6.0
 27             NL        7848       Schoonoord    Drenthe    ...                NaN  52.8442     6.7566       6.0
 28             NL        7849          De Kiel    Drenthe    ...                NaN  52.8625     6.7444       6.0
 29             NL        7851          Zweeloo    Drenthe    ...                NaN  52.7974     6.7327       6.0
 ...           ...         ...              ...        ...    ...                ...      ...        ...       ...
 4273           NL        8316        Marknesse  Flevoland    ...                NaN  52.7087     5.8684       6.0
 4274           NL        8317      Kraggenburg  Flevoland    ...                NaN  52.6598     5.9024       6.0
 4275           NL        8319        Schokland  Flevoland    ...                NaN  52.6444     5.7754       6.0
 4276           NL        8321              Urk  Flevoland    ...                NaN  52.6633     5.6090       6.0
 4277           NL        8322              Urk  Flevoland    ...                NaN  52.6645     5.6290       6.0
 4278           NL        8251          Dronten  Flevoland    ...                NaN  52.5224     5.7265       6.0
 4279           NL        8252          Dronten  Flevoland    ...                NaN  52.5135     5.7100       6.0
 4280           NL        8253          Dronten  Flevoland    ...                NaN  52.5379     5.7010       6.0
 4281           NL        8254          Dronten  Flevoland    ...                NaN  52.5247     5.7237       4.0
 4282           NL        8255      Swifterbant  Flevoland    ...                NaN  52.5671     5.6421       6.0
 4283           NL        8256    Biddinghuizen  Flevoland    ...                NaN  52.4429     5.6995       6.0
 4284           NL        8211         Lelystad  Flevoland    ...                NaN  52.5365     5.5138       6.0
 4285           NL        8212         Lelystad  Flevoland    ...                NaN  52.5127     5.5044       6.0
 4286           NL        8218         Lelystad  Flevoland    ...                NaN  52.4493     5.5122       6.0
 4287           NL        8219         Lelystad  Flevoland    ...                NaN  52.4862     5.5354       6.0
 4288           NL        8221         Lelystad  Flevoland    ...                NaN  52.5533     5.4795       4.0
 4289           NL        8222         Lelystad  Flevoland    ...                NaN  52.5341     5.4919       6.0
 4290           NL        8223         Lelystad  Flevoland    ...                NaN  52.5230     5.4860       6.0
 4291           NL        8224         Lelystad  Flevoland    ...                NaN  52.5135     5.4855       6.0
 4292           NL        8225         Lelystad  Flevoland    ...                NaN  52.5025     5.4901       6.0
 4293           NL        8226         Lelystad  Flevoland    ...                NaN  52.4944     5.4954       6.0
 4294           NL        8231         Lelystad  Flevoland    ...                NaN  52.5189     5.4679       6.0
 4295           NL        8232         Lelystad  Flevoland    ...                NaN  52.5074     5.4691       6.0
 4296           NL        8233         Lelystad  Flevoland    ...                NaN  52.5011     5.4755       6.0
 4297           NL        8239         Lelystad  Flevoland    ...                NaN  52.4831     5.4867       6.0
 4298           NL        8241         Lelystad  Flevoland    ...                NaN  52.5377     5.4562       6.0
 4299           NL        8242         Lelystad  Flevoland    ...                NaN  52.5202     5.4486       6.0
 4300           NL        8243         Lelystad  Flevoland    ...                NaN  52.5065     5.4487       6.0
 4301           NL        8244         Lelystad  Flevoland    ...                NaN  52.4972     5.4195       6.0
 4302           NL        8245         Lelystad  Flevoland    ...                NaN  52.4940     5.4570       6.0

 [4303 rows x 12 columns])

Find the geo coordinates by postal code:

# Get the coordinates from the postal code given. Note that the 
# postal code shall not contain letters.
nomi.query_postal_code("9712")

Output:

postal_code            9746
country code             NL
place_name        Groningen
state_name        Groningen
state_code                4
county_name       Groningen
county_code              14
community_name          NaN
community_code          NaN
latitude            53.2357
longitude            6.5125
accuracy                  6
Name: 0, dtype: object
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment