Reputation: 471
I am new to Geopandas. How can I draw a circle over a map? I would like to define LAT/LON and radius and then draw it on the map.
This is what I want:
Here is the code:
import matplotlib.pyplot as plt
import geopandas
plt.rcParams["font.family"] = "Times New Roman"
states = geopandas.read_file('data/usa-states-census-2014.shp')
type(states)
states.crs
states = states.to_crs("EPSG:3395")
states.boundary.plot(figsize=(18, 12), color="Black")
plt.show()
How do I plot the circles based on Lat/Long and Radius?
Upvotes: 1
Views: 4041
Reputation: 18772
Fortunately, the projection "EPSG:3395" is a conformal projection. To draw (projections of) circles on a conformal projection use .tissot()
method available with cartopy's geoaxes
. Here is a partial code that demonstrates the important steps:
ax2 = plt.subplot(111, projection=ccrs.epsg(3395)) #"EPSG:3395"
# usa_main is a geoDataFrame with crs="EPSG:3395"
usa_main.plot(column="sclass", legend=False,
cmap=matplotlib.cm.Reds,
ec=edgecolor, lw=0.4,
alpha=0.5,
ax=ax2)
# plot circle at 2 locations with different radii
ax2.tissot(rad_km=300, lons=[-95.4,], lats=[29.7,], n_samples=36, zorder=10)
ax2.tissot(rad_km=500, lons=[-81.3,], lats=[28.5,], n_samples=36, zorder=10)
ax2.gridlines(crs=ccrs.PlateCarree(), draw_labels=True)
Upvotes: 2