A faster way of loading shapely.wkt geometries into a pandas dataframe from a dataframe of WKT strings

Viewed 337

How it's currently done is as follows:

geoms = df["wkt"].apply(shapely.wkt.loads).values

Here df["wkt"] has rows with data like:

"MULTIPOLYGON (((24.2401805 70.8385222,24.2402333 70.83850555,24.2402166 70.83848885,24.24015 70.83848885,24.2401277 70.83850555,24.2401805 70.8385222)))"

But as the dataframe that the function is being applied to is huge this takes a while. Is there a way to speed this up? I've tried looking at multithreading or similar, but didn't really get it to work.

The same applies to this line:

df_geoms = [shapely.wkt.loads(x) for x in df.geom.values]
1 Answers

You can try the from_wkt command from the GeoPandas library:

geoms = geopandas.GeoSeries.from_wkt(df["wkt"])
Related