How to use the pyresample.utils.proj4_str_to_dict function in pyresample

To help you get started, we’ve selected a few pyresample examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytroll / pyresample / pyresample / utils / rasterio.py View on Github external
# b: row rotation (typically zero)
    # c: x-coordinate of the upper-left corner of the upper-left pixel
    # d: column rotation (typically zero)
    # e: height of a pixel (typically negative)
    # f: y-coordinate of the of the upper-left corner of the upper-left pixel
    c, a, b, f, d, e = dataset.GetGeoTransform()
    if not (b == d == 0):
        raise ValueError('Rotated rasters are not supported at this time.')
    area_extent = (c, f + e * dataset.RasterYSize, c + a * dataset.RasterXSize, f)

    if proj_dict is None:
        from osgeo import osr
        proj = dataset.GetProjection()
        if proj != '':
            sref = osr.SpatialReference(wkt=proj)
            proj_dict = proj4_str_to_dict(sref.ExportToProj4())
        else:
            raise ValueError('The source raster is not gereferenced, please provide the value of proj_dict')

        if proj_id is None:
            proj_id = proj.split('"')[1]

    area_def = AreaDefinition(area_id, name, proj_id, proj_dict,
                              dataset.RasterXSize, dataset.RasterYSize, area_extent)
    return area_def
github noaa-oar-arl / MONET / monet / models / basemodel.py View on Github external
def get_ioapi_pyresample_area_def(ds, proj4_srs):
    from pyresample import geometry, utils
    y_size = ds.NROWS
    x_size = ds.NCOLS
    projection = utils.proj4_str_to_dict(proj4_srs)
    proj_id = 'dataset'
    description = 'IOAPI area_def for pyresample'
    area_id = 'Unknown'
    x_ll, y_ll = x_ll, y_ll = ds.XORIG, ds.YORIG
    x_ur, y_ur = ds.XORIG + (ds.NCOLS * ds.XCELL) + ds.XCELL, ds.YORIG + (
        ds.YCELL * ds.NROWS) + ds.YCELL
    area_extent = (x_ll, y_ll, x_ur, y_ur)
    area_def = geometry.AreaDefinition(area_id, description, proj_id,
                                       projection, x_size, y_size, area_extent)
    return area_def
github pytroll / pyresample / pyresample / area_config.py View on Github external
def _get_proj4_args(proj4_args):
    """Create dict from proj4 args."""
    from pyresample.utils.proj4 import convert_proj_floats
    if isinstance(proj4_args, str):
        # float conversion is done in `proj4_str_to_dict` already
        return proj4_str_to_dict(str(proj4_args))

    from configobj import ConfigObj
    proj_config = ConfigObj(proj4_args)
    return convert_proj_floats(proj_config.items())
github pytroll / satpy / satpy / writers / scmi.py View on Github external
draw.text((x - t_size[0] / 2., y - t_size[1] / 2.), t, fill=255, font=font)

    img.save("test.png")

    from pyresample.utils import proj4_str_to_dict
    new_extents = (
        ll_extent[0],
        ur_extent[1] - 1001. * meters_ppy,
        ll_extent[0] + 1001. * meters_ppx,
        ur_extent[1],
    )
    grid_def = AreaDefinition(
        'debug_grid',
        'debug_grid',
        'debug_grid',
        proj4_str_to_dict(sector_info['projection']),
        1000,
        1000,
        new_extents
    )
    return grid_def, np.array(img)
github noaa-oar-arl / MONET / monet / grids.py View on Github external
proj4_srs : type
        Description of parameter `proj4_srs`.

    Returns
    -------
    type
        Description of returned object.

    """
    try:
        from pyresample.utils import proj4_str_to_dict
        from pyresample.geometry import SwathDefinition
    except ImportError:
        print('please install pyresample to use this functionality')
    swath = SwathDefinition(lats=lat, lons=lon)
    area = swath.compute_optimal_bb_area(proj4_str_to_dict(proj4_srs))
    return area
github pytroll / satpy / satpy / readers / geocat.py View on Github external
platform = self.get_platform(self['/attr/Platform_Name'])
        res = self._calc_area_resolution(dsid.resolution)
        proj = self._get_proj(platform, float(self['/attr/Subsatellite_Longitude']))
        area_name = '{} {} Area at {}m'.format(
            platform,
            self.metadata.get('sector_id', ''),
            int(res))
        lon = self._load_nav('pixel_longitude')
        lat = self._load_nav('pixel_latitude')
        extents = self._get_extents(proj, res, lon, lat)
        area_def = geometry.AreaDefinition(
            area_name,
            area_name,
            area_name,
            proj_dict=proj4_str_to_dict(proj),
            x_size=lon.shape[1],
            y_size=lon.shape[0],
            area_extent=extents,
        )
        return area_def
github pytroll / pyresample / pyresample / geometry.py View on Github external
if lons is not None:
            if lons.shape != self.shape:
                raise ValueError('Shape of lon lat grid must match '
                                 'area definition')
        self.size = height * width
        self.ndim = 2
        self.pixel_size_x = (area_extent[2] - area_extent[0]) / float(width)
        self.pixel_size_y = (area_extent[3] - area_extent[1]) / float(height)
        self.area_extent = tuple(area_extent)
        if CRS is not None:
            self.crs_wkt = CRS(projection).to_wkt()
            self._proj_dict = None
            self.crs = self._crs  # see _crs property for details
        else:
            if isinstance(projection, str):
                proj_dict = proj4_str_to_dict(projection)
            elif isinstance(projection, dict):
                # use the float-converted dict to pass to Proj
                projection = convert_proj_floats(projection.items())
                proj_dict = projection
            else:
                raise TypeError('Wrong type for projection: {0}. Expected dict or string.'.format(type(projection)))
            self._proj_dict = proj_dict

        # Calculate area_extent in lon lat
        proj = Proj(projection)
        corner_lons, corner_lats = proj((area_extent[0], area_extent[2]),
                                        (area_extent[1], area_extent[3]),
                                        inverse=True)
        self.area_extent_ll = (corner_lons[0], corner_lats[0],
                               corner_lons[1], corner_lats[1])