Skip to content

Instantly share code, notes, and snippets.

View gperonato's full-sized avatar

Giuseppe Peronato gperonato

View GitHub Profile
@nygeog
nygeog / csv-to-shapefile-geopandas.py
Last active July 18, 2024 00:31
Read a CSV with Pandas and set as GeoDataFrame with geopandas and save as Shapefile with fiona
import pandas as pd
from geopandas import GeoDataFrame
from shapely.geometry import Point
import fiona
df = pd.read_csv('data.csv')
geometry = [Point(xy) for xy in zip(df.x, df.y)]
crs = {'init': 'epsg:2263'} #http://www.spatialreference.org/ref/epsg/2263/
geo_df = GeoDataFrame(df, crs=crs, geometry=geometry)
@mhweber
mhweber / geopandas_clip.py
Created June 17, 2016 17:16
A quick and dirty poor man's clip using geopandas. First does a union between a plot shapefile and an overlapping features shapefilie, then subsets where attributes of the features shapefile are not null to get the features clipped to boundaries of plots.
Plots = gpd.GeoDataFrame.from_file('Plots.shp')
Plots.plot()
Features = gpd.GeoDataFrame.from_file('Features.shp')
Features.plot()
# union features
Both = overlay(Plots, Features, how="union")
Both.head()
# 'clip' by getting rid of union features where attributes for plot are null in the union
Clips = Both[pd.notnull(Both['ORIG_FID'])]
Clips.plot()
@tdhopper
tdhopper / dataframe to kml
Created March 26, 2013 18:21
Pandas dataframe to KML in 4 lines
import simplekml
kml = simplekml.Kml()
df.apply(lambda X: kml.newpoint(name=X["name"], coords=[( X["longitude"],X["latitude"])]) ,axis=1)
kml.save(path = "data.kml")