How to explicitly close datasets in GDAL ruby ​​binding?

I am using GDAL 1.7.1 from ruby1.9 to generate GeoTIFF files. In the tutorial, they recommend using GDALClose () to close the datasets and dump the remaining content into the file system. The same thing happens in the destructor for the dataset. The problem is that ruby ​​bindings rely on this destructor mechanism to close the data set, and I need the result of the file already in the process of generating it. Since ruby ​​is garbage collection, it seems that I cannot reliably close my files without leaving the ruby ​​process. At the moment, I fixed my version of GDAL to support the GDALClose method, but this does not seem to be a good long-term solution.

require 'gdal/gdal' [...] # open the driver for geotiff format driver = Gdal::Gdal.get_driver_by_name('GTiff') # create a new file target_map = driver.create(output_path, xsize, ysize, 3, Gdal::Gdalconst::GDT_UINT16, ["PHOTOMETRIC=RGB"]) # write band data 3.times do |i| band = target_map.band(i + 1) target_map.write_band(i + 1, mapped_data) end # now I would like to use the file in output_path, but at this point # large parts of the data still resides in memory it seems until # target_map is destroyed file = File.open( output_path, "r" ) [...] 

Is there anything in ruby ​​or swig to trigger a call to the destructor that I might have missed?

+4
source share
1 answer

Usually what is done with GDAL bindings in Python is setting objects to None . So in Ruby this will be nil :

 band = nil target_map = nil 

This is a fun way to save / close / close data, but it does.

+1
source

Source: https://habr.com/ru/post/1447688/


All Articles