当前位置: 首页>>代码示例>>Python>>正文


Python affine.Affine方法代码示例

本文整理汇总了Python中affine.Affine方法的典型用法代码示例。如果您正苦于以下问题:Python affine.Affine方法的具体用法?Python affine.Affine怎么用?Python affine.Affine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在affine的用法示例。


在下文中一共展示了affine.Affine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_bbox

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def set_bbox(self, new_bbox):
        """
        Sets new bbox while maintaining the same cell dimensions. Updates
        self.affine and self.shape. Also resets self.mask.

        Note that this method rounds the given bbox to match the existing
        cell dimensions.

        Parameters
        ----------
        new_bbox : tuple of floats (length 4)
                   (xmin, ymin, xmax, ymax)
        """
        affine = self.affine
        xmin, ymin, xmax, ymax = new_bbox
        ul = np.around(~affine * (xmin, ymax)).astype(int)
        lr = np.around(~affine * (xmax, ymin)).astype(int)
        xmin, ymax = affine * tuple(ul)
        shape = tuple(lr - ul)[::-1]
        new_affine = Affine(affine.a, affine.b, xmin,
                            affine.d, affine.e, ymax)
        self.affine = new_affine
        self.shape = shape
        #TODO: For now, simply reset mask
        self.mask = np.ones(shape, dtype=np.bool) 
开发者ID:mdbartos,项目名称:pysheds,代码行数:27,代码来源:grid.py

示例2: set_indices

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def set_indices(self, new_indices):
        """
        Updates self.affine and self.shape to correspond to new indices representing
        a new bounding rectangle. Also resets self.mask.

        Parameters
        ----------
        new_indices : tuple of ints (length 4)
                      (xmin_index, ymin_index, xmax_index, ymax_index)
        """
        affine = self.affine
        assert all((isinstance(ix, int) for ix in new_indices))
        ul = np.asarray((new_indices[0], new_indices[3]))
        lr = np.asarray((new_indices[2], new_indices[1]))
        xmin, ymax = affine * tuple(ul)
        shape = tuple(lr - ul)[::-1]
        new_affine = Affine(affine.a, affine.b, xmin,
                            affine.d, affine.e, ymax)
        self.affine = new_affine
        self.shape = shape
        #TODO: For now, simply reset mask
        self.mask = np.ones(shape, dtype=np.bool) 
开发者ID:mdbartos,项目名称:pysheds,代码行数:24,代码来源:grid.py

示例3: global_reader

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def global_reader(value=None):
    array = np.ma.masked_array(
        np.empty(shape=(360, 720), dtype=np.float32, order="C"),
        np.empty(shape=(360, 720), dtype=np.bool, order="C"),
    )
    if value is None:
        array.mask.fill(True)
    else:
        array.fill(value)
        array.mask.fill(False)
    transform = Affine(-180.0, 0.5, 0.0, 90.0, 0.0, -0.5)
    reader = Mock(spec=DatasetReader)
    reader.read.return_value = array
    reader.shape = array.shape
    reader.transform = transform
    reader.bounds = (-180.0, -90.0, 180.0, 90.0)
    reader.window.return_value = ((0, 359), (0, 719))
    reader.window_transform.return_value = transform
    return reader 
开发者ID:GFDRR,项目名称:thinkhazard,代码行数:21,代码来源:test_process.py

示例4: bounds_to_ranges

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def bounds_to_ranges(out_bounds=None, in_affine=None, in_shape=None):
    """
    Return bounds range values from geolocated input.

    Parameters
    ----------
    out_bounds : tuple
        left, bottom, right, top
    in_affine : Affine
        input geolocation
    in_shape : tuple
        input shape

    Returns
    -------
    minrow, maxrow, mincol, maxcol
    """
    return itertools.chain(
        *from_bounds(
            *out_bounds, transform=in_affine, height=in_shape[-2], width=in_shape[-1]
        ).round_lengths(pixel_precision=0).round_offsets(pixel_precision=0).toranges()
    ) 
