Created
May 15, 2021 14:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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