Ancestors

Written by Thomas Szczurek-Gayant on 2024-04-02 at 20:08

[#]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]

attributes dataframe making

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

Toot

Written by Thomas Szczurek-Gayant on 2024-04-02 at 20:09

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

Descendants

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/112203438238356804
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
258.747456 milliseconds
Gemini-to-HTML Time
0.510121 milliseconds

This content has been proxied by September (ba2dc).