Spaces:
Sleeping
Sleeping
import requests | |
import geopandas as gpd | |
def download_github_geojson(github_user, repository, file_path, token): | |
""" | |
Load GeoJSON data from a GitHub repository. | |
Args: | |
github_user (str): GitHub username. | |
repository (str): GitHub repository name. | |
file_path (str): Path of the GeoJSON file in the repository. | |
Returns: | |
pd.DataFrame: The loaded GeoJSON data. | |
""" | |
# headers with personal access token | |
headers = { | |
"Authorization": f"token {token}" | |
} | |
# Create a URL to the raw GeoJSON file in the repository | |
raw_url = f"https://raw.githubusercontent.com/{github_user}/{repository}/{file_path}" | |
print(f"Debug: raw_url = {raw_url}") # Debugging line | |
# Make a GET request to the URL | |
response = requests.get(raw_url, headers=headers) | |
if response.status_code == 200: | |
# Parse the GeoJSON data | |
geojson_data = gpd.read_file(response.text) | |
print("File loaded succesfully.") | |
print(geojson_data.head()) | |
return geojson_data | |
else: | |
print(f"Failed to retrieve GeoJSON data. Status code: {response.status_code}") | |
return None | |