Rose
Rose

Reputation: 205

Extracting Shapely Polygon Geometries as WKT list from Geopandas GeoDataFrame

Having no luck extracting shapefile Polygon geometries in a Geopandas Geodatabase.

Variable keeps displaying as <shapely.geometry.polygon.Polygon object at 0x0000020ADDDC00D0>

Not as the WKT displayed when printing out the GeoDataFrame.

Geopandas GeoDataFrame - named intersection_matches

            index_tile sheet_code  scale  tile                                           geometry
210648  BE36_1000_1349       BE36   1000  1349  POLYGON ((1875520.000 5792640.000, 1875040.000...
210649  BE36_1000_1350       BE36   1000  1350  POLYGON ((1876000.000 5792640.000, 1875520.000...
210698  BE36_1000_1449       BE36   1000  1449  POLYGON ((1875520.000 5791920.000, 1875040.000...
210699  BE36_1000_1450       BE36   1000  1450  POLYGON ((1876000.000 5791920.000, 1875520.000...
<class 'geopandas.geodataframe.GeoDataFrame'>

Extracting Shapely Polygon Column Rows from GeoDataFrame attempting to convert to WKT as object variable

1)
geometries = wkt.dumps(intersection_matches['geometry'])
print (geometries)
-------------------------
[<shapely.geometry.polygon.Polygon object at 0x000001DE73E58F40>, 
<shapely.geometry.polygon.Polygon object at 0x000001DE73E58FA0>, 
<shapely.geometry.polygon.Polygon object at 0x000001DE73E6C280>]

2)
print (intersection_matches['geometry'].tolist())
-------------------------
(same output as above)

3)
print (intersection_matches.iloc[:, 4].tolist())
-------------------------
TypeError: Only str is accepted.

4)
print (intersection_matches.decode("utf-8")[intersection_matches['geometry'].isin(list_of_values))
-------------------------
AttributeError: 'GeoDataFrame' object has no attribute 'decode'

Context

import geopandas as gpd
from shapely.geometry import Polygon
from shapely import wkt

imagery_bb_polygon_df = gpd.GeoDataFrame(index=[0], crs=("epsg:2193"), geometry=[Polygon(list_of_points)])
topo50_df = gpd.read_file(topo50_geometry_file)

intersection_matches = topo50_df.overlay(imagery_bb_polygon_df, how='intersection', keep_geom_type=False)

Upvotes: 1

Views: 3199

Answers (1)

Rose
Rose

Reputation: 205

print (intersection_matches['geometry'].to_wkt())

Upvotes: 2

Related Questions