Skip to content

Instantly share code, notes, and snippets.

@mazzma12
Created September 29, 2020 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mazzma12/3be29b4611945e3a52f603eae098a82e to your computer and use it in GitHub Desktop.
Save mazzma12/3be29b4611945e3a52f603eae098a82e to your computer and use it in GitHub Desktop.
Convert location points to GeoJSON
"""
Once often need to parse manually a CSV which contains erroneous cell, therefore I prefer not to use gpd.read_file()
"""
from pathlib import Path
import geopandas as gpd
import pandas as pd
import shapely
p = Path("./locations.csv")
df = pd.read_csv(p)
df["geometry"] = [
shapely.geometry.Point(x, y)
for (x, y) in zip(df["Longitude"].astype(float), df["Latitude"].astype(float))
]
gdf = gpd.GeoDataFrame(df)
gdf.to_file(p.with_suffix(".geojson"), driver="GeoJSON")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment