我從ruby1.9使用GDAL 1.7.1生成GeoTIFF文件。在tutorial中,他們建議使用GDALClose()來關閉數據集並將剩餘內容清除到文件系統。在數據集的析構函數中也是如此。問題在於ruby綁定依賴於這個析構函數來關閉數據集,並且我需要生成該文件的進程中已有文件的結果。由於紅寶石是垃圾收集,似乎我不能可靠地關閉我的文件,而不退出紅寶石進程。現在我修補了我的GDAL版本來支持GDALClose方法,但這似乎不是一個好的長期解決方案。如何在GDAL ruby綁定中顯式關閉數據集?
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中是否有強制析構函數調用的東西,我可能忽略了?
顯示代碼的一個小示例,演示該問題。你要求我們想象你寫的內容,我們沒有辦法做到這一點。 –