|
--- |
|
license: cc-by-4.0 |
|
size_categories: |
|
- 10M<n<100M |
|
tags: |
|
- geospatial |
|
--- |
|
|
|
# Geonames |
|
|
|
A simple parquet conversion of Geonames place database and ZIP codes. |
|
|
|
## Source |
|
|
|
The tab-separated, zipped textfiles `allCountries.zip` from: |
|
|
|
- https://download.geonames.org/export/dump/ and |
|
- https://download.geonames.org/export/zip/. |
|
|
|
## Columns |
|
|
|
allCountries.zip |
|
|
|
``` |
|
The main 'geoname' table has the following fields : |
|
--------------------------------------------------- |
|
geonameid : integer id of record in geonames database |
|
name : name of geographical point (utf8) varchar(200) |
|
asciiname : name of geographical point in plain ascii characters, varchar(200) |
|
alternatenames : alternatenames, comma separated, ascii names automatically transliterated, convenience attribute from alternatename table, varchar(10000) |
|
latitude : latitude in decimal degrees (wgs84) |
|
longitude : longitude in decimal degrees (wgs84) |
|
feature class : see http://www.geonames.org/export/codes.html, char(1) |
|
feature code : see http://www.geonames.org/export/codes.html, varchar(10) |
|
country code : ISO-3166 2-letter country code, 2 characters |
|
cc2 : alternate country codes, comma separated, ISO-3166 2-letter country code, 200 characters |
|
admin1 code : fipscode (subject to change to iso code), see exceptions below, see file admin1Codes.txt for display names of this code; varchar(20) |
|
admin2 code : code for the second administrative division, a county in the US, see file admin2Codes.txt; varchar(80) |
|
admin3 code : code for third level administrative division, varchar(20) |
|
admin4 code : code for fourth level administrative division, varchar(20) |
|
population : bigint (8 byte int) |
|
elevation : in meters, integer |
|
dem : digital elevation model, srtm3 or gtopo30, average elevation of 3''x3'' (ca 90mx90m) or 30''x30'' (ca 900mx900m) area in meters, integer. srtm processed by cgiar/ciat. |
|
timezone : the iana timezone id (see file timeZone.txt) varchar(40) |
|
modification date : date of last modification in yyyy-MM-dd format |
|
``` |
|
|
|
## Conversion |
|
|
|
```python |
|
import pandas as pd |
|
df = pd.read_csv('allCountries.txt', sep='\t', header=None, low_memory=False) |
|
df.to_parquet('geonames_23_03_2025.parquet') |
|
``` |
|
|
|
## Quality |
|
|
|
Be warned, the quality - especially for other languages than English - might sometimes be low. Sometimes there are duplicates and very confusing entries. |
|
|
|
## Query with DuckDB |
|
|
|
### Example query for `München` |
|
|
|
```python |
|
import duckdb |
|
import geopandas |
|
df = duckdb.sql(f"SELECT * FROM 'geonames_23_03_2025.parquet' WHERE \"1\" = 'München' ").df() # you can add the country code to the query with AND \"8\" = 'GB' |
|
gdf = geopandas.GeoDataFrame( df, geometry=geopandas.points_from_xy(x=df["5"], y=df["4"])) |
|
gdf |
|
``` |
|
|
|
| ID | Name | Alternate Name | Additional Info | Latitude | Longitude | Feature Class | Feature Code | Country Code | Admin Code | Admin1 | Admin2 | Admin3 | Admin4 | Population | Elevation | Time Zone | Last Update | Geometry | |
|
|---------|---------|---------------|----------------|-----------|-----------|---------------|--------------|--------------|------------|--------|--------|---------|----------|------------|-----------|---------------|--------------|------------------------| |
|
| 2867711 | München | Muenchen | None | 51.60698 | 13.31243 | P | PPL | DE | None | 11 | 00 | 12062 | 12062500 | 0 | NaN | Europe/Berlin | 2015-09-04 | POINT (13.312 51.607) | |
|
| 2867713 | München | Munchen | None | 48.69668 | 13.46314 | P | PPL | DE | None | 02 | 092 | 09275 | 09275128 | 0 | NaN | Europe/Berlin | 2013-02-19 | POINT (13.463 48.697) | |
|
|
|
Note that using the German spelling the query yields nonsense. Instead, query in English: |
|
|
|
```python |
|
import duckdb |
|
import geopandas |
|
df = duckdb.sql(f"SELECT * FROM 'geonames_23_03_2025.parquet' WHERE \"1\" = 'Munich' AND \"8\" = 'DE' ").df() # you can add the country code to the query with AND \"8\" = 'GB' |
|
gdf = geopandas.GeoDataFrame( df, geometry=geopandas.points_from_xy(x=df["5"], y=df["4"])) |
|
gdf |
|
``` |
|
|
|
| ID | Name | Official Name | Alternate Names | Latitude | Longitude | Feature Class | Feature Code | Country Code | Admin Code | Admin1 | Admin2 | Admin3 | Admin4 | Population | Elevation | Time Zone | Last Update | Geometry | |
|
|---------|--------|--------------|-----------------|-----------|-----------|---------------|--------------|--------------|------------|--------|--------|---------|----------|------------|-----------|--------------|--------------|------------------------| |
|
| 2867714 | Munich | Munich | Lungsod ng Muenchen, Lungsod ng München, MUC, Min... | 48.13743 | 11.57549 | P | PPLA | DE | None | 02 | 091 | 09162 | 09162000 | 1260391 | NaN | 524 | Europe/Berlin | 2023-10-12 | POINT (11.575 48.137) | |
|
|
|
This query returns only one entry with a city centroid, just as expected. |
|
|
|
## Visualize with deck.gl |
|
|
|
```python |
|
import pydeck as pdk |
|
import pandas as pd |
|
import numpy as np |
|
|
|
# load some gdf |
|
gdf["coordinates"] = gdf.apply(lambda x: [x.geometry.x, x.geometry.y], axis=1) |
|
|
|
# Define a layer to display on a map |
|
layer = pdk.Layer( |
|
"ScatterplotLayer", |
|
# coordinates is an array |
|
gdf[["1","coordinates"]], # super important! only pass what's needed. If geometry column from geopandas is passed, error! |
|
pickable=True, |
|
opacity=0.99, |
|
stroked=True, |
|
filled=True, |
|
radius_scale=6, |
|
radius_min_pixels=1, |
|
radius_max_pixels=100, |
|
line_width_min_pixels=1, |
|
get_position="coordinates", |
|
get_radius="1000", |
|
get_fill_color=[255, 140, 0], |
|
get_line_color=[255, 140, 0], |
|
) |
|
|
|
# Set the viewport location |
|
view_state = pdk.ViewState(latitude=np.mean(gdf.geometry.y), longitude=np.mean(gdf.geometry.x), zoom=12, bearing=0, pitch=0) |
|
|
|
# Render |
|
r = pdk.Deck(layers=[layer], initial_view_state=view_state,height=2000, tooltip={"text": "{1}"}) |
|
r.to_html("scatterplot_layer.html") |
|
``` |
|
|
|
 |
