Changes between Version 32 and Version 33 of WKTRasterDriver


Ignore:
Timestamp:
Jul 12, 2009, 4:53:16 PM (15 years ago)
Author:
jorgearevalo
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WKTRasterDriver

    v32 v33  
    44
    55
    6 ********** UPDATED ON 2009/07/08 ***********
     6********** UPDATED ON 2009/07/12 ***********
    77
    88
     
    1515[http://www.gis4free.org/blog/2009/06/20/gsoc-09-weekly-report-4-1206-1906/ Weekly report #4 (12/06 - 19/06)][[BR]]
    1616[http://www.gis4free.org/blog/2009/06/27/gsoc-09-weekly-report-5-1906-2606/ Weekly report #5 (19/06 - 26/06)][[BR]]
    17 [http://www.gis4free.org/blog/2009/07/04/gsoc-09-weekly-report-6-2606-0307/ Weekly report #6 (26/06 - 03/07)]
     17[http://www.gis4free.org/blog/2009/07/04/gsoc-09-weekly-report-6-2606-0307/ Weekly report #6 (26/06 - 03/07)][[BR]]
     18[http://www.gis4free.org/blog/2009/07/13/gsoc-09-weekly-report-7-0307-1007/ Weekly report #7 (03/07 - 10/07)]
    1819
    1920== General overview ==
     
    3839  a. A regularly tiled raster coverage.
    3940  a. A rectangular regularly tiled raster coverage.
    40   a. A tiled image.
     41  a. A tiled image. --> NOT CONSIDERED FROM NOW. ONLY 1-TABLE-RASTERS
    4142  a. A raster object coverage resulting from the rasterization of a vector coverage.
    4243
    43 Options c, d and e should have the easier ones to be read by the GDAL driver. They are raster with "regular blocking" structure. When a raster layer of these types is loaded:
     44Options c and d should have the easier ones to be read by the GDAL driver. They are raster with "regular blocking" structure. When a raster layer of these types is loaded:
    4445  1. All loaded tiles have the same width and height,
    4546  1. All tiles do not overlap and their upper left corners follow a regular block grid,
    4647  1. The global extent of the layer is rectangular and not rotated.
    4748
    48 Then, for the basic version of the GDAL WKT Raster driver, we can focus on these tasks (reading raster of types c, d and e). Anyway, in the project plan, all the mandatory and optional tasks are listed.
     49Then, for the basic version of the GDAL WKT Raster driver, we can focus on these tasks (reading raster of types c and d). For this reason, we specify several working modes for it. They aren't totally defined yet, but, at least, we should use:
     50- REGULARLY_BLOCKING mode: In this mode, our raster is regularly tiled. So, it fulfills the three previous properties.
     51- NON_REGULARLY_BLOCKING mode: In this mode, our raster is non-regularly tiled. The tiles can have different size and may overlap, so, the global extent of the raster isn't necessarily rectangular.
     52
     53Maybe we'll need more working modes in the future, for non-tiled rasters.
    4954
    5055== Implementing the Dataset ==
    5156
    52 UPDATE: We'll focus in the WKT Raster objects with only one table per coverage. Then, one GDAL Dataset will be created based on a set of tiles reading from one (and only one) table with a WKT Raster column. So, concept explained in the next paragraph is frozen, at least just now...
     57NOTE: ONLY REGULAR-BLOCKING RASTERS, FROM NOW
    5358
    54 *********
    55 One GDAL Dataset will be created based on a set of tiles reading from one or more tables with a WKT Raster column. Yes, we may need to read from more than one table: in the case of tiled images. In this type of images, a single table ''does not represent a complete coverage; other images forming the rest of the coverage are stored as other tables of tiled images. This structure is not very practical from a GIS analytical point of view since any operations applied to the coverage must also be applied to every table.''
    56 *********
     59The Dataset performs the following operations:
    5760
    58 
    59 There are three important methods that must be implemented in the Dataset class:
    60   * Open: a static method that establishes a connection with PostgreSQL and try to access the table given as argument. Several security checkings must be performed here: if the database has PostGIS support, if the table (or tables) exists, if has a field of raster type, if has a GIST index, etc. (Any more?). Additionally, this method will create the RasterBand objects, needed for fetching the raster bands' data, and create a pointer to the real data.
    61   * GetGeoTransform: Fetches the coefficients for transforming between pixel/line (P,L) raster space and projection coordinates (Xp, Yp) space.
    62   * GetProjectionRef: Fetches the projection coordinate system definition in OpenGIS WKT format. It should be suitable for use with the OGRSpatialReference class.
    63 
    64 This is for Dataset based on regular blocking arrangements. If we have non-regular blocking arrangements, things turn more complicated. And how do we know if the table can be considered as a raster coverage with regular blocking arrangement? By querying the '''raster_columns''' table.
    65 
    66 This table is a key concept in the WKT Raster world. ''Like the PostGIS "geometry_column" table, the PostGIS WKT Raster "raster_columns" table is a way for applications to get a quick overview of which tables have a raster column, and to get the main characteristics (metadata) of the rasters stored in these columns.''
    67 
    68 One of this table's fields is a boolean field called 'regular_blocking'. ''If it is set to 'true' then you treat all the rows as normal tiles and create a single GDALDataset. If it is set to 'false' then you should print an error message warning to check for the "MODE" option. This MODE option could work like this:''
    69 
    70 ''-MODE=WHOLE_TABLE, in this case you first query the full extent covered by all the raster contained in the table, create a 'black' image following this extent with nodata values and then 'print' every images in the big raster. This is very similar as if the regular_blocking flag is set but you will have to deal with true georeferences and possible overlaps. This should be very similar to what the gdal_merge.py tool does.''
    71 
    72 ''-MODE=FIRST_ROW, in this case you treat only the first row returned by a SQL query. This could be very similar to the 'where' parameter of the GEORASTER GDAL driver.''
    73 
    74 ''-MODE=ONE_FILE_PER_ROW, in this case you would read each row as an independent image. I'm not sure though that GDAL allows you to do this. For sure a good WKT exporter/dumper would allow this. The result would be one filesystem raster file per row.''. UPDATE: Subdatasets (http://www.gdal.org/gdal_datamodel.html, SUBDATASETS Domain) could be useful here. Can datasets based on a single row treated as tiles (blocks), this is, loaded in RAM, the whole image? Maybe is better to provide finer grained access to this datasets, but it will mean extra work.
    75 
    76 **** QUESTION: There is one type of regular-blocking WKT Raster that implies more than one table, the type called "tiled image". In this type, we'd have to read two or more tables to get the whole raster coverage. So, do we have to read all tables, with all of their tiles, to create a Dataset? In this case, the connection string syntax may vary...
    77 
    78 **** ANSWER, by Pierre Racine: I would not take care of this arrangement. Lets focus on reading one table at a time. As I said in the doc this arrangement is not very useful/modern.
    79 
    80 
    81 **** QUESTION: How to manage the mode in irregular-blocking rasters?
    82 
    83 **** ANSWER: Maybe an additional param to connection string: PG:......mode='<mode>'. Even for regular blocking arrangements too.
    84 
    85 Anyway, as we said, I'm going to focus on reading the regular blocking arrangements. And how should I read these arrangements?
    86 
    87 I think that I need 2 steps:
    88   1. Read the raster attributes using information from RASTER_COLUMNS table. For example: The parameters to GeoTransform operation must be taken from the RASTER_COLUMNS table. Update: done on r20
    89   1. Read the raster data as a HEXWKB stream, allocating enough memory for all the tiles.
    90 
    91 **** QUESTION: Should the RasterBand read all the tiles (rows of the raster table) and put them consecutives in the same memory area? If I expect this from RasterBand class, the memory allocation is easy.
    92 
    93 **** ANSWER: It should have only one block (tile) in memory at same time.
     61  1. Check connection string format
     62  1. Parse connection string, extracting useful information (table name, optional sql where part, working mode)
     63  1. Check working mode. If not regularly_tiled mode, from now, finish.
     64  1. Open a database connection.
     65  1. Perform some security and integrity checkings: check if database has PostGIS extensions, if the table exists, it is registered in RASTER_COLUMNS table, if has a GIST index, etc. Suggestions accepted and appreciated.
     66  1. Fetch raster properties from RASTER_COLUMNS table. If the table is not registered in RASTER_COLUMNS, as we are working only in regularly_tiled mode, we should finish.
     67  1. Populate its georeference information, to allow GetProjectionRef and GetGeoTransform methods provide correct information.
    9468
    9569
    9670== Implementing the RasterBand ==
    9771
    98 With the Dataset, we will be able to access the table (or tables) that form the WKT Raster object, and to know which type of raster are we dealing with. But we need to read the information of this raster. This is, to read the Raster Bands. There are two important methods to implement:
    99   * Constructor. In this method, the object gets important info, like the band number thar represents, the data type (data size) and the block size.
    100   * IReadBlock: This method is the one that really needs the WKT Raster data (the image or tile data). This method take as input the offset over the data (in tiled images, this offset is an index to move over the data pointed by the data field in the Dataset) and a buffer to store the block (tile) read.
     72If Dataset opens the connection with database, RasterBand reads blocks of data. So, the key method here is IReadBlock. This method:
    10173
    102 ''The full set of possible GDALDataType values are declared in gdal.h, and include GDT_Byte, GDT_UInt16, GDT_Int16, and GDT_Float32''. All of them must be managed.
     74  1. Get pixel size (now only 8bits).
     75  1. Transform pixel,line coordinates into coordinates of the raster reference systems, by using the proper methods of Dataset, and get the coordinates of the block center.
     76  1. Query for blocks that contains this point (the block center). As we only consider regularly_blocking rasters, the result will only 1 block. IMPORTANT: NOW, I'M USING A TESTING QUERY THAT ALWAYS FETCH THE SAME RASTER BLOCK. THE SPATIAL QUERY WILL BE ADDED ASAP.
     77  1. Fetch the block in HEXWKB format and parse it to get the data. The HEXWKB format includes raster information header on each block, so, this information can be used for integrity checkings.
     78  1. Copy the block data into the buffer.
    10379
    104 ''The block size is used to establish a natural or efficient block size to access the data with. For tiled datasets this will be the size of a tile, while for most other datasets it will be one scanline''. So, in our basic WKT Raster types reading, we should interpret this like ''the size of a tile''.
    105 
    106 And important issue here is ''how the tiles will finally be handled when fetching the raster data ''. Is the part in which I have more questions:
    107   * The data fetched with the Raster Band, is in HEXWKB format? (I think so) I should code a method to transform from this format to another ones...
    108   * Do we have to encode the data fetched in PNG/JPEG/TIFF format?
    109   * May we assume that the tiles stored at the same table are homogeneus? What does exactly 'homogeneus' mean here? Only same pixel type?
    110   * How do we manage the data fetched? Simply copy the raster data sequentially into the destination? Anf what happens if these raster data come from tiles with different pixeltype or band configuration?
    111 
    112 I think we should ''cut'', and take decissions about these questions. My proposal:
    113   * Data fetched in HEXWKB format. Implement a HEXWKB to binary decoding taking care to convert to local machine byte order if necessary. See OGRPGLayer::HEXToGeometry() method in ogrpglayer.cpp as a guide.
    114   * Apart from the possible implementation of out-db rasters, don't care about encoding to output format
    115   * ''In a regular_blocking table you can assume that all types are of the same pixel type, the same tile size (in pixels and lines), and the same geographic resolution.''
    116   * ''When you establish the GDALRasterBand corresponding to a band in the table you will declare the pixel data type based on the contents of the RASTER_COLUMNS table.   The IReadBlock() method will be invoked with a buffer that is the block/tile size and already of the declared pixel data type.  The tile you get from the database should also be in this type (assuming regular_blocking).  There should not be any translation of pixel type required though you will need to be byte order aware for non-byte image data. You will basically decode the HEXWKB image into the buffer passed into IReadBlock.''
    117 
    118 Any suggestions?
    119  
    12080
    12181== Overviews ==
     
    13191||Create basic enviroment for new GDAL driver|| 21th June||Done||
    13292||Create testing enviroment for debugging driver developing|| 28th June||Done||
    133 ||'''Objective 1 - Prototype read only support for regular blocking rasters'''||'''13th July'''||'''On going'''||'''midterm evaluation'''||
     93||'''Objective 1 - Prototype read only support for regular blocking rasters'''||'''15th July'''||'''On going'''||'''midterm evaluation'''||
    13494||Dataset: Connection with database and creation of Raster Bands objects (regular blocking rasters)||6th July||On going||
    135 ||RasterBand: Fetching of raster data||13th July||On going||
    136 ||'''Objective 1.1 - Support of different pixel data types, take care of byte swapping'''||'''16th July'''||'''todo'''||
     95||RasterBand: Query the correct block and fetch the raster data||15th July||On going||
     96||'''Objective 1.1 - Support of different pixel data types, take care of byte swapping'''||'''17th July'''||'''todo'''||
    13797||'''Objective 2 - Support access to overviews'''||'''19th July'''||'''todo'''||
    13898||'''Objective 3 - Support for out-db rasters'''||'''19th July'''||'''todo'''||
    13999||'''Objective 4 - Rasters inplace update'''||'''26th July'''||'''todo'''||
    140100||'''Objective 5 - Read only support for non-regular blocking rasters'''||'''2th-10th August'''||'''todo'''||
     101||Objective 5.1 - Block caching in Raster Band||2th-10th August||todo||
    141102||'''Objective 6 - Support for creating new rasters'''||'''10th - 17th August'''||'''undecided'''||'''final evaluation'''||
    142103