# Working with GeoSeries¶

In [1]:
from geopandas import GeoSeries
from shapely.geometry import Polygon, Point, LineString
pylab.rcParams['savefig.dpi'] = 100


#### Create some geometries with Shapely:¶

In [2]:
poly1 = Polygon([(0, 0), (1, 0), (1, 1)])
poly2 = Polygon([(2, 0), (3, 0), (3, 1), (2, 1)])
circle = Point([(1.5, 0.5)]).buffer(0.5)


#### Create a GeoSeries from a sequence of geometries:¶

In [3]:
g = GeoSeries([poly1, circle, poly2])
print g

0    POLYGON ((0.0000000000000000 0.000000000000000...
1    POLYGON ((2.0000000000000000 0.500000000000000...
2    POLYGON ((2.0000000000000000 0.000000000000000...
dtype: object

In [4]:
g.plot()

Out[4]:
<matplotlib.axes.AxesSubplot at 0x105a5b950>

Now we create a new series that has

In [5]:
big_circle = Point([1.5, 1.0]).buffer(0.9)
g.plot()
GeoSeries([big_circle]).plot()

Out[5]:
<matplotlib.axes.AxesSubplot at 0x10bf238d0>
In [6]:
g.difference(big_circle)

Out[6]:
0    POLYGON ((1.0000000000000000 0.251669431327654...
1    POLYGON ((1.8929164090542658 0.191447836648926...
2    POLYGON ((2.3999999999999999 1.000000000000000...
dtype: object
In [7]:
g.difference(big_circle).plot()

Out[7]:
<matplotlib.axes.AxesSubplot at 0x10bcf8690>
In [8]:
pts = GeoSeries([Point([0,0]), LineString([[1.5, 1], [1.5, 1.5]]), Point([3,0])])
c = pts.buffer(0.5)
g.plot()
c.plot()

Out[8]:
<matplotlib.axes.AxesSubplot at 0x10bcf4250>
In [9]:
g.union(c).plot()

Out[9]:
<matplotlib.axes.AxesSubplot at 0x10bcf1fd0>
In [10]:
g.intersection(c).plot()

Out[10]:
<matplotlib.axes.AxesSubplot at 0x10bcf1390>