|
|
|
## Sample |
|
|
|
| ID | Name | Official Name | Alternate Names | Latitude | Longitude | Feature Class | Feature Code | Country Code | Admin Code | Admin1 | Admin2 | Admin3 | Admin4 | Population | Elevation | Time Zone | Last Update | |
|
|----------|-------------------------------|------------------------------------|-------------------------------------------------|-----------|-----------|---------------|--------------|--------------|------------|--------|--------|--------|--------|------------|-----------|---------------|--------------| |
|
| 2994701 | Roc Meler | Roc Meler | Roc Mele, Roc Meler, Roc Mélé | 42.58765 | 1.74180 | T | PK | AD | AD,FR | 02 | NaN | NaN | NaN | 0 | 2811 | Europe/Andorra | 2023-10-03 | |
|
| 3017832 | Pic de les Abelletes | Pic de les Abelletes | Pic de la Font-Negre, Pic de la Font-Nègre, Pic ... | 42.52535 | 1.73343 | T | PK | AD | FR | A9 | 66 | 663 | 66146 | 0 | NaN | 2411 | Europe/Andorra | 2014-11-05 | |
|
| 3017833 | Estany de les Abelletes | Estany de les Abelletes | Estany de les Abelletes, Etang de Font-Negre, Ét... | 42.52915 | 1.73362 | H | LK | AD | FR | A9 | NaN | NaN | NaN | 0 | NaN | 2260 | Europe/Andorra | 2014-11-05 | |
|
| 3023203 | Port Vieux de la Coume d’Ose | Port Vieux de la Coume d'Ose | Port Vieux de Coume d'Ose, Port Vieux de Coume ... | 42.62568 | 1.61823 | T | PASS | AD | NaN | 00 | NaN | NaN | NaN | 0 | NaN | 2687 | Europe/Andorra | 2014-11-05 | |
|
| 3029315 | Port de la Cabanette | Port de la Cabanette | Port de la Cabanette, Porteille de la Cabanette | 42.60000 | 1.73333 | T | PASS | AD | AD,FR | B3 | 09 | 091 | 09139 | 0 | NaN | 2379 | Europe/Andorra | 2014-11-05 | |
|
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | |
|
| 13216940 | GLORIA Seamount | GLORIA Seamount | NaN | 45.03000 | -15.53500 | U | SMU | NaN | NaN | 00 | NaN | NaN | NaN | 0 | NaN | -9999 | NaN | 2025-02-19 | |
|
| 13216941 | Yubko Hills | Yubko Hills | NaN | 13.01820 | -134.41130 | U | HLSU | NaN | NaN | 00 | NaN | NaN | NaN | 0 | NaN | -9999 | NaN | 2025-02-19 | |
|
| 13216942 | Maguari Seamount | Maguari Seamount | NaN | 0.68832 | -44.31278 | U | SMU | NaN | NaN | 00 | NaN | NaN | NaN | 0 | NaN | -9999 | NaN | 2025-02-19 | |
|
| 13216943 | Quintana Seamount | Quintana Seamount | NaN | -32.74950 | -38.67696 | U | SMU | NaN | NaN | 00 | NaN | NaN | NaN | 0 | NaN | -9999 | NaN | 2025-02-19 | |
|
| 13216944 | Satander Guyot | Satander Guyot | NaN | -1.92806 | -37.82161 | U | DEPU | NaN | NaN | 00 | NaN | NaN | NaN | 0 | NaN | -9999 | NaN | 2025-02-19 | |
|
|
|
13111559 rows × 19 columns |