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


Python Affine.from_gdal方法代码示例

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


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

示例1: list_to_affine

# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import from_gdal [as 别名]
def list_to_affine(xform_mat):
    """Create an Affine from a list or array-formatted [a, b, d, e, xoff, yoff]

    Arguments
    ---------
    xform_mat : `list` or :class:`numpy.array`
        A `list` of values to convert to an affine object.

    Returns
    -------
    aff : :class:`affine.Affine`
        An affine transformation object.
    """
    # first make sure it's not in gdal order
    if len(xform_mat) > 6:
        xform_mat = xform_mat[0:6]
    if rasterio.transform.tastes_like_gdal(xform_mat):
        return Affine.from_gdal(*xform_mat)
    else:
        return Affine(*xform_mat) 
开发者ID:CosmiQ,项目名称:solaris,代码行数:22,代码来源:geo.py

示例2: get_geo_transform

# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import from_gdal [as 别名]
def get_geo_transform(raster_src):
    """Get the geotransform for a raster image source.

    Arguments
    ---------
    raster_src : str, :class:`rasterio.DatasetReader`, or `osgeo.gdal.Dataset`
        Path to a raster image with georeferencing data to apply to `geom`.
        Alternatively, an opened :class:`rasterio.Band` object or
        :class:`osgeo.gdal.Dataset` object can be provided. Required if not
        using `affine_obj`.

    Returns
    -------
    transform : :class:`affine.Affine`
        An affine transformation object to the image's location in its CRS.
    """

    if isinstance(raster_src, str):
        affine_obj = rasterio.open(raster_src).transform
    elif isinstance(raster_src, rasterio.DatasetReader):
        affine_obj = raster_src.transform
    elif isinstance(raster_src, gdal.Dataset):
        affine_obj = Affine.from_gdal(*raster_src.GetGeoTransform())

    return affine_obj 
开发者ID:CosmiQ,项目名称:solaris,代码行数:27,代码来源:image.py

示例3: clip

# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import from_gdal [as 别名]
def clip(self, shp, keep=False, *args, **kwargs):
        '''
        Clip raster using shape, where shape is either a GeoPandas DataFrame, shapefile,
        or some other geometry format used by python-raster-stats

        Returns list of GeoRasters or Pandas DataFrame with GeoRasters and additional information

        Usage:

        clipped = geo.clip(shape, keep=False)

        where:
        keep: Boolean (Default False), returns Georasters and Geometry information
        '''
        df = pd.DataFrame(zonal_stats(shp, self.raster, nodata=self.nodata_value, all_touched=True,
                                      raster_out=True, affine=Affine.from_gdal(*self.geot),
                                      geojson_out=keep,))
        if keep:
            df['GeoRaster'] = df.properties.apply(lambda x: GeoRaster(x['mini_raster_array'],
                                                                      Affine.to_gdal(x['mini_raster_affine']),
                                                                      nodata_value=x['mini_raster_nodata'],
                                                                      projection=self.projection,
                                                                      datatype=self.datatype))
            cols = list(set([i for i in df.properties[0].keys()]).intersection(set(shp.columns)))
            df2 = pd.DataFrame([df.properties.apply(lambda x: x[i]) for i in cols
                                ]).T.merge(df[['GeoRaster']], left_index=True, right_index=True,)
            df2.columns = cols+['GeoRaster']
            df2 = df2.merge(df[['id']], left_index=True, right_index=True)
            df2.set_index('id', inplace=True)
            return df2
        else:
            df['GeoRaster'] = df.apply(lambda x: GeoRaster(x.mini_raster_array,
                                                           Affine.to_gdal(x.mini_raster_affine),
                                                           nodata_value=x.mini_raster_nodata,
                                                           projection=self.projection,
                                                           datatype=self.datatype), axis=1)
            return df['GeoRaster'].values 
开发者ID:ozak,项目名称:georasters,代码行数:39,代码来源:georasters.py

示例4: stats

# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import from_gdal [as 别名]
def stats(self, shp, stats='mean', add_stats=None, raster_out=True, *args, **kwargs):
        '''
        Compute raster statistics for a given geometry in shape, where shape is either
        a GeoPandas DataFrame, shapefile, or some other geometry format used by
        python-raster-stats. Runs python-raster-stats in background
        (additional help and info can be found there)

        Returns dataframe with statistics and clipped raster

        Usage:

        df = geo.stats(shape, stats=stats, add_stats=add_stats)

        where:
        raster_out: If True (Default), returns clipped Georasters
        '''
        df = pd.DataFrame(zonal_stats(shp, self.raster, nodata=self.nodata_value,
                                      all_touched=True, raster_out=raster_out,
                                      affine=Affine.from_gdal(*self.geot),
                                      geojson_out=True, stats=stats, add_stats=add_stats))
        df['GeoRaster'] = df.properties.apply(lambda x: GeoRaster(x['mini_raster_array'],
                                                                  Affine.to_gdal(x['mini_raster_affine']),
                                                                  nodata_value=x['mini_raster_nodata'],
                                                                  projection=self.projection,
                                                                  datatype=self.datatype))
        statcols = list(set([i for i in df.properties[0].keys()]).difference(set(shp.columns)))
        cols = shp.columns.tolist()+statcols
        cols = [i for i in cols if i != 'geometry' and i.find('mini_raster') == -1]
        df2 = pd.DataFrame([df.properties.apply(lambda x: x[i]) for i in cols]).T
        df2.columns = cols
        df2 = df2.merge(df[['id', 'GeoRaster']], left_index=True, right_index=True)
        df2.set_index('id', inplace=True)
        return df2 
开发者ID:ozak,项目名称:georasters,代码行数:35,代码来源:georasters.py

示例5: from_georef

# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import from_gdal [as 别名]
def from_georef(cls, georef):
        tfm = Affine.from_gdal(georef["translateX"], georef["scaleX"], georef["shearX"],
                               georef["translateY"], georef["shearY"], georef["scaleY"])
        return cls(tfm, proj=georef["spatialReferenceSystemCode"]) 
开发者ID:DigitalGlobe,项目名称:gbdxtools,代码行数:6,代码来源:util.py

示例6: get_affine

# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import from_gdal [as 别名]
def get_affine(src):
    aff = None
    # See https://github.com/mapbox/rasterio/issues/86
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        aff = src.transform
    if isinstance(aff,list):
        aff = Affine.from_gdal(*aff)
    return aff 
开发者ID:igp-gravity,项目名称:geoist,代码行数:11,代码来源:gdal.py

示例7: test_reproject

# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import from_gdal [as 别名]
def test_reproject():
    from rasterio.warp import reproject
    from rasterio.enums import Resampling

    with rasterio.Env():
        # As source: a 1024 x 1024 raster centered on 0 degrees E and 0
        # degrees N, each pixel covering 15".
        rows, cols = src_shape = (1024, 1024)
        # decimal degrees per pixel
        d = 1.0 / 240

        # The following is equivalent to
        # A(d, 0, -cols*d/2, 0, -d, rows*d/2).
        src_transform = rasterio.Affine.translation(
                    -cols*d/2,
                    rows*d/2) * rasterio.Affine.scale(d, -d)
        src_crs = {'init': 'EPSG:4326'}
        source = np.ones(src_shape, np.uint8) * 255

        # Destination: a 2048 x 2048 dataset in Web Mercator (EPSG:3857)
        # with origin at 0.0, 0.0.
        dst_shape = (2048, 2048)
        dst_transform = Affine.from_gdal(
            -237481.5, 425.0, 0.0, 237536.4, 0.0, -425.0)
        dst_crs = {'init': 'EPSG:3857'}
        destination = np.zeros(dst_shape, np.uint8)

        reproject(
            source,
            destination,
            src_transform=src_transform,
            src_crs=src_crs,
            dst_transform=dst_transform,
            dst_crs=dst_crs,
            resampling=Resampling.nearest)

        # Assert that the destination is only partly filled.
        assert destination.any()
        assert not destination.all()


# Testing upsample function 
开发者ID:mapbox,项目名称:rio-pansharpen,代码行数:44,代码来源:test_pansharp_unittest.py


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