mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-21 13:00:14 +08:00
Merge pull request #37 from cfarmer/bounds
changing the way 'bounds' is implemented to match shapely
This commit is contained in:
+16
-1
@@ -5,6 +5,7 @@ import fiona
|
||||
from fiona.crs import from_epsg
|
||||
import numpy as np
|
||||
from pandas import Series, DataFrame
|
||||
from pandas.util.decorators import cache_readonly
|
||||
import pyproj
|
||||
from shapely.geometry import shape, Polygon, Point
|
||||
from shapely.geometry.collection import GeometryCollection
|
||||
@@ -295,7 +296,6 @@ class GeoSeries(Series):
|
||||
# Other operations
|
||||
#
|
||||
|
||||
# should this return bounds for entire series, or elementwise?
|
||||
@property
|
||||
def bounds(self):
|
||||
"""Return a DataFrame of minx, miny, maxx, maxy values of geometry objects"""
|
||||
@@ -303,6 +303,21 @@ class GeoSeries(Series):
|
||||
return DataFrame(bounds,
|
||||
columns=['minx', 'miny', 'maxx', 'maxy'],
|
||||
index=self.index)
|
||||
|
||||
@cache_readonly
|
||||
def total_bounds(self):
|
||||
"""Return a single bounding box (minx, miny, maxx, maxy) for all geometries
|
||||
|
||||
This is a shortcut for the following:
|
||||
>>> aggregator = dict(minx=np.nanmin, miny=np.nanmin,
|
||||
maxx=np.nanmax, maxy=np.nanmax)
|
||||
>>> series.bounds.groupby(lambda x: 1).agg(aggregator)
|
||||
"""
|
||||
|
||||
aggregator = dict(minx=np.nanmin, miny=np.nanmin,
|
||||
maxx=np.nanmax, maxy=np.nanmax)
|
||||
bbox = self.bounds.groupby(lambda x: 1).agg(aggregator)
|
||||
return tuple(bbox.values[0].tolist())
|
||||
|
||||
def buffer(self, distance, resolution=16):
|
||||
return GeoSeries([geom.buffer(distance, resolution) for geom in self],
|
||||
|
||||
@@ -285,4 +285,9 @@ class TestSeries(unittest.TestCase):
|
||||
res = self.g4.skew(ys=skew, origin=Point(0,0))
|
||||
self.assertTrue(geom_almost_equals(self.g4, res.skew(ys=-skew,
|
||||
origin=Point(0,0))))
|
||||
|
||||
def test_total_bounds(self):
|
||||
bbox = self.sol.x, self.sol.y, self.esb.x, self.esb.y
|
||||
self.assertEqual(self.landmarks.total_bounds, bbox)
|
||||
self.assertEqual(self.g1.total_bounds, (0, 0, 1, 1))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user