Skip to content

Commit

Permalink
fix some warnings and formated Footprint class docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
hervenivon committed Jul 6, 2018
1 parent 984104e commit 3b40328
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 51 deletions.
2 changes: 1 addition & 1 deletion buzzard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
When you import :code:`buzzard` for the first time, you should always do it from the main thread.
IMPORTANT: When you import :code:`buzzard` for the first time, you should always do it from the main thread.
"""

# Import osgeo before cv2
Expand Down
124 changes: 74 additions & 50 deletions buzzard/_footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,58 +30,80 @@
class Footprint(TileMixin, IntersectionMixin):
"""Constant object representing the location and size of a spatially localized raster.
The Footprint
- is a toolbox class designed to locate a rectangle in both image space and geometry space
- its main purpose is to simplify the manipulation of windows in rasters
- has many accessors
- has many algorithms
- is a constant object
- is designed to work with any rectangle in space (like non north-up/west-left rasters)
- is independent from projections, units and files
- uses [affine](https://github.com/sgillies/affine) library internally for conversions
Methods
-------
Method category | Method names
------------------------------------|-----------------------------------------------------------
Footprint construction |
from scratch | __init__, of_extent
from Footprint | __and__, intersection, erode, dilate, ...
Conversion | extent, coords, geom, __geo_interface__
Accessors |
Spatial - Size and vectors | size, width, height, diagvec, ...
Spatial - Coordinates | tl, bl, br, tr, ...
Spatial - Misc | area, length, semiminoraxis, ...
Raster - Size | rsize, rwidth, rheight, ...
Raster - Indices | rtl, rbl, rbr, ttr, ...
Raster - Misc | rarea, rlength, rsemiminoraxis, ...
Affine transformations | pxsize, pxvec, angle, ...
Binary predicates | __eq__, ...
Numpy | shape, meshgrid_raster, meshgrid_spatial, slice_in, ...
Coordinates conversions | spatial_to_raster, raster_to_spatial
Geometry / Raster conversions | find_polygons, burn_polygons, ...
Tiling | tile, tile_count, tile_occurrence
Serialization | __str__, ...
Informations on geo transforms (gt) and affine matrices
-------------------------------------------------------
http://www.perrygeo.com/python-affine-transforms.html
https://pypi.python.org/pypi/affine/1.0
GDAL ordering
The :code:`Footprint` class:
- is a toolbox class designed to position a rectangle in both image space and geometry space,
- its main purpose is to simplify the manipulation of windows in rasters,
- has many accessors,
- has many algorithms,
- is a constant object,
- is designed to work with any rectangle in space (like non north-up/west-left rasters),
- is independent from projections, units and files,
- uses :code:`affine` library internally for conversions (https://github.com/sgillies/affine).
+-------------------------------------------------+--------------------------------------------------------+
| Method category | Method names |
+==============+==================================+========================================================+
| Footprint | from scratch | __init__, of_extent |
| construction +----------------------------------+--------------------------------------------------------+
| | from :code:`Footprint` | __and__, intersection, erode, dilate, ... |
+--------------+----------------------------------+--------------------------------------------------------+
| Conversion | extent, coords, geom, __geo_interface__ |
+--------------+----------------------------------+--------------------------------------------------------+
| Accessors | Spatial - Size and vectors | size, width, height, diagvec, ... |
| +----------------------------------+--------------------------------------------------------+
| | Spatial - Coordinates | tl, bl, br, tr, ... |
| +----------------------------------+--------------------------------------------------------+
| | Spatial - Misc | area, length, semiminoraxis, ...x |
| +----------------------------------+--------------------------------------------------------+
| | Raster - Size | rsize, rwidth, rheight, ... |
| +----------------------------------+--------------------------------------------------------+
| | Raster - Indices | rtl, rbl, rbr, ttr, ... |
| +----------------------------------+--------------------------------------------------------+
| | Raster - Misc | rarea, rlength, rsemiminoraxis, ... |
| +----------------------------------+--------------------------------------------------------+
| | Affine transformations | pxsize, pxvec, angle, ... |
+--------------+----------------------------------+--------------------------------------------------------+
| Binary predicates | __eq__, ... |
+-------------------------------------------------+--------------------------------------------------------+
| Numpy | shape, meshgrid_raster, meshgrid_spatial, slice_in, ...|
+-------------------------------------------------+--------------------------------------------------------+
| Coordinates conversions | spatial_to_raster, raster_to_spatial |
+-------------------------------------------------+--------------------------------------------------------+
| Geometry / Raster conversions | find_polygons, burn_polygons, ... |
+-------------------------------------------------+--------------------------------------------------------+
| Tiling | tile, tile_count, tile_occurrence |
+-------------------------------------------------+--------------------------------------------------------+
| Serialization | __str__, ... |
+-------------------------------------------------+--------------------------------------------------------+
Informations on geo transforms (gt) and affine matrices:
- http://www.perrygeo.com/python-affine-transforms.html
- https://pypi.python.org/pypi/affine/1.0
GDAL ordering:
+-----+------------------+--------------+-----+-----------------+-------------------+
| c | a | b | f | d | e |
|-----|------------------|--------------|-----|-----------------|-------------------|
+-----+------------------+--------------+-----+-----------------+-------------------+
| tlx | width of a pixel | row rotation | tly | column rotation | height of a pixel |
+-----+------------------+--------------+-----+-----------------+-------------------+
>>> c, a, b, f, d, e = fp.gt
>>> tlx, dx, rx, tly, ry, dy = fp.gt
Matrix ordering
Matrix ordering:
+------------------+--------------+-----+-----------------+-------------------+-----+
| a | b | c | d | e | f |
|------------------|--------------|-----|-----------------|-------------------|-----|
+------------------+--------------+-----+-----------------+-------------------+-----+
| width of a pixel | row rotation | tlx | column rotation | height of a pixel | tly |
+------------------+--------------+-----+-----------------+-------------------+-----+
>>> a, b, c, d, e, f = fp.aff6
>>> dx, rx, tlx, ry, dy, tly = fp.aff6
"""

__slots__ = ['_tl', '_bl', '_br', '_tr', '_aff', '_rsize', '_significant_min']
Expand Down Expand Up @@ -200,9 +222,10 @@ def of_extent(cls, extent, scale):
extent: (nbr, nbr, nbr, nbr)
Spatial coordinates of (minx, maxx, miny, maxy) defining a rectangle
scale: nbr or (nbr, nbr)
Resolution of output Footprint
if nbr: resolution = [a, -a]
if (nbr, nbr): resolution [a, b]
Resolution of output Footprint:
* if nbr: resolution = [a, -a]
* if (nbr, nbr): resolution [a, b]
"""
# Check extent parameter
extent = np.asarray(extent, dtype='float64')
Expand Down Expand Up @@ -245,7 +268,7 @@ def of_extent(cls, extent, scale):
return cls(tl=rect.tl, size=size, rsize=rsize)

def clip(self, startx, starty, endx, endy):
"""Construct a new Footprint from by clipping self using pixel indices
"""Construct a new Footprint by clipping self using pixel indices
To clip using coordinates see `Footprint.intersection`.
Expand All @@ -262,7 +285,8 @@ def clip(self, startx, starty, endx, endy):
Returns
-------
Footprint
: Footprint
The new clipped :code:`Footprint`
"""
startx, endx, _ = slice(startx, endx).indices(self.rsizex)
starty, endy, _ = slice(starty, endy).indices(self.rsizey)
Expand All @@ -289,13 +313,13 @@ def _morpho(self, scount):
)

def erode(self, count):
"""Construct a new Footprint from self, eroding all edges by `count` pixels"""
"""Construct a new Footprint from self, eroding all edges by :code:`count` pixels"""
assert count >= 0
assert count == int(count)
return self._morpho(-count)

def dilate(self, count):
"""Construct a new Footprint from self, dilating all edges by `count` pixels"""
"""Construct a new Footprint from self, dilating all edges by :code:`count` pixels"""
assert count >= 0
assert count == int(count)
return self._morpho(count)
Expand Down

0 comments on commit 3b40328

Please sign in to comment.