Python gdal.GRA_Bilinear() Examples
The following are 3
code examples of gdal.GRA_Bilinear().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gdal
, or try the search function
.
Example #1
Source File: modis_tg_halli.py From hydrology with GNU General Public License v3.0 | 5 votes |
def reproject_dataset(dataset, output_file_name, wkt_from="+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs", epsg_to=32643, pixel_spacing=1000, file_format='GTiff'): ''' :param dataset: Modis subset name use gdal.GetSubdatasets() :param output_file_name: file location along with proper extension :param wkt_from: Modis wkt (default) :param epsg_to: integer default(32643) :param pixel_spacing: in metres :param file_format: default GTiff :return: ''' wgs84 = osr.SpatialReference() wgs84.ImportFromEPSG(epsg_to) modis = osr.SpatialReference() modis.ImportFromProj4(wkt_from) tx = osr.CoordinateTransformation(modis, wgs84) g = gdal.Open(dataset) geo_t = g.GetGeoTransform() print geo_t x_size = g.RasterXSize y_size = g.RasterYSize (ulx, uly, ulz) = tx.TransformPoint(geo_t[0], geo_t[3]) (lrx, lry, lrz) = tx.TransformPoint(geo_t[0] + (geo_t[1]*x_size), geo_t[3]+ (geo_t[5]*y_size)) mem_drv = gdal.GetDriverByName(file_format) dest = mem_drv.Create(output_file_name, int((lrx-ulx)/pixel_spacing), int((uly - lry)/pixel_spacing), 1, gdal.GDT_Float32) new_geo = ([ulx, pixel_spacing, geo_t[2], uly, geo_t[4], -pixel_spacing]) dest.SetGeoTransform(new_geo) dest.SetProjection(wgs84.ExportToWkt()) gdal.ReprojectImage(g, dest, modis.ExportToWkt(), wgs84.ExportToWkt(), gdal.GRA_Bilinear) print "reprojected"
Example #2
Source File: functions.py From hants with Apache License 2.0 | 4 votes |
def Raster_to_Array(input_tiff, ll_corner, x_ncells, y_ncells, values_type='float32'): """ Loads a raster into a numpy array """ # Input inp_lyr = gdal.Open(input_tiff) inp_srs = inp_lyr.GetProjection() inp_transform = inp_lyr.GetGeoTransform() inp_band = inp_lyr.GetRasterBand(1) inp_data_type = inp_band.DataType cellsize_x = inp_transform[1] rot_1 = inp_transform[2] rot_2 = inp_transform[4] cellsize_y = inp_transform[5] NoData_value = inp_band.GetNoDataValue() ll_x = ll_corner[0] ll_y = ll_corner[1] top_left_x = ll_x top_left_y = ll_y - cellsize_y*y_ncells # Change start point temp_path = tempfile.mkdtemp() temp_driver = gdal.GetDriverByName('GTiff') temp_tiff = os.path.join(temp_path, os.path.basename(input_tiff)) temp_source = temp_driver.Create(temp_tiff, x_ncells, y_ncells, 1, inp_data_type) temp_source.GetRasterBand(1).SetNoDataValue(NoData_value) temp_source.SetGeoTransform((top_left_x, cellsize_x, rot_1, top_left_y, rot_2, cellsize_y)) temp_source.SetProjection(inp_srs) # Snap gdal.ReprojectImage(inp_lyr, temp_source, inp_srs, inp_srs, gdal.GRA_Bilinear) temp_source = None # Read array d_type = pd.np.dtype(values_type) out_lyr = gdal.Open(temp_tiff) array = out_lyr.ReadAsArray(0, 0, out_lyr.RasterXSize, out_lyr.RasterYSize).astype(d_type) array[pd.np.isclose(array, NoData_value)] = pd.np.nan out_lyr = None return array
Example #3
Source File: functions.py From wa with Apache License 2.0 | 4 votes |
def Raster_to_Array(input_tiff, ll_corner, x_ncells, y_ncells, values_type='float32'): """ Loads a raster into a numpy array """ # Input inp_lyr = gdal.Open(input_tiff) inp_srs = inp_lyr.GetProjection() inp_transform = inp_lyr.GetGeoTransform() inp_band = inp_lyr.GetRasterBand(1) inp_data_type = inp_band.DataType cellsize_x = inp_transform[1] rot_1 = inp_transform[2] rot_2 = inp_transform[4] cellsize_y = inp_transform[5] NoData_value = inp_band.GetNoDataValue() ll_x = ll_corner[0] ll_y = ll_corner[1] top_left_x = ll_x top_left_y = ll_y - cellsize_y*y_ncells # Change start point temp_path = tempfile.mkdtemp() temp_driver = gdal.GetDriverByName('GTiff') temp_tiff = os.path.join(temp_path, os.path.basename(input_tiff)) temp_source = temp_driver.Create(temp_tiff, x_ncells, y_ncells, 1, inp_data_type) temp_source.GetRasterBand(1).SetNoDataValue(NoData_value) temp_source.SetGeoTransform((top_left_x, cellsize_x, rot_1, top_left_y, rot_2, cellsize_y)) temp_source.SetProjection(inp_srs) # Snap gdal.ReprojectImage(inp_lyr, temp_source, inp_srs, inp_srs, gdal.GRA_Bilinear) temp_source = None # Read array d_type = pd.np.dtype(values_type) out_lyr = gdal.Open(temp_tiff) array = out_lyr.ReadAsArray(0, 0, out_lyr.RasterXSize, out_lyr.RasterYSize).astype(d_type) array[pd.np.isclose(array, NoData_value)] = pd.np.nan out_lyr = None return array