Skip to content

Instantly share code, notes, and snippets.

View shakasom's full-sized avatar

Abdishakur Hassan shakasom

View GitHub Profile
countries.crs
# Look at the geometry column: decimal degrees
countries.geometry[:5]
# Project the data into Mercator Projection epsg=3395
countries_projected = countries.to_crs({'init': 'epsg:3395'})
# See the geometry column of the projected countries
countries_projected['geometry'][:5]
fig, ax = plt.subplots(figsize=(14,12))
countries_projected.plot(ax=ax)
# Cities are still in WGS84
cities.plot(ax=ax, color='red');
# Save projected countries
shp = '1-introData/countries_epsg3395.shp'
countries_projected.to_file(shp)
# Read the data
# 1. Read Countries --> Geopackage Format
file = '1-introData/countries.gpkg'
countries = gpd.read_file(file)
# Cities: Point data
cities = gpd.read_file('1-introData/cities.geojson')
# GeoDataFrame
geoDataFrame = countries[['geometry', 'NAME']]
geoDataFrame.head()
type(geoDataFrame)
# GeoDataFrame
geoDataFrame = countries[['geometry', 'NAME']]
geoDataFrame.head()
type(geoDataFrame)
# Series
series = countries['NAME']
series[:5]
print(type(series))
# GeoSeries
geoSeries = countries['geometry']
geoSeries[:5]
print(type(geoSeries))
fig, ax = plt.subplots(figsize=(12,12))
geoDataFrame.centroid.plot(ax=ax)
plt.tight_layout()
plt.show()