hydro-engine icon indicating copy to clipboard operation
hydro-engine copied to clipboard

snapping to nicer extents

Open visr opened this issue 7 years ago • 0 comments

In the wflow modelbuilder I always snap outside to nice coordinates, i.e. if the cellsize is 0.01, then the bounding box coordinates are divisible by 0.01, (i.e. 34.4, 20.54, but not as we currently get from the hydro engine with catchment finding 10.498425023678). This makes it a bit nicer, because it is more likely to align with other datasets.

This is the code I used in Python

def round_extent(extent, snap, prec):
    """Increases the extent until all sides lie on a coordinate
    divisible by 'snap'."""
    xmin, ymin, xmax, ymax = extent
    snap = float(snap)  # prevent integer division issues
    xmin = round(np.floor(xmin / snap) * snap, prec)
    ymin = round(np.floor(ymin / snap) * snap, prec)
    xmax = round(np.ceil(xmax / snap) * snap, prec)
    ymax = round(np.ceil(ymax / snap) * snap, prec)
    return xmin, ymin, xmax, ymax

Might be nice to provide for this option in the hydro engine api as well? Or perhaps even make it default.

visr avatar Jun 21 '18 10:06 visr