== Write support for the PostGIS Raster driver == '''Introduction''' A GDAL driver allows reading/writing of raster(or images) data from/to formats like TIFF, PNG or JPEG. The current GDAL PostGIS Raster driver supports reading of PostGIS rasters objects from a PostgreSQL/PostGIS database but does not support writing. This project includes designing and implementing a driver for write support. Currently PostGIS raster2pgsql loader is used to load GDAL supported raster formats in the database. '''Background''' PostGIS Raster is the project that provides raster support on PostGIS. Most GDAL drivers are based in the concept of block. In tiled datasets, 1 block = 1 tile and all tiles have the same dimensions (width and height). But in the GDAL PostGIS Raster, each tile of a coverage can have different dimensions, different pixel size etc. In order to handle such kinds of tiles, the GDAL PostGIS Raster uses the VRT driver as proxy since it works in the same manner. Important methods used for writing in database are IWriteBlock and IRasterIO. The PostGIS Raster driver works with IRasterIO since the driver needs to handle unequally sized blocks. '''The idea''' * Modify the I/O of the driver to respond to the input arguments: The PostGIS raster2pgsql loader takes multiple arguments depending on the users requirements. Similarly the GDAL PostGIS Raster driver needs to respond appropriately to the input arguments. In case some specific options need to be passed, layer creation options and configuration options are to be used from ogr2ogr. * Implement methods for writing the sql query in buffer: The key functions from the PostGIS raster2pgsql loader that need to be implemented/duplicated are: a) process_rasters b) convert_raster c) create_table d) drop_table e) insert_record f) create_index g) analyze_table h) append_sql_to_buffer More functions will be needed to implement later but these are the key ones I figured out for now. * Implement methods to write the query in the database: The input data is read into the memory buffer, which is then passed as an argument to PostGISRasterRasterBand::IRasterIO method. Using the above implemented functions transform the buffer data into SQL code. Modify this IRasterIO method which executes the SQL code to write the data into a region of PostGISRasterRasterBand(in the PostgreSQL db). IRasterIO method is used to handle such unequally sized blocks of data with different dimensions, geo-referencing, pixel size etc. * Testing: The driver needs to be robust and respond to all the arguments passed to it appropriately. I would test all the possible use cases of the driver on similar lines with the raster2pgsql loader. The testing would be done using the GDAL autotest suite. All tests are to be automated and added to the suite. '''Project plan''' I will have about 12 weeks to complete the project. Here is a tentative schedule: * Before 19th May: Refine project plan. Get familiar with the development environment of GDAL and PostGIS. * Week 1-2: Understanding and familiarizing with the I/O system in GDAL. * Week 3-5: Compose the sql query in the buffer. Write methods to prepare the sql query. * Week 6: Mid-term evaluations. Solve bugs that may come up during the evaluation. * Week 7: Implement methods to load the raster files in the buffer * Week 8-9: Modify the IRasterIO and more methods to write data from the buffer to the PostgreSQL database. * Week 10: Buffer time. Clean up the code wherever required. * Week 11-12: Testing and bug fixing. Draft final report and documentation. '''Future ideas / How can your idea be expanded?''' The QGIS DBManager plugin will be required to be tested with the new driver with write support. After the completion of this project we will have GDAL + PostGIS Raster with read as well as write support. This will be a powerful tool for third parties that rely on PostGIS for their data and use GDAL as main tool to handle it. They will be able to just use GDAL to read/write data in PostGIS Raster, without using the loader. I have also contacted with the PostGIS users/dev lists, to ask them for future uses and possible features that might be needed. '''Project Progress''' Github: https://github.com/varunsaraf/postgis_raster Blog: https://github.com/varunsaraf/postgis_raster/wiki/GSoC-2014 GDAL Commits: