Repository: geopandas/geopandas

Issue:
overlay gives confusing error when passed `GeoSeries`
Should either support or give informative error. Right now gives:

```
In [6]: country_cores = overlay(countries, capital_buffer, how='intersection')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-a69b51de5bcf> in <module>()
----> 1 country_cores = overlay(countries, capital_buffer, how='intersection')

/Users/Nick/github/geopandas/geopandas/tools/overlay.py in overlay(df1, df2, how, use_sindex)
     85     # Collect the interior and exterior rings
     86     rings1 = _extract_rings(df1)
---> 87     rings2 = _extract_rings(df2)
     88     mls1 = MultiLineString(rings1)
     89     mls2 = MultiLineString(rings2)

/Users/Nick/github/geopandas/geopandas/tools/overlay.py in _extract_rings(df)
     31     poly_msg = "overlay only takes GeoDataFrames with (multi)polygon geometries"
     32     rings = []
---> 33     for i, feat in df.iterrows():
     34         geom = feat.geometry
     35 

/Users/Nick/github/pandas/pandas/core/generic.py in __getattr__(self, name)
   2665             if name in self._info_axis:
   2666                 return self[name]
-> 2667             return object.__getattribute__(self, name)
   2668 
   2669     def __setattr__(self, name, value):

AttributeError: 'GeoSeries' object has no attribute 'iterrows'
```



Discussion:

Resolving patch:
diff --git a/geopandas/tools/overlay.py b/geopandas/tools/overlay.py
--- a/geopandas/tools/overlay.py
+++ b/geopandas/tools/overlay.py
@@ -30,8 +30,10 @@ def _extract_rings(df):
     """
     poly_msg = "overlay only takes GeoDataFrames with (multi)polygon geometries"
     rings = []
+    geometry_column = df.geometry.name
+
     for i, feat in df.iterrows():
-        geom = feat.geometry
+        geom = feat[geometry_column]
 
         if geom.type not in ['Polygon', 'MultiPolygon']:
             raise TypeError(poly_msg)
@@ -82,6 +84,9 @@ def overlay(df1, df2, how, use_sindex=True):
         raise ValueError("`how` was \"%s\" but is expected to be in %s" % \
             (how, allowed_hows))
 
+    if isinstance(df1, GeoSeries) or isinstance(df2, GeoSeries):
+        raise NotImplementedError("overlay currently only implemented for GeoDataFrames")
+
     # Collect the interior and exterior rings
     rings1 = _extract_rings(df1)
     rings2 = _extract_rings(df2)
@@ -125,13 +130,13 @@ def overlay(df1, df2, how, use_sindex=True):
         prop2 = None
         for cand_id in candidates1:
             cand = df1.ix[cand_id]
-            if cent.intersects(cand.geometry):
+            if cent.intersects(cand[df1.geometry.name]):
                 df1_hit = True
                 prop1 = cand
                 break  # Take the first hit
         for cand_id in candidates2:
             cand = df2.ix[cand_id]
-            if cent.intersects(cand.geometry):
+            if cent.intersects(cand[df2.geometry.name]):
                 df2_hit = True
                 prop2 = cand
                 break  # Take the first hit


Test patch:
diff --git a/geopandas/tests/test_overlay.py b/geopandas/tests/test_overlay.py
--- a/geopandas/tests/test_overlay.py
+++ b/geopandas/tests/test_overlay.py
@@ -86,6 +86,28 @@ def test_duplicate_column_name(self):
         df = overlay(self.polydf, polydf2r, how="union")
         self.assertTrue('Shape_Area_2' in df.columns and 'Shape_Area' in df.columns)
 
+    def test_geometry_not_named_geometry(self):
+        # Issue #306
+        # Add points and flip names
+        polydf3 = self.polydf.copy()
+        polydf3 = polydf3.rename(columns={'geometry':'polygons'})
+        polydf3 = polydf3.set_geometry('polygons')
+        polydf3['geometry'] = self.pointdf.geometry.loc[0:4]
+        self.assertTrue(polydf3.geometry.name == 'polygons')
+
+        df = overlay(polydf3, self.polydf2, how="union")
+        self.assertTrue(type(df) is GeoDataFrame)
+        
+        df2 = overlay(self.polydf, self.polydf2, how="union")
+        self.assertTrue(df.geom_almost_equals(df2).all())
+
+    def test_geoseries_warning(self):
+        # Issue #305
+
+        def f():
+            overlay(self.polydf, self.polydf2.geometry, how="union")
+        self.assertRaises(NotImplementedError, f)
+