Kotlin island is situated in Gulf of Finland and is one of districts of the city of Saint Petersburg in Russia.
This example shows how Lets-Plot GeoPandas integration can help to build an inset map of Kotlin island.
import geopandas as gpd
from shapely.geometry import box
from lets_plot import *
LetsPlot.setup_html()
spb_gdf = gpd.read_file("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/spb_districts.geojson")
This map will become the inset map. The red rectangle indicates the bounds of the future main map.
kotlin_bbox = [29.63, 59.965, 29.815, 60.035]
kotlin_rect = dict(zip(['xmin', 'ymin', 'xmax', 'ymax'], kotlin_bbox))
spb_plot = ggplot() + \
geom_rect(map=gpd.GeoDataFrame(geometry=[box(*spb_gdf.geometry.total_bounds)]), \
color='black', fill='white') + \
geom_polygon(map=spb_gdf, color='#a1d99b', fill='#f7fcf5') + \
geom_rect(**kotlin_rect, color='red', alpha=0) + \
geom_text(label='Saint Petersburg', x=30.334445, y=59.934294, color='black', size=6) + \
theme_void()
spb_plot
We use xlim
and ylim
parameters of the coordinate system to crop the entire map containing all districts of St.-Petersburg.
# GeoDataFrame containing names and coordinates of some tourist attractions to show on the main map.
places_gdf = gpd.read_file("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/kotlin_places.geojson")
# Cut-out the Kotlin area and add layes with text and points of interest.
kotlin_plot = ggplot() + \
geom_rect(**kotlin_rect, fill='#aadaff', alpha=0.2) + \
geom_polygon(map=spb_gdf, color='#31a354', fill='#e5f5e0') + \
geom_point(aes(color='type', shape='type'), data=places_gdf, size=5) + \
geom_text(aes(label='name'), data=places_gdf, hjust='right', position=position_nudge(x=-.002)) + \
geom_text(label='Kotlin Isl.', x=29.725, y=60.011, color='#31a354', size=13, fontface='italic') + \
geom_text(label='Gulf of Finland', x=29.665, y=60.002, color='#578bcc', size=11, fontface='italic') + \
coord_cartesian(xlim=kotlin_bbox[0::2], ylim=kotlin_bbox[1::2]) + \
ggtitle('Tourist attractions on Kotlin island') + \
theme_void() + theme(legend_position=[.15, .2])
kotlin_plot
bunch = GGBunch()
bunch.add_plot(kotlin_plot, 0, 0, 800, 600)
bunch.add_plot(spb_plot, 600, 25, 200, 150)
bunch.show()