Skip to content

Instantly share code, notes, and snippets.

View udit-asopa's full-sized avatar
🚀
Open to opportunities

Udit Asopa udit-asopa

🚀
Open to opportunities
View GitHub Profile
@udit-asopa
udit-asopa / plot_geodataframe_on_basemap.py
Created April 27, 2025 08:44
Plot geopandas geodataframe on basemap
import geopandas as gpd
import matplotlib.pyplot as plt
import contextily as ctx
gdf = gpd.read_file('my_population_data.gpkg')
fig, ax = plt.subplots(figsize=(10, 10))
gdf.plot(
ax=ax,
column='population',
@udit-asopa
udit-asopa / clip_geopandas_multipolygon_gdf_with_another_extent_gdf.py
Created April 27, 2025 08:30
Clip one geopandas multipolygon gdf with another clip extent to include only the geometries that the fully within the source gdf
import geopandas as gpd
import matplotlib.pyplot as plt
master_gdf = gpd.read_file('master_gdf.gpkg').to_crs('EPSG:4326') # make sure both gdf are in same CRS
clip_zone_gdf = gpd.read_file('clipping_shapefile.gpkg').to_crs('EPSG:4326')
clip_union = clip_zone_gdf.unary_union
master_gdf_clipped = master_gdf[master_gdf.geometry.within(clip_union)]
master_gdf_clipped.to_file("master_gdf_clipped.gpkg",driver='GPKG')
@udit-asopa
udit-asopa / fetch_springer_ebooks.py
Created August 12, 2024 06:48 — forked from deeplook/fetch_springer_ebooks.py
Fetch free Springer ebooks.
#!/usr/bin/env python3
"""
Download free Springer ebooks.
Examples:
python fetch_springer_ebooks python
python fetch_springer_ebooks --dest my/ebooks math
python fetch_springer_ebooks
@udit-asopa
udit-asopa / file_finder.py
Last active July 29, 2024 20:13
List files with specific string in their name and of specific format, from a big folder with many files
import os
import re
def file_finder(directory_path:str,
specific_string_list:list) -> list:
all_files = os.listdir(directory_path)
all_txt = [file for file in all_files if file.endswith(".txt")]
pattern = re.compile(f"""{"|".join(re.escape(item) for item in specific_string_list)}""")
@udit-asopa
udit-asopa / KML_to_geopandas_dataframe.py
Last active July 29, 2024 19:37
How to read KML file into python and create geopandas dataframe
import os
import geopandas as gpd
from fiona.drvsupport import supported_drivers
def kml_file_reader(kml_filepath:str) -> gpd.GeoDataFrame:
kml_data = gpd.read_file(kml_filepath, driver = 'LIBKML') \
if os.path.exists(kml_filepath) \
else print ("***KML file at provided path does not exists***")