After i did an intersection with two shape using geopandas through the following topic (Intersecting two shape problem using geopandas). But it output a multi geometry type shape,which in futher step will impossible export to polygon. Results show as below:

for i in data:
   geom = i['geometry']
   print geom


POLYGON ((139.9125 40.592043, 139.925 40.592043, 139.925 40.58371, 139.9125 40.58371, 139.9125 40.592043))
POINT (139.9125 40.58371)
LINESTRING (139.9125 40.58371, 139.925 40.58371)

How can i exclude Point and LineString from multi-types into a single geometry type as polygon?

1 Answer 1


If you simply want to exclude all the geometries that are not polygons

for i in data:
   geom = i['geometry']
   if geom.geom_type=='Polygon':
      print geom

Return only Polygon geometries

data_ok= []
for i in data:
   if i['geometry'].geom_type=='Polygon':

or in one line with list comprehensions, in one line

 data_ok= [i for i in data if i['geometry'].geom_type=='Polygon']

And you can eliminate a loop in your original script

data = []
for index, orig in poly1.iterrows():
    for index2, ref in poly2.iterrows():      
        if ref['geometry'].intersects(orig['geometry']): 
             if ref['geometry'].intersection(orig['geometry']).geom_type=='Polygon':
  • Thanks very much. I know this print will works, but how to return and set the intersected data only holds polygon geometry?
    – King-Zhao
    Mar 2, 2017 at 12:43
  • With another list, for example, look above
    – gene
    Mar 2, 2017 at 13:05
  • Yeah, thank you so much, i've got the problem solved, it works. But as usual, the output to_file method always show an error like this: ` self.session.start(self, **kwargs)` File "fiona\ogrext.pyx", line 942, in fiona.ogrext.WritingSession.start (fiona/ogrext.c:16386) ValueError: Null layer
    – King-Zhao
    Mar 3, 2017 at 0:26
  • df = gpd.GeoDataFrame(data,columns=['geometry','wdspd']) df.to_file('./wdspd_intersection.shp')` df.head()
    – King-Zhao
    Mar 3, 2017 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.