當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。