本文整理汇总了Python中nansat.vrt.VRT.from_dataset_params方法的典型用法代码示例。如果您正苦于以下问题:Python VRT.from_dataset_params方法的具体用法?Python VRT.from_dataset_params怎么用?Python VRT.from_dataset_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nansat.vrt.VRT
的用法示例。
在下文中一共展示了VRT.from_dataset_params方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_dataset_params [as 别名]
def __init__(self, srs=None, ext=None, ds=None, **kwargs):
"""Create Domain from GDALDataset or string options or lat/lon grids"""
# If too much information is given raise error
if ds is not None and srs is not None and ext is not None:
raise ValueError('Ambiguous specification of both dataset, srs- and ext-strings.')
# choose between input opitons:
# ds
# ds and srs
# srs and ext
# if only a dataset is given:
# copy geo-reference from the dataset
if ds is not None and srs is None:
self.vrt = VRT.from_gdal_dataset(ds)
# If dataset and srs are given (but not ext):
# use AutoCreateWarpedVRT to determine bounds and resolution
elif ds is not None and srs is not None:
srs = NSR(srs)
tmp_vrt = gdal.AutoCreateWarpedVRT(ds, None, srs.wkt)
if tmp_vrt is None:
raise NansatProjectionError('Could not warp the given dataset to the given SRS.')
else:
self.vrt = VRT.from_gdal_dataset(tmp_vrt)
# If SpatialRef and extent string are given (but not dataset)
elif srs is not None and ext is not None:
srs = NSR(srs)
# create full dictionary of parameters
extent_dict = Domain._create_extent_dict(ext)
# convert -lle to -te
if 'lle' in extent_dict.keys():
extent_dict = self._convert_extentDic(srs, extent_dict)
# get size/extent from the created extent dictionary
geo_transform, raster_x_size, raster_y_size = self._get_geotransform(extent_dict)
# create VRT object with given geo-reference parameters
self.vrt = VRT.from_dataset_params(x_size=raster_x_size, y_size=raster_y_size,
geo_transform=geo_transform,
projection=srs.wkt,
gcps=[], gcp_projection='')
elif 'lat' in kwargs and 'lon' in kwargs:
warnings.warn('Domain(lon=lon, lat=lat) will be deprectaed!'
'Use Domain.from_lonlat()', NansatFutureWarning)
# create self.vrt from given lat/lon
self.vrt = VRT.from_lonlat(kwargs['lon'], kwargs['lat'])
else:
raise ValueError('"dataset" or "srsString and extentString" '
'or "dataset and srsString" are required')
示例2: test_from_dataset_params
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_dataset_params [as 别名]
def test_from_dataset_params(self):
ds = gdal.Open(self.test_file_gcps)
vrt = VRT.from_dataset_params(ds.RasterXSize,
ds.RasterYSize,
ds.GetGeoTransform(),
ds.GetProjection(),
ds.GetGCPs(),
ds.GetGCPProjection())
self.assertEqual(vrt.dataset.RasterXSize, ds.RasterXSize)
self.assertEqual(vrt.dataset.RasterYSize, ds.RasterYSize)
self.assertEqual(vrt.dataset.GetProjection(), ds.GetProjection())
self.assertEqual(vrt.dataset.GetGeoTransform(), ds.GetGeoTransform())
self.assertEqual(vrt.dataset.GetGCPProjection(), ds.GetGCPProjection())
self.assertIn('filename', list(vrt.dataset.GetMetadata().keys()))