开发者ID:ungarj,项目名称:mapchete,代码行数:24,代码来源:raster.py

示例5: _morpho

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def _morpho(self, scount):
        aff = self._aff * affine.Affine.translation(-scount, -scount)
        return Footprint(
            gt=aff.to_gdal(),
            rsize=(self.rsize + 2 * scount),
        ) 
开发者ID:airware,项目名称:buzzard,代码行数:8,代码来源:_footprint.py

示例6: size

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def size(self):
        """Spatial distances: (||raster left - raster right||, ||raster top - raster bottom||)"""
        return np.abs(~affine.Affine.rotation(self.angle) * self.diagvec, dtype=np.float64) 
开发者ID:airware,项目名称:buzzard,代码行数:5,代码来源:_footprint.py

示例7: rlength

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def rlength(self):
        """Pixel quantity: pixel count in the outer ring"""
        rx, ry = self.rsize
        # Convert to int before multiplication to avoid overflow
        inner_area = max(0, int(rx) - 2) * max(0, int(ry) - 2)
        return self.rarea - inner_area

    # Accessors - Affine transformations ******************************************************** ** 
开发者ID:airware,项目名称:buzzard,代码行数:10,代码来源:_footprint.py

示例8: scale

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def scale(self):
        """Spatial vector: scale used in the affine transformation, np.abs(scale) == pxsize"""
        aff = ~affine.Affine.rotation(self.angle)
        tl = np.asarray(aff * self.tl)
        br = np.asarray(aff * self.br)
        return np.asarray((br - tl) / self.rsize, dtype=np.float64) 
开发者ID:airware,项目名称:buzzard,代码行数:8,代码来源:_footprint.py

示例9: ResampleRaster

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def ResampleRaster(InputRasterFile,OutputRasterFile,XResolution,YResolution=None,Format="ENVI"):

    """
    Description goes here...

    MDH

    """

    # import modules
    import rasterio, affine
    from rasterio.warp import reproject, Resampling

    # read the source raster
    with rasterio.open(InputRasterFile) as src:
        Array = src.read()
        OldResolution = src.res

        #setup output resolution
        if YResolution == None:
            YResolution = XResolution
        NewResolution = (XResolution,YResolution)


        # setup the transform to change the resolution
        XResRatio = OldResolution[0]/NewResolution[0]
        YResRatio = OldResolution[1]/NewResolution[1]
        NewArray = np.empty(shape=(Array.shape[0], int(round(Array.shape[1] * XResRatio)), int(round(Array.shape[2] * YResRatio))))
        Aff = src.affine
        NewAff = affine.Affine(Aff.a/XResRatio, Aff.b, Aff.c, Aff.d, Aff.e/YResRatio, Aff.f)

        # reproject the raster
        reproject(Array, NewArray, src_transform=Aff, dst_transform=NewAff, src_crs = src.crs, dst_crs = src.crs, resample=Resampling.bilinear)

        # write results to file
        with rasterio.open(OutputRasterFile, 'w', driver=src.driver, \
                            height=NewArray.shape[1],width=NewArray.shape[2], \
                            nodata=src.nodata,dtype=str(NewArray.dtype), \
                            count=src.count,crs=src.crs,transform=NewAff) as dst:
            dst.write(NewArray) 
开发者ID:LSDtopotools,项目名称:LSDMappingTools,代码行数:42,代码来源:rotated_mapping_tools.py

示例10: ConvertRaster2LatLong

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def ConvertRaster2LatLong(InputRasterFile,OutputRasterFile):

    """
    Convert a raster to lat long WGS1984 EPSG:4326 coordinates for global plotting

    MDH

    """

    # import modules
    import rasterio
    from rasterio.warp import reproject, calculate_default_transform as cdt, Resampling

    # read the source raster
    with rasterio.open(InputRasterFile) as src:
        #get input coordinate system
        Input_CRS = src.crs
        # define the output coordinate system
        Output_CRS = {'init': "epsg:4326"}
        # set up the transform
        Affine, Width, Height = cdt(Input_CRS,Output_CRS,src.width,src.height,*src.bounds)
        kwargs = src.meta.copy()
        kwargs.update({
            'crs': Output_CRS,
            'transform': Affine,
            'affine': Affine,
            'width': Width,
            'height': Height
        })

        with rasterio.open(OutputRasterFile, 'w', **kwargs) as dst:
            for i in range(1, src.count+1):
                reproject(
                    source=rasterio.band(src, i),
                    destination=rasterio.band(dst, i),
                    src_transform=src.affine,
                    src_crs=src.crs,
                    dst_transform=Affine,
                    dst_crs=Output_CRS,
                    resampling=Resampling.bilinear) 
开发者ID:LSDtopotools,项目名称:LSDMappingTools,代码行数:42,代码来源:rotated_mapping_tools.py

示例11: __init__

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def __init__(self, affine, shape, mask=None, nodata=None,
                 crs=pyproj.Proj(_pyproj_init),
                 y_coord_ix=0, x_coord_ix=1):
        if affine is not None:
            self.affine = affine
        else:
            self.affine = Affine(0,0,0,0,0,0)
        super().__init__(shape=shape, mask=mask, nodata=nodata, crs=crs,
                         y_coord_ix=y_coord_ix, x_coord_ix=x_coord_ix) 
开发者ID:mdbartos,项目名称:pysheds,代码行数:11,代码来源:view.py

示例12: affine

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def affine(self, new_affine):
        assert(isinstance(new_affine, Affine))
        self._affine = new_affine 
开发者ID:mdbartos,项目名称:pysheds,代码行数:5,代码来源:view.py

示例13: __init__

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def __init__(self, affine=Affine(0,0,0,0,0,0), shape=(1,1), nodata=0,
                 crs=pyproj.Proj(_pyproj_init),
                 mask=None):
        self.affine = affine
        self.shape = shape
        self.nodata = nodata
        self.crs = crs
        # TODO: Mask should be a raster, not an array
        if mask is None:
            self.mask = np.ones(shape)
        self.grids = [] 
开发者ID:mdbartos,项目名称:pysheds,代码行数:13,代码来源:grid.py

示例14: defaults

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def defaults(self):
        props = {
            'affine' : Affine(0,0,0,0,0,0),
            'shape' : (1,1),
            'nodata' : 0,
            'crs' : pyproj.Proj(_pyproj_init),
        }
        return props 
开发者ID:mdbartos,项目名称:pysheds,代码行数:10,代码来源:grid.py

示例15: nearest_cell

# 需要导入模块: import affine [as 别名]
# 或者: from affine import Affine [as 别名]
def nearest_cell(self, x, y, affine=None, snap='corner'):
        """
        Returns the index of the cell (column, row) closest
        to a given geographical coordinate.
 
        Parameters
        ----------
        x : int or float
            x coordinate.
        y : int or float
            y coordinate.
        affine : affine.Affine
                 Affine transformation that defines the translation between
                 geographic x/y coordinate and array row/column coordinate.
                 Defaults to self.affine.
        snap : str
               Indicates the cell indexing method. If "corner", will resolve to 
               snapping the (x,y) geometry to the index of the nearest top-left 
               cell corner. If "center", will return the index of the cell that 
               the geometry falls within.
        Returns
        -------
        x_i, y_i : tuple of ints
                   Column index and row index
        """
        if not affine:
            affine = self.affine
        try:
            assert isinstance(affine, Affine)
        except:
            raise TypeError('affine must be an Affine instance.')
        snap_dict = {'corner': np.around, 'center': np.floor}
        col, row = snap_dict[snap](~affine * (x, y)).astype(int)
        return col, row 
开发者ID:mdbartos,项目名称:pysheds,代码行数:36,代码来源:grid.py


注:本文中的affine.Affine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。