Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bettdouglas/c2188ca65648dfb45327137e69a840e6 to your computer and use it in GitHub Desktop.
Save bettdouglas/c2188ca65648dfb45327137e69a840e6 to your computer and use it in GitHub Desktop.
A quick snippet to find country_code and centroid from natural earth dataset
url = 'https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip'
#!pip install wget
import wget
# download countries_data set
filename = wget.download(url)
ctry = 'Japan'
import geopandas as gpd
gdf = gpd.read_file(filename)
ctry_geometry = gdf[gdf['ADMIN'].str.contains(ctry)]['geometry'].squeeze() #extract geometry
country_code = gdf[gdf['ADMIN'].str.contains(ctry)]['SOV_A3'].squeeze()
ctry_centroid = ctry_geometry.centroid
lat,lon = ctry_centroid.y,ctry_centroid.x # extract lat and lon
lat,lon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment