如何在GDAL ruby​​绑定中显式关闭数据集?

我使用ruby1.9中的GDAL 1.7.1来生成GeoTIFF文件。 在教程中,他们建议使用GDALClose()关闭数据集并将剩余的内容刷新到文件系统。 在数据集的析构函数中也是如此。 问题是ruby绑定依赖于这个析构函数机制来关闭数据集,我需要已经在生成它的进程中的文件结果。 由于ruby是垃圾收集的,似乎我不能可靠地关闭我的文件,而不退出ruby进程。 现在我修补了我的GDAL版本以支持GDALClose方法,但这似乎不是一个好的长期解决方案。

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" ) [...] 

有没有东西用ruby或swig强制析构函数调用,我可能忽略了?

通常,在Python中使用GDAL绑定所做的是将对象设置为None 。 所以在Ruby中,这将是nil

 band = nil target_map = nil 

保存/刷新/关闭数据是一种有趣的方式,但它是如何完成的。

Interesting Posts