Created
September 29, 2020 15:13
-
-
Save mazzma12/3be29b4611945e3a52f603eae098a82e to your computer and use it in GitHub Desktop.
Convert location points to GeoJSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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