6

I have a geopandas dataframe

    geometry                                           idx
0   POLYGON ((-74.25559 40.91553, -74.24559 40.915...   0
1   POLYGON ((-74.25559 40.90553, -74.24559 40.905...   1
2   POLYGON ((-74.25559 40.89553, -74.24559 40.895...   2
3   POLYGON ((-74.25559 40.88553, -74.24559 40.885...   3
4   POLYGON ((-74.25559 40.87553, -74.24559 40.875...   4

where

gridDF['geometry'][0]
 <shapely.geometry.polygon.Polygon at 0x7fa4cc6ccc50>

I would like to convert the entries in the column geometry as a string.

emax
  • 6,965
  • 19
  • 74
  • 141

2 Answers2

6

You can use apply if you want to do all rows at once.

from shapely import wkt
gridDF['str_geom'] = gridDF.geometry.apply(lambda x: wkt.dumps(x))
Matthew Borish
  • 3,016
  • 2
  • 13
  • 25
  • 2
    can also write this as ```gridDF['str_geom'] = gridDF['geometry'].apply(wkt.dumps) ``` `wkt.dumps` is already a single function, so not required to write it inside a lambda – user4815162342 Jun 28 '21 at 13:37
0

I think you can use this function: shapely.wkt.dumps

Example:

from shapely import wkt
wkt_string = wkt.dumps(gridDF['geometry'][0])
print(wkt_string)

The wkt_string should be the geometry as string in wkt format.

Yosua
  • 411
  • 3
  • 7