Skip to content
Browse files

Start to subclass Series to a GeoSeries

  • Loading branch information...
Kelsey Jordahl
Kelsey Jordahl committed Jun 27, 2013
0 parents commit 60f285509394ac2a81847d249a90a315c4faa3fa
Showing with 51 additions and 0 deletions.
  1. +51 −0 geopandas/
@@ -0,0 +1,51 @@
import numpy as np
from pandas import Series, DataFrame

class GeoSeries(Series):
A Series object designed to store shapely geometry objects.

def __new__(cls, *args, **kwargs):
arr = Series.__new__(cls, *args, **kwargs)
return arr.view(GeoSeries)

def area(self):
Return the area of each member of the GeoSeries
return Series([geom.area for geom in self], index=self.index)

def boundary(self):
return GeoSeries([geom.boundary for geom in self], index=self.index)

def bounds(self):
Return a DataFrame of minx, miny, maxx, maxy values of geometry objects
bounds = np.array([geom.bounds for geom in self])
return DataFrame(bounds,
columns=['minx', 'miny', 'maxx', 'maxy'],

def geom_type(self):
return Series([geom.geom_type for geom in self], index=self.index)

def contains(self, other):
Return a Series of boolean values.
Operates on either a GeoSeries or a Shapely geometry
if isinstance(other, GeoSeries):
# TODO: align series
return Series([s[0].contains(s[1]) for s in zip(self, other)],
return Series([s.contains(other) for s in self],

0 comments on commit 60f2855

Please sign in to comment.
You can’t perform that action at this time.