[#]gischat Load a Qgis layer into a geopandas dataframe in the qgis python interpreter :
import pandas as pd
import geopandas as gpd
def layer_to_gdf(layer_name):
# PyQgisation of the layer
vlayer = QgsProject.instance().mapLayersByName(layer_name)[0]
cols = [f.name() for f in vlayer.fields()]
datagen = ([f[col] for col in cols] for f in vlayer.getFeatures())
df = pd.DataFrame.from_records(data=datagen, columns=cols)
# generate GeoSeries
=> More informations about this toot | More toots from thomas_szczurek@mapstodon.space
gs = gpd.GeoSeries.from_wkt([feature.geometry().asWkt() for feature in vlayer.getFeatures()])
# Génération de la Geodataframe
gdf = gpd.GeoDataFrame(df, geometry=gs)
return gdf
[#] name of the layer you want to geodataframe
layer_name = 'your_name'
my_gdf = layer_to_gdf(layer_name)
End of function before "# name" please indent !
=> More informations about this toot | More toots from thomas_szczurek@mapstodon.space
text/gemini
This content has been proxied by September (ba2dc).