Geopandas: how to convert the column geometry to string?

Viewed 5817

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.

2 Answers

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))

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.

Related