Dingyuan-Chen / shp2coco

a tool to convert .shp file (ArcGIS format) to .json file (COCO datasets).
55 stars 12 forks source link

Write operation not permitted on dataset opened in read-only mode #5

Open sunnythree opened 3 years ago

sunnythree commented 3 years ago

Traceback (most recent call last): File "D:\work\myai\shp2coco\tif_process.py", line 154, in clip_mask_with_grid self.dataset, jclip_size, iclip_size, save_path) File "D:\work\myai\shp2coco\tif_process.py", line 315, in save_image_with_georef ds.GetRasterBand(1).WriteArray(clip) File "C:\Users\CHINA\Anaconda3\envs\msai\lib\site-packages\osgeo\gdal.py", line 2834, in WriteArray callback_data=callback_data) File "C:\Users\CHINA\Anaconda3\envs\msai\lib\site-packages\osgeo\gdal_array.py", line 430, in BandWriteArray _RaiseException() File "C:\Users\CHINA\Anaconda3\envs\msai\lib\site-packages\osgeo\gdal_array.py", line 235, in _RaiseException raise RuntimeError(gdal.GetLastErrorMsg()) RuntimeError: Write operation not permitted on dataset opened in read-only mode

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:/work/myai/shp2coco/shape_to_coco.py", line 137, in main() File "D:/work/myai/shp2coco/shape_to_coco.py", line 130, in main clip_from_file(clip_size, ROOT, img_path, shp_path) File "D:\work\myai\shp2coco\tif_process.py", line 383, in clip_from_file pic_num = tif.clip_tif_and_shapefile(clip_size, pic_id, root + '/' + shp_path + '/' + img_id + '/' + img_id + '.shp', root + '/dataset') File "D:\work\myai\shp2coco\tif_process.py", line 262, in clip_tif_and_shapefile self.clip_mask_with_grid(clip_size=clip_size, begin_id=begin_id, out_dir=out_dir + '/annotations') File "D:\work\myai\shp2coco\tif_process.py", line 158, in clip_mask_with_grid raise IOError('clip failed!%d' % count) OSError: clip failed!1

Process finished with exit code 1

sunnythree commented 3 years ago

use: ds = driver.CreateCopy(save_path, ds, gdal.GF_Write) replace : driver.CreateCopy(save_path, ds) fix this problem