From be4a1efa4e7c0b2cbd8a877e816d9200c951a679 Mon Sep 17 00:00:00 2001 From: Kelsey Jordahl Date: Thu, 27 Jun 2013 17:46:46 -0500 Subject: [PATCH] Implement union and difference methods. --- geopandas/geoseries.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/geopandas/geoseries.py b/geopandas/geoseries.py index d1b1b1a..03b4f07 100644 --- a/geopandas/geoseries.py +++ b/geopandas/geoseries.py @@ -135,6 +135,33 @@ class GeoSeries(Series): return Series([s.contains(other) for s in self], index=self.index) + # TODO: refactor to eliminate replications + def difference(self, other): + """ + Return a GeoSeries of differences + Operates on either a GeoSeries or a Shapely geometry + """ + if isinstance(other, GeoSeries): + # TODO: align series + return GeoSeries([s[0].difference(s[1]) for s in zip(self, other)], + index=self.index) + else: + return GeoSeries([s.difference(other) for s in self], + index=self.index) + + def union(self, other): + """ + Return a GeoSeries of differences + Operates on either a GeoSeries or a Shapely geometry + """ + if isinstance(other, GeoSeries): + # TODO: align series + return GeoSeries([s[0].union(s[1]) for s in zip(self, other)], + index=self.index) + else: + return GeoSeries([s.union(other) for s in self], + index=self.index) + def buffer(self, distance, resolution=16): return GeoSeries([geom.buffer(distance, resolution) for geom in self], index=self.index)